mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-18 01:54:47 +02:00
8134540: Much nearly duplicated code for PerfMemory support
Reviewed-by: coleenp, dholmes
This commit is contained in:
parent
a9519c83b8
commit
82adfb3233
9 changed files with 102 additions and 2625 deletions
|
@ -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, ...);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue