8134540: Much nearly duplicated code for PerfMemory support

Reviewed-by: coleenp, dholmes
This commit is contained in:
Harold Seigel 2021-01-19 13:44:07 +00:00
parent a9519c83b8
commit 82adfb3233
9 changed files with 102 additions and 2625 deletions

View file

@ -4349,6 +4349,37 @@ jlong os::Linux::fast_thread_cpu_time(clockid_t clockid) {
return (tp.tv_sec * NANOSECS_PER_SEC) + tp.tv_nsec;
}
// Determine if the vmid is the parent pid for a child in a PID namespace.
// Return the namespace pid if so, otherwise -1.
int os::Linux::get_namespace_pid(int vmid) {
char fname[24];
int retpid = -1;
snprintf(fname, sizeof(fname), "/proc/%d/status", vmid);
FILE *fp = fopen(fname, "r");
if (fp) {
int pid, nspid;
int ret;
while (!feof(fp) && !ferror(fp)) {
ret = fscanf(fp, "NSpid: %d %d", &pid, &nspid);
if (ret == 1) {
break;
}
if (ret == 2) {
retpid = nspid;
break;
}
for (;;) {
int ch = fgetc(fp);
if (ch == EOF || ch == (int)'\n') break;
}
}
fclose(fp);
}
return retpid;
}
extern void report_error(char* file_name, int line_no, char* title,
char* format, ...);