-
Notifications
You must be signed in to change notification settings - Fork 7
Refactor thread filter mechanisms #209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3b91530
913d2b6
873fcb2
be0752b
0f92917
258f23e
1d4efc0
115a60a
efa094e
1be1c3a
4772169
60ef060
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -318,7 +318,7 @@ char *Recording::_jvm_flags = NULL; | |
char *Recording::_java_command = NULL; | ||
|
||
Recording::Recording(int fd, Arguments &args) | ||
: _fd(fd), _thread_set(), _method_map() { | ||
: _fd(fd), _method_map() { | ||
|
||
args.save(_args); | ||
_chunk_start = lseek(_fd, 0, SEEK_END); | ||
|
@@ -330,6 +330,8 @@ Recording::Recording(int fd, Arguments &args) | |
_bytes_written = 0; | ||
|
||
_tid = OS::threadId(); | ||
_active_index.store(0, std::memory_order_relaxed); | ||
|
||
VM::jvmti()->GetAvailableProcessors(&_available_processors); | ||
|
||
writeHeader(_buf); | ||
|
@@ -1059,11 +1061,18 @@ void Recording::writeExecutionModes(Buffer *buf) { | |
} | ||
|
||
void Recording::writeThreads(Buffer *buf) { | ||
addThread(_tid); | ||
std::vector<int> threads; | ||
threads.reserve(_thread_set.size()); | ||
_thread_set.collect(threads); | ||
_thread_set.clear(); | ||
int old_index = _active_index.fetch_xor(1, std::memory_order_acq_rel); | ||
// After flip: new samples go into the new active set | ||
// We flush from old_index (the previous active set) | ||
|
||
std::unordered_set<int> threads; | ||
threads.insert(_tid); | ||
|
||
for (int i = 0; i < CONCURRENCY_LEVEL; ++i) { | ||
// Collect thread IDs from the fixed-size table into the main set | ||
_thread_ids[i][old_index].collect(threads); | ||
_thread_ids[i][old_index].clear(); | ||
} | ||
|
||
Profiler *profiler = Profiler::instance(); | ||
ThreadInfo *t_info = &profiler->_thread_info; | ||
|
@@ -1072,15 +1081,15 @@ void Recording::writeThreads(Buffer *buf) { | |
|
||
buf->putVar64(T_THREAD); | ||
buf->putVar64(threads.size()); | ||
for (int i = 0; i < threads.size(); i++) { | ||
for (auto tid : threads) { | ||
const char *thread_name; | ||
jlong thread_id; | ||
std::pair<std::shared_ptr<std::string>, u64> info = t_info->get(threads[i]); | ||
std::pair<std::shared_ptr<std::string>, u64> info = t_info->get(tid); | ||
if (info.first) { | ||
thread_name = info.first->c_str(); | ||
thread_id = info.second; | ||
} else { | ||
snprintf(name_buf, sizeof(name_buf), "[tid=%d]", threads[i]); | ||
snprintf(name_buf, sizeof(name_buf), "[tid=%d]", tid); | ||
thread_name = name_buf; | ||
thread_id = 0; | ||
} | ||
|
@@ -1090,9 +1099,9 @@ void Recording::writeThreads(Buffer *buf) { | |
(thread_id == 0 ? length + 1 : 2 * length) - | ||
3 * 10; // 3x max varint length | ||
flushIfNeeded(buf, required); | ||
buf->putVar64(threads[i]); | ||
buf->putVar64(tid); | ||
buf->putUtf8(thread_name, length); | ||
buf->putVar64(threads[i]); | ||
buf->putVar64(tid); | ||
if (thread_id == 0) { | ||
buf->put8(0); | ||
} else { | ||
|
@@ -1442,7 +1451,11 @@ void Recording::recordCpuLoad(Buffer *buf, float proc_user, float proc_system, | |
flushIfNeeded(buf); | ||
} | ||
|
||
void Recording::addThread(int tid) { _thread_set.add(tid); } | ||
// assumption is that we hold the lock (with lock_index) | ||
void Recording::addThread(int lock_index, int tid) { | ||
int active = _active_index.load(std::memory_order_acquire); | ||
_thread_ids[lock_index][active].insert(tid); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder - does the ordering matter here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not acceptable: no allocations can take place here. |
||
} | ||
|
||
Error FlightRecorder::start(Arguments &args, bool reset) { | ||
const char *file = args.file(); | ||
|
@@ -1599,7 +1612,7 @@ void FlightRecorder::recordEvent(int lock_index, int tid, u32 call_trace_id, | |
break; | ||
} | ||
_rec->flushIfNeeded(buf); | ||
_rec->addThread(tid); | ||
_rec->addThread(lock_index, tid); | ||
} | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it ok to remove this call? We should make sure that the recording thread is also included as events can be associated with it - recording info, settings, config - all point to _tid thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I do (with the
threads.insert(_tid);
)I had to move it down a few lines.