2019-05-30 20:27:25 -07:00
|
|
|
From 6416e68e4d81d9b37d24076d446115f08f99bf81 Mon Sep 17 00:00:00 2001
|
2017-03-19 11:40:52 -07:00
|
|
|
From: =?UTF-8?q?Michael=20M=C3=BCller?= <michael@fds-team.de>
|
|
|
|
Date: Thu, 9 Mar 2017 16:27:23 +0100
|
2019-02-12 15:07:39 -08:00
|
|
|
Subject: [PATCH] ntdll: Fill process kernel and user time.
|
2017-03-19 11:40:52 -07:00
|
|
|
|
|
|
|
---
|
2019-05-30 20:27:25 -07:00
|
|
|
dlls/ntdll/nt.c | 6 ++-
|
|
|
|
dlls/ntdll/ntdll_misc.h | 4 ++
|
|
|
|
dlls/ntdll/thread.c | 84 +++++++++++++++++++++++------------------
|
|
|
|
3 files changed, 57 insertions(+), 37 deletions(-)
|
2017-03-19 11:40:52 -07:00
|
|
|
|
|
|
|
diff --git a/dlls/ntdll/nt.c b/dlls/ntdll/nt.c
|
2019-05-30 20:27:25 -07:00
|
|
|
index 2cd2ab327..c3250746b 100644
|
2017-03-19 11:40:52 -07:00
|
|
|
--- a/dlls/ntdll/nt.c
|
|
|
|
+++ b/dlls/ntdll/nt.c
|
2019-05-30 20:27:25 -07:00
|
|
|
@@ -2384,6 +2384,7 @@ NTSTATUS WINAPI NtQuerySystemInformation(
|
2017-03-19 11:40:52 -07:00
|
|
|
{
|
|
|
|
SYSTEM_PROCESS_INFORMATION* spi = SystemInformation;
|
|
|
|
SYSTEM_PROCESS_INFORMATION* last = NULL;
|
|
|
|
+ unsigned long clk_tck = sysconf(_SC_CLK_TCK);
|
|
|
|
HANDLE hSnap = 0;
|
|
|
|
WCHAR procname[1024];
|
|
|
|
WCHAR* exename;
|
2019-05-30 20:27:25 -07:00
|
|
|
@@ -2421,7 +2422,7 @@ NTSTATUS WINAPI NtQuerySystemInformation(
|
2017-03-19 11:40:52 -07:00
|
|
|
|
|
|
|
if (Length >= len + procstructlen)
|
|
|
|
{
|
|
|
|
- /* ftCreationTime, ftUserTime, ftKernelTime;
|
|
|
|
+ /* ftCreationTime;
|
|
|
|
* vmCounters, ioCounters
|
|
|
|
*/
|
|
|
|
|
2019-05-30 20:27:25 -07:00
|
|
|
@@ -2439,6 +2440,9 @@ NTSTATUS WINAPI NtQuerySystemInformation(
|
2017-03-19 11:40:52 -07:00
|
|
|
|
|
|
|
/* spi->ti will be set later on */
|
|
|
|
|
|
|
|
+ if (reply->unix_pid != -1)
|
|
|
|
+ read_process_time(reply->unix_pid, -1, clk_tck,
|
|
|
|
+ &spi->KernelTime, &spi->UserTime);
|
|
|
|
}
|
|
|
|
len += procstructlen;
|
|
|
|
}
|
|
|
|
diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h
|
2019-05-30 20:27:25 -07:00
|
|
|
index 3463ebd38..78831cf37 100644
|
2017-03-19 11:40:52 -07:00
|
|
|
--- a/dlls/ntdll/ntdll_misc.h
|
|
|
|
+++ b/dlls/ntdll/ntdll_misc.h
|
2019-05-30 20:27:25 -07:00
|
|
|
@@ -265,6 +265,10 @@ extern SYSTEM_CPU_INFORMATION cpu_info DECLSPEC_HIDDEN;
|
2017-03-19 11:40:52 -07:00
|
|
|
NTSTATUS WINAPI RtlHashUnicodeString(PCUNICODE_STRING,BOOLEAN,ULONG,ULONG*);
|
2019-02-14 16:18:02 -08:00
|
|
|
void WINAPI LdrInitializeThunk(CONTEXT*,void**,ULONG_PTR,ULONG_PTR);
|
2017-03-19 11:40:52 -07:00
|
|
|
|
|
|
|
+/* process / thread time */
|
|
|
|
+extern BOOL read_process_time(int unix_pid, int unix_tid, unsigned long clk_tck,
|
|
|
|
+ LARGE_INTEGER *kernel, LARGE_INTEGER *user) DECLSPEC_HIDDEN;
|
2019-03-26 17:07:38 -07:00
|
|
|
+
|
|
|
|
/* string functions */
|
|
|
|
int __cdecl NTDLL_tolower( int c );
|
|
|
|
int __cdecl _stricmp( LPCSTR str1, LPCSTR str2 );
|
2017-03-19 11:40:52 -07:00
|
|
|
diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c
|
2019-05-30 20:27:25 -07:00
|
|
|
index 70320afe7..8dac11393 100644
|
2017-03-19 11:40:52 -07:00
|
|
|
--- a/dlls/ntdll/thread.c
|
|
|
|
+++ b/dlls/ntdll/thread.c
|
2019-02-14 16:18:02 -08:00
|
|
|
@@ -149,6 +149,53 @@ static ULONG_PTR get_image_addr(void)
|
2019-02-12 15:07:39 -08:00
|
|
|
}
|
|
|
|
#endif
|
2017-03-19 11:40:52 -07:00
|
|
|
|
|
|
|
+
|
|
|
|
+BOOL read_process_time(int unix_pid, int unix_tid, unsigned long clk_tck,
|
|
|
|
+ LARGE_INTEGER *kernel, LARGE_INTEGER *user)
|
|
|
|
+{
|
|
|
|
+#ifdef __linux__
|
|
|
|
+ unsigned long usr, sys;
|
|
|
|
+ char buf[512], *pos;
|
|
|
|
+ FILE *fp;
|
|
|
|
+ int i;
|
|
|
|
+
|
|
|
|
+ /* based on https://github.com/torvalds/linux/blob/master/fs/proc/array.c */
|
|
|
|
+ if (unix_tid != -1)
|
|
|
|
+ sprintf( buf, "/proc/%u/task/%u/stat", unix_pid, unix_tid );
|
|
|
|
+ else
|
|
|
|
+ sprintf( buf, "/proc/%u/stat", unix_pid );
|
|
|
|
+ if ((fp = fopen( buf, "r" )))
|
|
|
|
+ {
|
|
|
|
+ pos = fgets( buf, sizeof(buf), fp );
|
|
|
|
+ fclose( fp );
|
|
|
|
+
|
|
|
|
+ /* format of first chunk is "%d (%s) %c" - we have to skip to the last ')'
|
|
|
|
+ * to avoid misinterpreting the string. */
|
|
|
|
+ if (pos) pos = strrchr( pos, ')' );
|
|
|
|
+ if (pos) pos = strchr( pos + 1, ' ' );
|
|
|
|
+ if (pos) pos++;
|
|
|
|
+
|
|
|
|
+ /* skip over the following fields: state, ppid, pgid, sid, tty_nr, tty_pgrp,
|
|
|
|
+ * task->flags, min_flt, cmin_flt, maj_flt, cmaj_flt */
|
|
|
|
+ for (i = 0; (i < 11) && pos; i++)
|
|
|
|
+ {
|
|
|
|
+ pos = strchr( pos + 1, ' ' );
|
|
|
|
+ if (pos) pos++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* the next two values are user and system time */
|
|
|
|
+ if (pos && (sscanf( pos, "%lu %lu", &usr, &sys ) == 2))
|
|
|
|
+ {
|
|
|
|
+ kernel->QuadPart = (ULONGLONG)sys * 10000000 / clk_tck;
|
|
|
|
+ user->QuadPart = (ULONGLONG)usr * 10000000 / clk_tck;
|
|
|
|
+ return TRUE;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
+ return FALSE;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
/***********************************************************************
|
2019-02-12 15:07:39 -08:00
|
|
|
* thread_init
|
2017-03-19 11:40:52 -07:00
|
|
|
*
|
2019-05-16 15:58:11 -07:00
|
|
|
@@ -902,42 +949,7 @@ NTSTATUS WINAPI NtQueryInformationThread( HANDLE handle, THREADINFOCLASS class,
|
2017-03-19 11:40:52 -07:00
|
|
|
#ifdef __linux__
|
|
|
|
/* only /proc provides exact values for a specific thread */
|
|
|
|
if (unix_pid != -1 && unix_tid != -1)
|
|
|
|
- {
|
|
|
|
- unsigned long usr, sys;
|
|
|
|
- char buf[512], *pos;
|
|
|
|
- FILE *fp;
|
|
|
|
- int i;
|
|
|
|
-
|
|
|
|
- /* based on https://github.com/torvalds/linux/blob/master/fs/proc/array.c */
|
|
|
|
- sprintf( buf, "/proc/%u/task/%u/stat", unix_pid, unix_tid );
|
|
|
|
- if ((fp = fopen( buf, "r" )))
|
|
|
|
- {
|
|
|
|
- pos = fgets( buf, sizeof(buf), fp );
|
|
|
|
- fclose( fp );
|
|
|
|
-
|
|
|
|
- /* format of first chunk is "%d (%s) %c" - we have to skip to the last ')'
|
|
|
|
- * to avoid misinterpreting the string. */
|
|
|
|
- if (pos) pos = strrchr( pos, ')' );
|
|
|
|
- if (pos) pos = strchr( pos + 1, ' ' );
|
|
|
|
- if (pos) pos++;
|
|
|
|
-
|
|
|
|
- /* skip over the following fields: state, ppid, pgid, sid, tty_nr, tty_pgrp,
|
|
|
|
- * task->flags, min_flt, cmin_flt, maj_flt, cmaj_flt */
|
|
|
|
- for (i = 0; (i < 11) && pos; i++)
|
|
|
|
- {
|
|
|
|
- pos = strchr( pos + 1, ' ' );
|
|
|
|
- if (pos) pos++;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /* the next two values are user and system time */
|
|
|
|
- if (pos && (sscanf( pos, "%lu %lu", &usr, &sys ) == 2))
|
|
|
|
- {
|
|
|
|
- kusrt.KernelTime.QuadPart = (ULONGLONG)sys * 10000000 / clk_tck;
|
|
|
|
- kusrt.UserTime.QuadPart = (ULONGLONG)usr * 10000000 / clk_tck;
|
|
|
|
- filled_times = TRUE;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
+ filled_times = read_process_time(unix_pid, unix_tid, clk_tck, &kusrt.KernelTime, &kusrt.UserTime);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get values for current process instead */
|
|
|
|
--
|
2019-05-30 20:27:25 -07:00
|
|
|
2.21.0
|
2017-03-19 11:40:52 -07:00
|
|
|
|