Skip to content

Commit c55cd69

Browse files
committed
feat(eBPF): include file name and line number in java method symbols
1 parent b7c8cda commit c55cd69

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

agent/src/ebpf/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ OBJS := user/elf.o \
102102
user/profile/java/collect_symbol_files.o
103103

104104
JAVA_TOOL := deepflow-jattach
105-
JAVA_AGENT_VERSION := 2
105+
JAVA_AGENT_VERSION := 3
106106
JAVA_AGENT_GNU_SO := df_java_agent_v$(JAVA_AGENT_VERSION).so
107107
JAVA_AGENT_MUSL_SO := df_java_agent_musl_v$(JAVA_AGENT_VERSION).so
108108
JAVA_AGENT_SO := $(JAVA_AGENT_GNU_SO) $(JAVA_AGENT_MUSL_SO)

agent/src/ebpf/user/profile/java/symbol_collect_agent.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,30 @@ void generate_single_entry(enum event_type type, jvmtiEnv * jvmti,
377377
} else {
378378
memcpy(class_name, csig, sizeof(class_name) - 1);
379379
}
380-
snprintf(output, noutput, "%s::%s%s", class_name,
381-
method_name, method_signature);
382380

381+
char *source_file = NULL;
382+
jvmtiError err =
383+
(*jvmti)->GetSourceFileName(jvmti, class, &source_file);
384+
if (err != JVMTI_ERROR_NONE) {
385+
source_file = NULL;
386+
}
387+
388+
jint entry_count = 0;
389+
jvmtiLineNumberEntry *table = NULL;
390+
int line_number = -1;
391+
err =
392+
(*jvmti)->GetLineNumberTable(jvmti, method, &entry_count,
393+
&table);
394+
if (err == JVMTI_ERROR_NONE && entry_count > 0 && table != NULL) {
395+
line_number = table[0].line_number;
396+
}
397+
398+
snprintf(output, noutput, "%s::%s%s[%s:%d]", class_name,
399+
method_name, method_signature,
400+
source_file == NULL ? "" : source_file, line_number);
401+
402+
deallocate(jvmti, (unsigned char *)table);
403+
deallocate(jvmti, (unsigned char *)source_file);
383404
deallocate(jvmti, (unsigned char *)csig);
384405
}
385406

0 commit comments

Comments
 (0)