Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: base/process/process_metrics_win.cc

Issue 2779413002: Duplicate process handle in process_metrics_win.cc (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/process/process_metrics.h" 5 #include "base/process/process_metrics.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <psapi.h> 8 #include <psapi.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 13 matching lines...) Expand all
24 const int PAGESIZE_KB = 4; 24 const int PAGESIZE_KB = 4;
25 25
26 typedef NTSTATUS(WINAPI* NTQUERYSYSTEMINFORMATION)( 26 typedef NTSTATUS(WINAPI* NTQUERYSYSTEMINFORMATION)(
27 SYSTEM_INFORMATION_CLASS SystemInformationClass, 27 SYSTEM_INFORMATION_CLASS SystemInformationClass,
28 PVOID SystemInformation, 28 PVOID SystemInformation,
29 ULONG SystemInformationLength, 29 ULONG SystemInformationLength,
30 PULONG ReturnLength); 30 PULONG ReturnLength);
31 31
32 } // namespace 32 } // namespace
33 33
34 ProcessMetrics::~ProcessMetrics() { } 34 ProcessMetrics::~ProcessMetrics() {
35 if (process_)
36 ::CloseHandle(process_);
brucedawson 2017/03/30 23:09:46 Shouldn't this use a handle wrapper class rather t
stanisc 2017/03/30 23:24:34 It should, but process_ field is defined in the he
37 }
35 38
36 // static 39 // static
37 std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics( 40 std::unique_ptr<ProcessMetrics> ProcessMetrics::CreateProcessMetrics(
38 ProcessHandle process) { 41 ProcessHandle process) {
39 return WrapUnique(new ProcessMetrics(process)); 42 return WrapUnique(new ProcessMetrics(process));
40 } 43 }
41 44
42 size_t ProcessMetrics::GetPagefileUsage() const { 45 size_t ProcessMetrics::GetPagefileUsage() const {
43 PROCESS_MEMORY_COUNTERS pmc; 46 PROCESS_MEMORY_COUNTERS pmc;
44 if (GetProcessMemoryInfo(process_, &pmc, sizeof(pmc))) { 47 if (GetProcessMemoryInfo(process_, &pmc, sizeof(pmc))) {
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 last_cpu_time_ = time; 315 last_cpu_time_ = time;
313 316
314 return static_cast<double>(system_time_delta * 100.0) / time_delta; 317 return static_cast<double>(system_time_delta * 100.0) / time_delta;
315 } 318 }
316 319
317 bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const { 320 bool ProcessMetrics::GetIOCounters(IoCounters* io_counters) const {
318 return GetProcessIoCounters(process_, io_counters) != FALSE; 321 return GetProcessIoCounters(process_, io_counters) != FALSE;
319 } 322 }
320 323
321 ProcessMetrics::ProcessMetrics(ProcessHandle process) 324 ProcessMetrics::ProcessMetrics(ProcessHandle process)
322 : process_(process), 325 : process_(nullptr),
323 processor_count_(SysInfo::NumberOfProcessors()), 326 processor_count_(SysInfo::NumberOfProcessors()),
324 last_system_time_(0) {} 327 last_system_time_(0) {
328 if (process) {
329 BOOL result =
330 ::DuplicateHandle(::GetCurrentProcess(), process, ::GetCurrentProcess(),
331 &process_, PROCESS_QUERY_INFORMATION, FALSE, 0);
332 DCHECK(result);
333 }
334 }
325 335
326 size_t GetSystemCommitCharge() { 336 size_t GetSystemCommitCharge() {
327 // Get the System Page Size. 337 // Get the System Page Size.
328 SYSTEM_INFO system_info; 338 SYSTEM_INFO system_info;
329 GetSystemInfo(&system_info); 339 GetSystemInfo(&system_info);
330 340
331 PERFORMANCE_INFORMATION info; 341 PERFORMANCE_INFORMATION info;
332 if (!GetPerformanceInfo(&info, sizeof(info))) { 342 if (!GetPerformanceInfo(&info, sizeof(info))) {
333 DLOG(ERROR) << "Failed to fetch internal performance info."; 343 DLOG(ERROR) << "Failed to fetch internal performance info.";
334 return 0; 344 return 0;
(...skipping 19 matching lines...) Expand all
354 364
355 meminfo->total = mem_status.ullTotalPhys / 1024; 365 meminfo->total = mem_status.ullTotalPhys / 1024;
356 meminfo->avail_phys = mem_status.ullAvailPhys / 1024; 366 meminfo->avail_phys = mem_status.ullAvailPhys / 1024;
357 meminfo->swap_total = mem_status.ullTotalPageFile / 1024; 367 meminfo->swap_total = mem_status.ullTotalPageFile / 1024;
358 meminfo->swap_free = mem_status.ullAvailPageFile / 1024; 368 meminfo->swap_free = mem_status.ullAvailPageFile / 1024;
359 369
360 return true; 370 return true;
361 } 371 }
362 372
363 } // namespace base 373 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698