From 34f797e88f8cd172153e29b7833e331d28362741 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Mon, 27 Jan 2020 14:48:54 +0900 Subject: [PATCH] perf does not recognize too short function name --- sample/profiler.cpp | 4 ---- xbyak/xbyak_util.h | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/sample/profiler.cpp b/sample/profiler.cpp index 772e5c5..dc15d9b 100644 --- a/sample/profiler.cpp +++ b/sample/profiler.cpp @@ -6,7 +6,6 @@ #include #include #include -#define XBYAK_NO_OP_NAMES #include const int N = 3000000; @@ -70,9 +69,6 @@ int main(int argc, char *argv[]) Xbyak::util::Profiler prof; printf("mode=%d\n", mode); prof.init(mode); - /* - func name must have three characters - */ prof.set("f", (const void*)f, c.getSize()); prof.set("g", (const void*)g, c2.getSize()); diff --git a/xbyak/xbyak_util.h b/xbyak/xbyak_util.h index 91b2e21..4f79d8f 100644 --- a/xbyak/xbyak_util.h +++ b/xbyak/xbyak_util.h @@ -1,5 +1,6 @@ #ifndef XBYAK_XBYAK_UTIL_H_ #define XBYAK_XBYAK_UTIL_H_ +#include /** utility class and functions for Xbyak @@ -759,7 +760,7 @@ public: }; Profiler() : mode_(None) - , suffix_(0) + , suffix_("") , startAddr_(0) #ifdef XBYAK_USE_PERF , fp_(0) @@ -833,7 +834,16 @@ public: #ifdef XBYAK_USE_PERF if (mode_ == Perf) { if (fp_ == 0) return; - fprintf(fp_, "%llx %zx %s%s\n", (long long)startAddr, funcSize, funcName, suffix_); + fprintf(fp_, "%llx %zx %s%s", (long long)startAddr, funcSize, funcName, suffix_); + /* + perf does not recognize the function name which is less than 3, + so append '_' at the end of the name if necessary + */ + size_t n = strlen(funcName) + strlen(suffix_); + for (size_t i = n; i < 3; i++) { + fprintf(fp_, "_"); + } + fprintf(fp_, "\n"); fflush(fp_); } #endif