Skip to content

Commit 668e058

Browse files
authored
use pid+tid for node environment key (#96)
1 parent c77144e commit 668e058

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

support/ebpf/interpreter_dispatcher.ebpf.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,17 +434,17 @@ static EBPF_INLINE bool get_node_env_ptr(V8ProcInfo *proc, u64 *env_ptr_out)
434434
return true;
435435
}
436436

437-
static EBPF_INLINE bool get_node_async_id(V8ProcInfo *proc, u32 tid, u64 *out)
437+
static EBPF_INLINE bool get_node_async_id(V8ProcInfo *proc, u64 pid_tgid, u64 *out)
438438
{
439439
int err;
440440

441441
u64 env_ptr;
442442
// Try to get fresh env_ptr
443443
if (get_node_env_ptr(proc, &env_ptr)) {
444-
bpf_map_update_elem(&v8_cached_env_ptrs, &tid, &env_ptr, BPF_ANY);
444+
bpf_map_update_elem(&v8_cached_env_ptrs, &pid_tgid, &env_ptr, BPF_ANY);
445445
} else {
446446
// Fallback to cached value from previous successful extraction
447-
u64 *cached_env_ptr = bpf_map_lookup_elem(&v8_cached_env_ptrs, &tid);
447+
u64 *cached_env_ptr = bpf_map_lookup_elem(&v8_cached_env_ptrs, &pid_tgid);
448448
if (cached_env_ptr && *cached_env_ptr != 0) {
449449
// TODO[btv] -- Figure out why the environment is sometimes null.
450450
// It doesn't seem to matter in practice, since the environment rarely (never?)
@@ -649,7 +649,8 @@ static EBPF_INLINE void maybe_add_node_custom_labels(PerCPURecord *record)
649649
}
650650

651651
u64 id;
652-
bool success = get_node_async_id(v8_proc, record->trace.tid, &id);
652+
u64 pid_tgid = (u64)record->trace.pid << 32 | record->trace.tid;
653+
bool success = get_node_async_id(v8_proc, pid_tgid, &id);
653654
if (success) {
654655
if (id == 0) {
655656
increment_metric(metricID_UnwindNodeClWarnIdZero);

support/ebpf/tracer.ebpf.amd64

248 Bytes
Binary file not shown.

support/ebpf/tracer.ebpf.arm64

248 Bytes
Binary file not shown.

support/ebpf/v8_tracer.ebpf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bpf_map_def SEC("maps") v8_procs = {
4242
// Map from thread IDs to cached Node.js environment pointers
4343
bpf_map_def SEC("maps") v8_cached_env_ptrs = {
4444
.type = BPF_MAP_TYPE_LRU_HASH,
45-
.key_size = sizeof(u32), // TID
45+
.key_size = sizeof(u64), // pid+tid
4646
.value_size = sizeof(u64), // cached environment pointer
4747
.max_entries = 4096, // more threads than processes
4848
};

0 commit comments

Comments
 (0)