Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2003-07-10 05:09:24 +0400
committerChristopher Faylor <me@cgf.cx>2003-07-10 05:09:24 +0400
commitcf38615c3b9052dc19ed249bffcc46a7b2117ffc (patch)
treef1c8fe0ad655b0e00988f22cf84e3a49efb8f811 /winsup/cygwin/fhandler_proc.cc
parentab3dc80d9e4852a01e8fd1ff265e38aab1e06dd5 (diff)
* fhandler_proc.cc (fhandler_proc::fill_filebuf): Allocate more space for stat
buffer. (format_proc_stat): Reorganize to accumulate and report on all cpus.
Diffstat (limited to 'winsup/cygwin/fhandler_proc.cc')
-rw-r--r--winsup/cygwin/fhandler_proc.cc77
1 files changed, 54 insertions, 23 deletions
diff --git a/winsup/cygwin/fhandler_proc.cc b/winsup/cygwin/fhandler_proc.cc
index 286a8a23f..57d91ffce 100644
--- a/winsup/cygwin/fhandler_proc.cc
+++ b/winsup/cygwin/fhandler_proc.cc
@@ -349,7 +349,7 @@ fhandler_proc::fill_filebuf ()
}
case PROC_STAT:
{
- filebuf = (char *) realloc (filebuf, bufalloc = 2048);
+ filebuf = (char *) realloc (filebuf, bufalloc = 16384);
filesize = format_proc_stat (filebuf, bufalloc);
break;
}
@@ -456,24 +456,61 @@ out:
static _off64_t
format_proc_stat (char *destbuf, size_t maxsize)
{
- unsigned long long user_time = 0ULL, kernel_time = 0ULL, idle_time = 0ULL;
unsigned long pages_in = 0UL, pages_out = 0UL, interrupt_count = 0UL,
context_switches = 0UL, swap_in = 0UL, swap_out = 0UL;
time_t boot_time = 0;
- if (wincap.is_winnt ())
+ char *eobuf = destbuf;
+ if (!wincap.is_winnt ())
+ eobuf += __small_sprintf (destbuf, "cpu %U %U %U %U\n", 0, 0, 0, 0);
+ else
{
NTSTATUS ret;
- SYSTEM_PROCESSOR_TIMES spt;
SYSTEM_PERFORMANCE_INFORMATION spi;
SYSTEM_TIME_OF_DAY_INFORMATION stodi;
- ret = NtQuerySystemInformation (SystemProcessorTimes,
- (PVOID) &spt,
- sizeof spt, NULL);
+
+ SYSTEM_BASIC_INFORMATION sbi;
+ if ((ret = NtQuerySystemInformation (SystemBasicInformation,
+ (PVOID) &sbi, sizeof sbi, NULL))
+ != STATUS_SUCCESS)
+ {
+ __seterrno_from_win_error (RtlNtStatusToDosError (ret));
+ debug_printf ("NtQuerySystemInformation: ret = %d, "
+ "Dos(ret) = %d",
+ ret, RtlNtStatusToDosError (ret));
+ sbi.NumberProcessors = 1;
+ }
+
+ SYSTEM_PROCESSOR_TIMES spt[sbi.NumberProcessors];
+ ret = NtQuerySystemInformation (SystemProcessorTimes, (PVOID) spt,
+ sizeof spt[0] * sbi.NumberProcessors, NULL);
+ interrupt_count = 0;
if (ret == STATUS_SUCCESS)
- ret = NtQuerySystemInformation (SystemPerformanceInformation,
- (PVOID) &spi,
- sizeof spi, NULL);
+ {
+ unsigned long long user_time = 0ULL, kernel_time = 0ULL, idle_time = 0ULL;
+ for (int i = 0; i < sbi.NumberProcessors; i++)
+ {
+ kernel_time += (spt[i].KernelTime.QuadPart - spt[i].IdleTime.QuadPart) * HZ / 10000000ULL;
+ user_time += spt[i].UserTime.QuadPart * HZ / 10000000ULL;
+ idle_time += spt[i].IdleTime.QuadPart * HZ / 10000000ULL;
+ }
+
+ eobuf += __small_sprintf (eobuf, "cpu %U %U %U %U\n",
+ user_time, 0ULL, kernel_time, idle_time);
+ user_time = 0ULL, kernel_time = 0ULL, idle_time = 0ULL;
+ for (int i = 0; i < sbi.NumberProcessors; i++)
+ {
+ interrupt_count += spt[i].InterruptCount;
+ kernel_time = (spt[i].KernelTime.QuadPart - spt[i].IdleTime.QuadPart) * HZ / 10000000ULL;
+ user_time = spt[i].UserTime.QuadPart * HZ / 10000000ULL;
+ idle_time = spt[i].IdleTime.QuadPart * HZ / 10000000ULL;
+ eobuf += __small_sprintf (eobuf, "cpu%d %U %U %U %U\n", i,
+ user_time, 0ULL, kernel_time, idle_time);
+ }
+
+ ret = NtQuerySystemInformation (SystemPerformanceInformation,
+ (PVOID) &spi, sizeof spi, NULL);
+ }
if (ret == STATUS_SUCCESS)
ret = NtQuerySystemInformation (SystemTimeOfDayInformation,
(PVOID) &stodi,
@@ -486,10 +523,6 @@ format_proc_stat (char *destbuf, size_t maxsize)
ret, RtlNtStatusToDosError (ret));
return 0;
}
- kernel_time = (spt.KernelTime.QuadPart - spt.IdleTime.QuadPart) * HZ / 10000000ULL;
- user_time = spt.UserTime.QuadPart * HZ / 10000000ULL;
- idle_time = spt.IdleTime.QuadPart * HZ / 10000000ULL;
- interrupt_count = spt.InterruptCount;
pages_in = spi.PagesRead;
pages_out = spi.PagefilePagesWritten + spi.MappedFilePagesWritten;
/*
@@ -512,19 +545,17 @@ format_proc_stat (char *destbuf, size_t maxsize)
* counters is by no means worth it.
* }
*/
- return __small_sprintf (destbuf, "cpu %U %U %U %U\n"
- "page %u %u\n"
+ eobuf += __small_sprintf (eobuf, "page %u %u\n"
"swap %u %u\n"
"intr %u\n"
"ctxt %u\n"
"btime %u\n",
- user_time, 0ULL,
- kernel_time, idle_time,
- pages_in, pages_out,
- swap_in, swap_out,
- interrupt_count,
- context_switches,
- boot_time);
+ pages_in, pages_out,
+ swap_in, swap_out,
+ interrupt_count,
+ context_switches,
+ boot_time);
+ return eobuf - destbuf;
}
#define read_value(x,y) \