5283 char cdummy; |
5282 char cdummy; |
5284 int idummy; |
5283 int idummy; |
5285 long ldummy; |
5284 long ldummy; |
5286 FILE *fp; |
5285 FILE *fp; |
5287 |
5286 |
5288 snprintf(proc_name, 64, "/proc/%d/stat", tid); |
5287 snprintf(proc_name, 64, "/proc/self/task/%d/stat", tid); |
5289 |
|
5290 // The /proc/<tid>/stat aggregates per-process usage on |
|
5291 // new Linux kernels 2.6+ where NPTL is supported. |
|
5292 // The /proc/self/task/<tid>/stat still has the per-thread usage. |
|
5293 // See bug 6328462. |
|
5294 // There possibly can be cases where there is no directory |
|
5295 // /proc/self/task, so we check its availability. |
|
5296 if (proc_task_unchecked && os::Linux::is_NPTL()) { |
|
5297 // This is executed only once |
|
5298 proc_task_unchecked = false; |
|
5299 fp = fopen("/proc/self/task", "r"); |
|
5300 if (fp != NULL) { |
|
5301 snprintf(proc_name, 64, "/proc/self/task/%d/stat", tid); |
|
5302 fclose(fp); |
|
5303 } |
|
5304 } |
|
5305 |
|
5306 fp = fopen(proc_name, "r"); |
5288 fp = fopen(proc_name, "r"); |
5307 if ( fp == NULL ) return -1; |
5289 if ( fp == NULL ) return -1; |
5308 statlen = fread(stat, 1, 2047, fp); |
5290 statlen = fread(stat, 1, 2047, fp); |
5309 stat[statlen] = '\0'; |
5291 stat[statlen] = '\0'; |
5310 fclose(fp); |
5292 fclose(fp); |