Skip to content

Commit 37963c0

Browse files
mpozniak95Jongy
authored andcommitted
Add option to include method modifiers in frame name (#5)
async-profiler side of intel/gprofiler#570.
1 parent bdf95a7 commit 37963c0

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

src/arguments.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,9 @@ Error Arguments::parse(const char* args) {
386386
CASE("meminfolog")
387387
_log_meminfo_on_dump = true;
388388

389+
CASE("includemm")
390+
_includemm = true;
391+
389392
DEFAULT()
390393
if (_unknown_arg == NULL) _unknown_arg = arg;
391394
}

src/arguments.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ class Arguments {
179179
bool _sched;
180180
bool _live;
181181
bool _fdtransfer;
182+
bool _includemm;
182183
const char* _fdtransfer_path;
183184
int _style;
184185
StackWalkFeatures _features;
@@ -248,7 +249,8 @@ class Arguments {
248249
_title(NULL),
249250
_minwidth(0),
250251
_reverse(false),
251-
_log_meminfo_on_dump(false) {
252+
_log_meminfo_on_dump(false),
253+
_includemm(false) {
252254
}
253255

254256
~Arguments();

src/frameName.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ static inline bool isDigit(char c) {
1717
}
1818

1919

20+
// Based on: https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#:~:text=Table%C2%A04.5.%C2%A0Method%20access%20and%20property%20flags
21+
// Good practice order from: https://checkstyle.sourceforge.io/config_modifier.html#ModifierOrder
22+
const static std::pair<int, std::string> access_flags [] = {
23+
std::make_pair(0x0001, "public"),
24+
std::make_pair(0x0002, "private"),
25+
std::make_pair(0x0004, "protected"),
26+
std::make_pair(0x0400, "abstract"),
27+
std::make_pair(0x0008, "static"),
28+
std::make_pair(0x0010, "final"),
29+
std::make_pair(0x0020, "synchronized"),
30+
std::make_pair(0x0100, "native"),
31+
std::make_pair(0x0800, "strict"),
32+
std::make_pair(0x0040, "bridge"),
33+
std::make_pair(0x0080, "varargs"),
34+
std::make_pair(0x1000, "synthetic"),
35+
};
36+
37+
2038
Matcher::Matcher(const char* pattern) {
2139
if (pattern[0] == '*') {
2240
_type = MATCH_ENDS_WITH;
@@ -84,7 +102,7 @@ FrameName::FrameName(Arguments& args, int style, int epoch, Mutex& thread_names_
84102
{
85103
// Require printf to use standard C format regardless of system locale
86104
_saved_locale = uselocale(newlocale(LC_NUMERIC_MASK, "C", (locale_t)0));
87-
105+
_includemm = args._includemm;
88106
buildFilter(_include, args._buf, args._include);
89107
buildFilter(_exclude, args._buf, args._exclude);
90108

@@ -165,6 +183,7 @@ void FrameName::javaMethodName(jmethodID method) {
165183
char* class_name = NULL;
166184
char* method_name = NULL;
167185
char* method_sig = NULL;
186+
jint modifiers = 0;
168187

169188
jvmtiEnv* jvmti = VM::jvmti();
170189
jvmtiError err;
@@ -174,6 +193,16 @@ void FrameName::javaMethodName(jmethodID method) {
174193
(err = jvmti->GetClassSignature(method_class, &class_name, NULL)) == 0) {
175194
// Trim 'L' and ';' off the class descriptor like 'Ljava/lang/Object;'
176195
javaClassName(class_name + 1, strlen(class_name) - 2, _style);
196+
if (_includemm) {
197+
jvmti->GetMethodModifiers(method, &modifiers);
198+
std::string modifiers_to_append = "";
199+
for (int i=0; i<(sizeof(access_flags) / sizeof(access_flags[0])); i++) {
200+
if (modifiers & access_flags[i].first) {
201+
modifiers_to_append.append(access_flags[i].second + " ");
202+
}
203+
}
204+
_str.insert(0, modifiers_to_append);
205+
}
177206
_str.append(".").append(method_name);
178207
if (_style & STYLE_SIGNATURES) {
179208
if (_style & STYLE_NO_SEMICOLON) {

src/frameName.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class FrameName {
6464
Mutex& _thread_names_lock;
6565
ThreadMap& _thread_names;
6666
locale_t _saved_locale;
67+
bool _includemm;
6768

6869
void buildFilter(std::vector<Matcher>& vector, const char* base, int offset);
6970
const char* decodeNativeSymbol(const char* name);

0 commit comments

Comments
 (0)