Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename
  • Loading branch information
zhengyu.gu committed Jun 11, 2025
commit cc957930b34f8358cb4088310f7f56998cb04bd6
12 changes: 6 additions & 6 deletions ddprof-lib/src/main/cpp/threadFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@ void ThreadFilter::clear() {
_size = 0;
}

int ThreadFilter::hashThreadId(int thread_id) {
int ThreadFilter::mapThreadId(int thread_id) {
Comment thread
zhengyu123 marked this conversation as resolved.
u16 lower16 = (u16)(thread_id & 0xffff);
lower16 = ((lower16 & 0x00ff) << 8) | ((lower16 & 0xff00) >> 8);
int tid = (thread_id & ~0xffff) | lower16;
return tid;
}

bool ThreadFilter::accept(int thread_id) {
thread_id = hashThreadId(thread_id);
thread_id = mapThreadId(thread_id);
u64 *b = bitmap(thread_id);
return b != NULL && (word(b, thread_id) & (1ULL << (thread_id & 0x3f)));
}

void ThreadFilter::add(int thread_id) {
thread_id = hashThreadId(thread_id);
thread_id = mapThreadId(thread_id);
u64 *b = bitmap(thread_id);
if (b == NULL) {
b = (u64 *)OS::safeAlloc(BITMAP_SIZE);
Expand All @@ -120,7 +120,7 @@ void ThreadFilter::add(int thread_id) {
}

void ThreadFilter::remove(int thread_id) {
thread_id = hashThreadId(thread_id);
thread_id = mapThreadId(thread_id);
u64 *b = bitmap(thread_id);
if (b == NULL) {
return;
Expand All @@ -143,8 +143,8 @@ void ThreadFilter::collect(std::vector<int> &v) {
u64 word = __atomic_load_n(&b[j], __ATOMIC_ACQUIRE);
while (word != 0) {
int tid = start_id + j * 64 + __builtin_ctzl(word);
// restore thread id;
tid = hashThreadId(tid);
// restore thread id
tid = mapThreadId(tid);
v.push_back(tid);
word &= (word - 1);
}
Expand Down
2 changes: 1 addition & 1 deletion ddprof-lib/src/main/cpp/threadFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ThreadFilter {
__ATOMIC_ACQUIRE);
}

static int hashThreadId(int thread_id);
static int mapThreadId(int thread_id);

u64 &word(u64 *bitmap, int thread_id) {
// todo: add thread safe APIs
Expand Down
Loading