Skip to content

Commit 1f31fdc

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

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
@@ -367,6 +367,9 @@ Error Arguments::parse(const char* args) {
367367
CASE("meminfolog")
368368
_log_meminfo_on_dump = true;
369369

370+
CASE("includemm")
371+
_includemm = true;
372+
370373
DEFAULT()
371374
if (_unknown_arg == NULL) _unknown_arg = arg;
372375
}

src/arguments.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ class Arguments {
166166
bool _sched;
167167
bool _live;
168168
bool _fdtransfer;
169+
bool _includemm;
169170
const char* _fdtransfer_path;
170171
int _style;
171172
CStack _cstack;
@@ -233,7 +234,8 @@ class Arguments {
233234
_title(NULL),
234235
_minwidth(0),
235236
_reverse(false),
236-
_log_meminfo_on_dump(false) {
237+
_log_meminfo_on_dump(false),
238+
_includemm(false) {
237239
}
238240

239241
~Arguments();

src/frameName.cpp

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

3030

31+
// 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
32+
// Good practice order from: https://checkstyle.sourceforge.io/config_modifier.html#ModifierOrder
33+
const static std::pair<int, std::string> access_flags [] = {
34+
std::make_pair(0x0001, "public"),
35+
std::make_pair(0x0002, "private"),
36+
std::make_pair(0x0004, "protected"),
37+
std::make_pair(0x0400, "abstract"),
38+
std::make_pair(0x0008, "static"),
39+
std::make_pair(0x0010, "final"),
40+
std::make_pair(0x0020, "synchronized"),
41+
std::make_pair(0x0100, "native"),
42+
std::make_pair(0x0800, "strict"),
43+
std::make_pair(0x0040, "bridge"),
44+
std::make_pair(0x0080, "varargs"),
45+
std::make_pair(0x1000, "synthetic"),
46+
};
47+
48+
3149
Matcher::Matcher(const char* pattern) {
3250
if (pattern[0] == '*') {
3351
_type = MATCH_ENDS_WITH;
@@ -95,7 +113,7 @@ FrameName::FrameName(Arguments& args, int style, int epoch, Mutex& thread_names_
95113
{
96114
// Require printf to use standard C format regardless of system locale
97115
_saved_locale = uselocale(newlocale(LC_NUMERIC_MASK, "C", (locale_t)0));
98-
116+
_includemm = args._includemm;
99117
buildFilter(_include, args._buf, args._include);
100118
buildFilter(_exclude, args._buf, args._exclude);
101119

@@ -167,6 +185,7 @@ void FrameName::javaMethodName(jmethodID method) {
167185
char* class_name = NULL;
168186
char* method_name = NULL;
169187
char* method_sig = NULL;
188+
jint modifiers = 0;
170189

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

src/frameName.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class FrameName {
7575
Mutex& _thread_names_lock;
7676
ThreadMap& _thread_names;
7777
locale_t _saved_locale;
78+
bool _includemm;
7879

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

0 commit comments

Comments
 (0)