Skip to content

Commit

Permalink
pcaddr
Browse files Browse the repository at this point in the history
  • Loading branch information
apangin committed Sep 18, 2024
1 parent 6d7f73a commit d624d9f
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ static const Multiplier UNIVERSAL[] = {{'n', 1}, {'u', 1000}, {'m', 1000000}, {'
// interval=N - sampling interval in ns (default: 10'000'000, i.e. 10 ms)
// jstackdepth=N - maximum Java stack depth (default: 2048)
// signal=N - use alternative signal for cpu or wall clock profiling
// features=LIST - advanced stack trace features (vtable, comptask)"
// features=LIST - advanced stack trace features (vtable, comptask, pcaddr)"
// safemode=BITS - disable stack recovery techniques (default: 0, i.e. everything enabled)
// file=FILENAME - output file name for dumping
// log=FILENAME - log warnings and errors to the given dedicated stream
Expand Down Expand Up @@ -272,6 +272,7 @@ Error Arguments::parse(const char* args) {
if (strstr(value, "probesp")) _features.probe_sp = 1;
if (strstr(value, "vtable")) _features.vtable_target = 1;
if (strstr(value, "comptask")) _features.comp_task = 1;
if (strstr(value, "pcaddr")) _features.pc_addr = 1;
}

CASE("safemode") {
Expand Down
5 changes: 3 additions & 2 deletions src/arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ struct StackWalkFeatures {
unsigned short probe_sp : 1;
unsigned short vtable_target : 1;
unsigned short comp_task : 1;
unsigned short _reserved : 7;
unsigned short pc_addr : 1;
unsigned short _reserved : 6;

StackWalkFeatures() : unknown_java(1), unwind_stub(1), unwind_comp(1), unwind_native(1), java_anchor(1), gc_traces(1),
probe_sp(0), vtable_target(0), comp_task(0), _reserved(0) {
probe_sp(0), vtable_target(0), comp_task(0), pc_addr(0), _reserved(0) {
}
};

Expand Down
9 changes: 7 additions & 2 deletions src/flightRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ class Lookup {
} else if (frame.bci == BCI_NATIVE_FRAME) {
const char* name = (const char*)method;
fillNativeMethodInfo(mi, name, Profiler::instance()->getLibraryName(name));
} else if (frame.bci == BCI_ADDRESS) {
char buf[32];
snprintf(buf, sizeof(buf), "%p", method);
fillNativeMethodInfo(mi, buf, NULL);
} else if (frame.bci == BCI_ERROR) {
fillNativeMethodInfo(mi, (const char*)method, NULL);
} else {
Expand Down Expand Up @@ -709,7 +713,7 @@ class Recording {
}

const char* getFeaturesString(char* str, size_t size, StackWalkFeatures f) {
snprintf(str, size, "%s %s %s %s %s %s %s %s %s",
snprintf(str, size, "%s %s %s %s %s %s %s %s %s %s",
f.unknown_java ? "unknown_java" : "-",
f.unwind_stub ? "unwind_stub" : "-",
f.unwind_comp ? "unwind_comp" : "-",
Expand All @@ -718,7 +722,8 @@ class Recording {
f.gc_traces ? "gc_traces" : "-",
f.probe_sp ? "probesp" : "-",
f.vtable_target ? "vtable" : "-",
f.comp_task ? "comptask" : "-");
f.comp_task ? "comptask" : "-",
f.pc_addr ? "pcaddr" : "-");
return str;
}

Expand Down
7 changes: 7 additions & 0 deletions src/frameName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,12 @@ const char* FrameName::name(ASGCT_CallFrame& frame, bool for_matching) {
}
}

case BCI_ADDRESS: {
char buf[32];
snprintf(buf, sizeof(buf), "%p", frame.method_id);
return _str.assign(buf).c_str();
}

case BCI_ERROR:
return _str.assign("[").append((const char*)frame.method_id).append("]").c_str();

Expand Down Expand Up @@ -345,6 +351,7 @@ FrameTypeId FrameName::type(ASGCT_CallFrame& frame) {
return FRAME_KERNEL;

case BCI_THREAD_ID:
case BCI_ADDRESS:
case BCI_ERROR:
return FRAME_NATIVE;

Expand Down
2 changes: 1 addition & 1 deletion src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static const char USAGE_STRING[] =
" -I include output only stack traces containing the specified pattern\n"
" -X exclude exclude stack traces with the specified pattern\n"
" -L level log level: debug|info|warn|error|none\n"
" -F features advanced stack trace features: vtable, comptask\n"
" -F features advanced stack trace features: vtable, comptask, pcaddr\n"
" -v, --version display version string\n"
"\n"
" --title string FlameGraph title\n"
Expand Down
4 changes: 4 additions & 0 deletions src/profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,10 @@ u64 Profiler::recordSample(void* ucontext, u64 counter, EventType event_type, Ev
}
}

if (_features.pc_addr && event_type <= EXECUTION_SAMPLE && ucontext != NULL) {
num_frames += makeFrame(frames + num_frames, BCI_ADDRESS, StackFrame(ucontext).pc());
}

StackContext java_ctx = {0};
num_frames += getNativeTrace(ucontext, frames + num_frames, event_type, tid, &java_ctx);

Expand Down
3 changes: 2 additions & 1 deletion src/vmEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ enum ASGCT_CallFrameType {
BCI_LOCK = -14, // class name of the locked object
BCI_PARK = -15, // class name of the park() blocker
BCI_THREAD_ID = -16, // method_id designates a thread
BCI_ERROR = -17, // method_id is an error string
BCI_ADDRESS = -17, // method_id is a PC address
BCI_ERROR = -18, // method_id is an error string
};

// See hotspot/src/share/vm/prims/forte.cpp
Expand Down

0 comments on commit d624d9f

Please sign in to comment.