comparison src/os/linux/vm/os_linux.cpp @ 14726:92aa6797d639

Backed out merge changeset: b51e29501f30 Backed out merge revision to its first parent (8f483e200405)
author Doug Simon <doug.simon@oracle.com>
date Mon, 24 Mar 2014 21:30:43 +0100
parents b51e29501f30
children
comparison
equal deleted inserted replaced
14719:0bdd0d157040 14726:92aa6797d639
5282 // -1 on error. 5282 // -1 on error.
5283 // 5283 //
5284 5284
5285 static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) { 5285 static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
5286 static bool proc_task_unchecked = true; 5286 static bool proc_task_unchecked = true;
5287 static const char *proc_stat_path = "/proc/%d/stat";
5287 pid_t tid = thread->osthread()->thread_id(); 5288 pid_t tid = thread->osthread()->thread_id();
5288 char *s; 5289 char *s;
5289 char stat[2048]; 5290 char stat[2048];
5290 int statlen; 5291 int statlen;
5291 char proc_name[64]; 5292 char proc_name[64];
5294 char cdummy; 5295 char cdummy;
5295 int idummy; 5296 int idummy;
5296 long ldummy; 5297 long ldummy;
5297 FILE *fp; 5298 FILE *fp;
5298 5299
5299 snprintf(proc_name, 64, "/proc/%d/stat", tid);
5300
5301 // The /proc/<tid>/stat aggregates per-process usage on 5300 // The /proc/<tid>/stat aggregates per-process usage on
5302 // new Linux kernels 2.6+ where NPTL is supported. 5301 // new Linux kernels 2.6+ where NPTL is supported.
5303 // The /proc/self/task/<tid>/stat still has the per-thread usage. 5302 // The /proc/self/task/<tid>/stat still has the per-thread usage.
5304 // See bug 6328462. 5303 // See bug 6328462.
5305 // There possibly can be cases where there is no directory 5304 // There possibly can be cases where there is no directory
5307 if (proc_task_unchecked && os::Linux::is_NPTL()) { 5306 if (proc_task_unchecked && os::Linux::is_NPTL()) {
5308 // This is executed only once 5307 // This is executed only once
5309 proc_task_unchecked = false; 5308 proc_task_unchecked = false;
5310 fp = fopen("/proc/self/task", "r"); 5309 fp = fopen("/proc/self/task", "r");
5311 if (fp != NULL) { 5310 if (fp != NULL) {
5312 snprintf(proc_name, 64, "/proc/self/task/%d/stat", tid); 5311 proc_stat_path = "/proc/self/task/%d/stat";
5313 fclose(fp); 5312 fclose(fp);
5314 } 5313 }
5315 } 5314 }
5316 5315
5316 sprintf(proc_name, proc_stat_path, tid);
5317 fp = fopen(proc_name, "r"); 5317 fp = fopen(proc_name, "r");
5318 if ( fp == NULL ) return -1; 5318 if ( fp == NULL ) return -1;
5319 statlen = fread(stat, 1, 2047, fp); 5319 statlen = fread(stat, 1, 2047, fp);
5320 stat[statlen] = '\0'; 5320 stat[statlen] = '\0';
5321 fclose(fp); 5321 fclose(fp);