Mercurial > hg > graal-jvmci-8
comparison src/os/linux/vm/os_linux.cpp @ 14658:d72cee0607a3
8036122: Fix warning 'format not a string literal'
Reviewed-by: mduigou, kvn
author | goetz |
---|---|
date | Mon, 03 Mar 2014 11:54:35 +0100 |
parents | bb9356ec5967 |
children | b51e29501f30 |
comparison
equal
deleted
inserted
replaced
14657:4adcdd3ccb66 | 14658:d72cee0607a3 |
---|---|
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"; | |
5288 pid_t tid = thread->osthread()->thread_id(); | 5287 pid_t tid = thread->osthread()->thread_id(); |
5289 char *s; | 5288 char *s; |
5290 char stat[2048]; | 5289 char stat[2048]; |
5291 int statlen; | 5290 int statlen; |
5292 char proc_name[64]; | 5291 char proc_name[64]; |
5295 char cdummy; | 5294 char cdummy; |
5296 int idummy; | 5295 int idummy; |
5297 long ldummy; | 5296 long ldummy; |
5298 FILE *fp; | 5297 FILE *fp; |
5299 | 5298 |
5299 snprintf(proc_name, 64, "/proc/%d/stat", tid); | |
5300 | |
5300 // The /proc/<tid>/stat aggregates per-process usage on | 5301 // The /proc/<tid>/stat aggregates per-process usage on |
5301 // new Linux kernels 2.6+ where NPTL is supported. | 5302 // new Linux kernels 2.6+ where NPTL is supported. |
5302 // The /proc/self/task/<tid>/stat still has the per-thread usage. | 5303 // The /proc/self/task/<tid>/stat still has the per-thread usage. |
5303 // See bug 6328462. | 5304 // See bug 6328462. |
5304 // There possibly can be cases where there is no directory | 5305 // There possibly can be cases where there is no directory |
5306 if (proc_task_unchecked && os::Linux::is_NPTL()) { | 5307 if (proc_task_unchecked && os::Linux::is_NPTL()) { |
5307 // This is executed only once | 5308 // This is executed only once |
5308 proc_task_unchecked = false; | 5309 proc_task_unchecked = false; |
5309 fp = fopen("/proc/self/task", "r"); | 5310 fp = fopen("/proc/self/task", "r"); |
5310 if (fp != NULL) { | 5311 if (fp != NULL) { |
5311 proc_stat_path = "/proc/self/task/%d/stat"; | 5312 snprintf(proc_name, 64, "/proc/self/task/%d/stat", tid); |
5312 fclose(fp); | 5313 fclose(fp); |
5313 } | 5314 } |
5314 } | 5315 } |
5315 | 5316 |
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); |