src/os/linux/vm/os_linux.cpp
Print this page
@@ -5282,11 +5282,10 @@
// -1 on error.
//
static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
static bool proc_task_unchecked = true;
- static const char *proc_stat_path = "/proc/%d/stat";
pid_t tid = thread->osthread()->thread_id();
char *s;
char stat[2048];
int statlen;
char proc_name[64];
@@ -5295,10 +5294,13 @@
char cdummy;
int idummy;
long ldummy;
FILE *fp;
+
+ sprintf(proc_name, "/proc/%d/stat", tid);
+
// The /proc/<tid>/stat aggregates per-process usage on
// new Linux kernels 2.6+ where NPTL is supported.
// The /proc/self/task/<tid>/stat still has the per-thread usage.
// See bug 6328462.
// There possibly can be cases where there is no directory
@@ -5306,16 +5308,15 @@
if (proc_task_unchecked && os::Linux::is_NPTL()) {
// This is executed only once
proc_task_unchecked = false;
fp = fopen("/proc/self/task", "r");
if (fp != NULL) {
- proc_stat_path = "/proc/self/task/%d/stat";
+ sprintf(proc_name, "/proc/self/task/%d/stat", tid);
fclose(fp);
}
}
- sprintf(proc_name, proc_stat_path, tid);
fp = fopen(proc_name, "r");
if ( fp == NULL ) return -1;
statlen = fread(stat, 1, 2047, fp);
stat[statlen] = '\0';
fclose(fp);