summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <cgf@redhat.com>2003-07-10 01:10:44 +0000
committerChristopher Faylor <cgf@redhat.com>2003-07-10 01:10:44 +0000
commitce0f4904ca9d06f7c3a0ccc020a23d54eaa63929 (patch)
tree5246709ed6888888093026840d9d7160071993d4
parent259bc8ab1fd10a915d03c9dfa8eadc8dfe8cd8d2 (diff)
downloadgdb-ce0f4904ca9d06f7c3a0ccc020a23d54eaa63929.tar.gz
merge from trunk
-rw-r--r--winsup/cygwin/ChangeLog6
-rw-r--r--winsup/cygwin/fhandler_proc.cc77
2 files changed, 60 insertions, 23 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 47ee10ba6cb..909830d3868 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,11 @@
2003-07-09 Christopher Faylor <cgf@redhat.com>
+ * fhandler_proc.cc (fhandler_proc::fill_filebuf): Allocate more space
+ for stat buffer.
+ (format_proc_stat): Reorganize to accumulate and report on all cpus.
+
+2003-07-09 Christopher Faylor <cgf@redhat.com>
+
* sysconf.cc (sysconf): Return processors online rather than bitmask
for _SC_NPROCESSORS_ONLN.
diff --git a/winsup/cygwin/fhandler_proc.cc b/winsup/cygwin/fhandler_proc.cc
index 081fcf53771..668731748f6 100644
--- a/winsup/cygwin/fhandler_proc.cc
+++ b/winsup/cygwin/fhandler_proc.cc
@@ -344,7 +344,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;
}
@@ -451,24 +451,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,
@@ -481,10 +518,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;
/*
@@ -507,19 +540,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) \