Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/ntdll/unix/process.c | 19 ++++++----- server/process.c | 69 +++++++++++++++++++++------------------ server/protocol.def | 13 +++++--- server/trace.c | 12 +++++++ tools/make_requests | 1 + 5 files changed, 70 insertions(+), 44 deletions(-)
diff --git a/dlls/ntdll/unix/process.c b/dlls/ntdll/unix/process.c index 7061d8864db..8c0b97922d2 100644 --- a/dlls/ntdll/unix/process.c +++ b/dlls/ntdll/unix/process.c @@ -1057,6 +1057,16 @@ static void fill_VM_COUNTERS( VM_COUNTERS_EX *pvmi )
#endif
+static void vm_counters_from_server( VM_COUNTERS_EX *to, const vm_counters_t *from ) +{ + to->PeakVirtualSize = from->peak_virtual_size; + to->VirtualSize = from->virtual_size; + to->PeakWorkingSetSize = from->peak_working_set_size; + to->WorkingSetSize = from->working_set_size; + to->PagefileUsage = from->pagefile_usage; + to->PeakPagefileUsage = from->peak_pagefile_usage; +} + #define UNIMPLEMENTED_INFO_CLASS(c) \ case c: \ FIXME( "(process=%p) Unimplemented information class: " #c "\n", handle); \ @@ -1178,14 +1188,7 @@ NTSTATUS WINAPI NtQueryInformationProcess( HANDLE handle, PROCESSINFOCLASS class { req->handle = wine_server_obj_handle( handle ); if (!(ret = wine_server_call( req ))) - { - pvmi.PeakVirtualSize = reply->peak_virtual_size; - pvmi.VirtualSize = reply->virtual_size; - pvmi.PeakWorkingSetSize = reply->peak_working_set_size; - pvmi.WorkingSetSize = reply->working_set_size; - pvmi.PagefileUsage = reply->pagefile_usage; - pvmi.PeakPagefileUsage = reply->peak_pagefile_usage; - } + vm_counters_from_server( &pvmi, &reply->counters ); } SERVER_END_REQ; if (ret) break; diff --git a/server/process.c b/server/process.c index 5e587b28cbe..7d3429d9635 100644 --- a/server/process.c +++ b/server/process.c @@ -1086,6 +1086,42 @@ int set_process_debug_flag( struct process *process, int flag ) return write_process_memory( process, process->peb + 2, 1, &data ); }
+void get_vm_counters( vm_counters_t *counters, struct process *process ) +{ +#ifdef linux + if (process->unix_pid != -1) + { + FILE *f; + char proc_path[32], line[256]; + unsigned long value; + + sprintf( proc_path, "/proc/%u/status", process->unix_pid ); + if ((f = fopen( proc_path, "r" ))) + { + while (fgets( line, sizeof(line), f )) + { + if (sscanf( line, "VmPeak: %lu", &value )) + counters->peak_virtual_size = (mem_size_t)value * 1024; + else if (sscanf( line, "VmSize: %lu", &value )) + counters->virtual_size = (mem_size_t)value * 1024; + else if (sscanf( line, "VmHWM: %lu", &value )) + counters->peak_working_set_size = (mem_size_t)value * 1024; + else if (sscanf( line, "VmRSS: %lu", &value )) + counters->working_set_size = (mem_size_t)value * 1024; + else if (sscanf( line, "RssAnon: %lu", &value )) + counters->pagefile_usage += (mem_size_t)value * 1024; + else if (sscanf( line, "VmSwap: %lu", &value )) + counters->pagefile_usage += (mem_size_t)value * 1024; + } + counters->peak_pagefile_usage = counters->pagefile_usage; + fclose( f ); + } + else set_error( STATUS_ACCESS_DENIED ); + } + else set_error( STATUS_ACCESS_DENIED ); +#endif +} + /* create a new process */ DECL_HANDLER(new_process) { @@ -1430,38 +1466,7 @@ DECL_HANDLER(get_process_vm_counters) struct process *process = get_process_from_handle( req->handle, PROCESS_QUERY_LIMITED_INFORMATION );
if (!process) return; -#ifdef linux - if (process->unix_pid != -1) - { - FILE *f; - char proc_path[32], line[256]; - unsigned long value; - - sprintf( proc_path, "/proc/%u/status", process->unix_pid ); - if ((f = fopen( proc_path, "r" ))) - { - while (fgets( line, sizeof(line), f )) - { - if (sscanf( line, "VmPeak: %lu", &value )) - reply->peak_virtual_size = (mem_size_t)value * 1024; - else if (sscanf( line, "VmSize: %lu", &value )) - reply->virtual_size = (mem_size_t)value * 1024; - else if (sscanf( line, "VmHWM: %lu", &value )) - reply->peak_working_set_size = (mem_size_t)value * 1024; - else if (sscanf( line, "VmRSS: %lu", &value )) - reply->working_set_size = (mem_size_t)value * 1024; - else if (sscanf( line, "RssAnon: %lu", &value )) - reply->pagefile_usage += (mem_size_t)value * 1024; - else if (sscanf( line, "VmSwap: %lu", &value )) - reply->pagefile_usage += (mem_size_t)value * 1024; - } - reply->peak_pagefile_usage = reply->pagefile_usage; - fclose( f ); - } - else set_error( STATUS_ACCESS_DENIED ); - } - else set_error( STATUS_ACCESS_DENIED ); -#endif + get_vm_counters( &reply->counters, process ); release_object( process ); }
diff --git a/server/protocol.def b/server/protocol.def index 943c1ade1a4..9f5cd3bc79e 100644 --- a/server/protocol.def +++ b/server/protocol.def @@ -918,16 +918,21 @@ struct rawinput_device @END
-/* Retrieve information about a process memory usage */ -@REQ(get_process_vm_counters) - obj_handle_t handle; /* process handle */ -@REPLY +typedef struct +{ mem_size_t peak_virtual_size; /* peak virtual memory in bytes */ mem_size_t virtual_size; /* virtual memory in bytes */ mem_size_t peak_working_set_size; /* peak real memory in bytes */ mem_size_t working_set_size; /* real memory in bytes */ mem_size_t pagefile_usage; /* commit charge in bytes */ mem_size_t peak_pagefile_usage; /* peak commit charge in bytes */ +} vm_counters_t; + +/* Retrieve information about a process memory usage */ +@REQ(get_process_vm_counters) + obj_handle_t handle; /* process handle */ +@REPLY + vm_counters_t counters; @END
diff --git a/server/trace.c b/server/trace.c index 55d7bd85dd6..8e73af239d2 100644 --- a/server/trace.c +++ b/server/trace.c @@ -410,6 +410,18 @@ static void dump_hw_input( const char *prefix, const hw_input_t *input ) } }
+static void dump_vm_counters( const char *prefix, const vm_counters_t *counters ) +{ + fprintf( stderr, "%s{", prefix ); + dump_uint64( "peak_virtual_size=", &counters->peak_virtual_size ); + dump_uint64( ", virtual_size=", &counters->virtual_size ); + dump_uint64( ", peak_working_set_size=", &counters->peak_working_set_size ); + dump_uint64( ", working_set_size=", &counters->working_set_size ); + dump_uint64( ", pagefile_usage=", &counters->pagefile_usage ); + dump_uint64( ", peak_pagefile_usage=", &counters->peak_pagefile_usage ); + fputc( '}', stderr ); +} + static void dump_luid( const char *prefix, const luid_t *luid ) { fprintf( stderr, "%s%d.%u", prefix, luid->high_part, luid->low_part ); diff --git a/tools/make_requests b/tools/make_requests index 60324d07989..354e70866c0 100755 --- a/tools/make_requests +++ b/tools/make_requests @@ -54,6 +54,7 @@ my %formats = "ioctl_code_t" => [ 4, 4, "&dump_ioctl_code" ], "client_cpu_t" => [ 4, 4, "&dump_client_cpu" ], "hw_input_t" => [ 32, 8, "&dump_hw_input" ], + "vm_counters_t" => [ 48, 8, "&dump_vm_counters" ], );
my @requests = ();