Skip to content

Commit

Permalink
Convert frame name format to 'function (DSO)' for LIB style (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-ol authored and Jongy committed Jan 24, 2023
1 parent 49080a2 commit f4d874c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/codeCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ size_t NativeFunc::usedMemory(const char* name) {

CodeCache::CodeCache(const char* name, short lib_index, const void* min_address, const void* max_address) {
_name = NativeFunc::create(name, -1);
char *tmp = (char*)malloc(strlen(name) + 3);
snprintf(tmp, strlen(name) + 3, "(%s)", name);
_lib_symbol = NativeFunc::create(tmp, -1);
free(tmp);
_lib_index = lib_index;
_min_address = min_address;
_max_address = max_address;
Expand All @@ -63,6 +67,7 @@ CodeCache::~CodeCache() {
for (int i = 0; i < _count; i++) {
NativeFunc::destroy(_blobs[i]._name);
}
NativeFunc::destroy(_lib_symbol);
NativeFunc::destroy(_name);
delete[] _blobs;
free(_dwarf_table);
Expand Down Expand Up @@ -153,7 +158,8 @@ const char* CodeCache::binarySearch(const void* address) {
if (low > 0 && (_blobs[low - 1]._start == _blobs[low - 1]._end || _blobs[low - 1]._end == address)) {
return _blobs[low - 1]._name;
}
return _name;

return _lib_symbol;
}

const void* CodeCache::findSymbol(const char* name) {
Expand Down
1 change: 1 addition & 0 deletions src/codeCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class FrameDesc;
class CodeCache {
protected:
char* _name;
char* _lib_symbol;
short _lib_index;
const void* _min_address;
const void* _max_address;
Expand Down
4 changes: 2 additions & 2 deletions src/frameName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const char* FrameName::decodeNativeSymbol(const char* name) {
char* demangled = abi::__cxa_demangle(name, NULL, NULL, &status);
if (demangled != NULL) {
if (lib_name != NULL) {
_str.assign(lib_name).append("`").append(demangled);
_str.assign(demangled).append(" (").append(lib_name).append(")");
} else {
_str.assign(demangled);
}
Expand All @@ -144,7 +144,7 @@ const char* FrameName::decodeNativeSymbol(const char* name) {
}

if (lib_name != NULL) {
return _str.assign(lib_name).append("`").append(name).c_str();
return _str.assign(name).append(" (").append(lib_name).append(")").c_str();
} else {
return name;
}
Expand Down
16 changes: 12 additions & 4 deletions src/profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ const char* Profiler::getLibraryName(const char* native_symbol) {
if (lib_index >= 0 && lib_index < _native_libs.count()) {
const char* s = _native_libs[lib_index]->name();
if (s != NULL) {
const char* p = strrchr(s, '/');
return p != NULL ? p + 1 : s;
return s;
}
}
return NULL;
Expand All @@ -259,15 +258,24 @@ CodeCache* Profiler::findJvmLibrary(const char* lib_name) {
CodeCache* Profiler::findLibraryByName(const char* lib_name) {
const size_t lib_name_len = strlen(lib_name);
const int native_lib_count = _native_libs.count();
int basename_match_i = -1;
for (int i = 0; i < native_lib_count; i++) {
const char* s = _native_libs[i]->name();
if (s != NULL) {
const char* p = strrchr(s, '/');
if (p != NULL && strncmp(p + 1, lib_name, lib_name_len) == 0) {
if (strncmp(s, lib_name, lib_name_len) == 0) {
return _native_libs[i];
}
if (basename_match_i < 0) {
const char* p = strrchr(s, '/');
if (p != NULL && strncmp(p + 1, lib_name, lib_name_len) == 0) {
basename_match_i = i;
}
}
}
}
if (basename_match_i >= 0) {
return _native_libs[basename_match_i];
}
return NULL;
}

Expand Down

0 comments on commit f4d874c

Please sign in to comment.