Skip to content

Commit

Permalink
libbpf-tools: javagc: Hints for more information (#5154)
Browse files Browse the repository at this point in the history
Prints a prompt message for not finding jvm.so and opening
/proc/PID/maps incorrectly.

Signed-off-by: Rong Tao <[email protected]>
  • Loading branch information
Rtoax authored Nov 23, 2024
1 parent 378d287 commit ebcc7a7
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions libbpf-tools/javagc.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,39 @@ static int get_jvmso_path(char *path)
size_t seg_start, seg_end, seg_off;
FILE *f;
int i = 0;
bool found = false;

if (env.pid == -1) {
fprintf(stderr, "not specify pid, see --pid.\n");
return -1;
}

sprintf(buf, "/proc/%d/maps", env.pid);
f = fopen(buf, "r");
if (!f)
if (!f) {
fprintf(stderr, "open %s failed: %m\n", buf);
return -1;
}

while (fscanf(f, "%zx-%zx %s %zx %*s %*d%[^\n]\n",
&seg_start, &seg_end, mode, &seg_off, line) == 5) {
i = 0;
while (isblank(line[i]))
i++;
if (strstr(line + i, "libjvm.so")) {
found = true;
strcpy(path, line + i);
break;
}
}

strcpy(path, line + i);
fclose(f);

if (!found) {
fprintf(stderr, "Not found libjvm.so.\n");
return -ENOENT;
}

return 0;
}

Expand Down

0 comments on commit ebcc7a7

Please sign in to comment.