Skip to content

Commit e2510f3

Browse files
jbachorikclaude
andcommitted
Reset JfrMetadata between profiler sessions
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 2422667 commit e2510f3

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

ddprof-lib/src/main/cpp/jfrMetadata.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ bool JfrMetadata::_initialized = false;
2626

2727
JfrMetadata::JfrMetadata() : Element("root") {}
2828

29+
void JfrMetadata::reset() {
30+
_root._children.clear();
31+
_root._attributes.clear();
32+
_strings.clear();
33+
_string_map.clear();
34+
// Re-register "root" at ID 0 so _root._name (const 0) stays valid
35+
getId("root");
36+
_initialized = false;
37+
}
38+
2939
void JfrMetadata::initialize(
3040
const std::vector<std::string> &contextAttributes) {
3141
if (_initialized) {

ddprof-lib/src/main/cpp/jfrMetadata.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ class JfrMetadata : Element {
259259
JfrMetadata();
260260

261261
static void initialize(const std::vector<std::string> &contextAttributes);
262+
static void reset();
262263

263264
static Element *root() { return &_root; }
264265

ddprof-lib/src/main/cpp/profiler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,7 @@ Error Profiler::start(Arguments &args, bool reset) {
14481448
// Always enable library trap to catch wasmtime loading and patch its broken sigaction
14491449
switchLibraryTrap(true);
14501450

1451+
JfrMetadata::reset();
14511452
JfrMetadata::initialize(args._context_attributes);
14521453
_num_context_attributes = args._context_attributes.size();
14531454
error = _jfr.start(args, reset);

0 commit comments

Comments
 (0)