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

Side by Side Diff: base/process/private_working_set_snapshot.h

Issue 1181263005: Make task manager memory data more efficient and meaningful. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add missing include Created 5 years, 5 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
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
ncarter (slow) 2015/06/26 21:46:15 2015, and drop the (c) [yeah, seriously :( ] http
brucedawson 2015/06/27 00:13:05 Okay that's funny. Lesson learned about the perils
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef PRIVATE_WORKING_SET_SNAPSHOT_H_
ncarter (slow) 2015/06/26 21:46:15 This should be: BASE_PROCESS_PRIVATE_WORKING_SET_
brucedawson 2015/06/27 00:13:05 Done.
6 #define PRIVATE_WORKING_SET_SNAPSHOT_H_
7
8 #include <vector>
9
10 #include "base/base_export.h"
11 #include "base/process/process_handle.h"
12
13 #if defined(OS_WIN)
14
15 #include <pdh.h>
16
17 namespace base {
18
19 // This class can be used to do bulk collection of private working sets. This
20 // exists because on Windows it is much faster to collect a group of private
21 // working sets all at once using PdhOpenQuery than to calculate the private
22 // working sets for each process individually.
23 class BASE_EXPORT PrivateWorkingSetSnapshot {
24 public:
25 PrivateWorkingSetSnapshot();
26 ~PrivateWorkingSetSnapshot();
27 // Add a process name that this object should monitor, such as "chrome". All
28 // processes whose name starts with this string will be monitored.
29 void AddToMonitorList(const std::string& process_name);
30 // Query the system for working-set information for all monitored processes
31 // and update the results cache. This function may take a few ms to run.
32 void Sample();
ncarter (slow) 2015/06/26 21:46:15 I'd add a blank line between each method here. I t
brucedawson 2015/06/27 00:13:05 Done.
33 // Ask for the working set for a specific process, from the most recent call
34 // to Sample. If no data is available then zero will be returned. The result
35 // is in bytes.
36 size_t GetPrivateWorkingSet(base::ProcessId process_id) const;
37
38 private:
39 // The handle to the query object.
40 PDH_HQUERY query_handle_ = nullptr;
ncarter (slow) 2015/06/26 21:46:15 We talked over VC about switching this to win::Sco
brucedawson 2015/06/27 00:13:05 Done.
41
42 // This holds a pair of Pdh counters to queries for the process ID and private
43 // working set for a particular process name being monitored. The results from
44 // the two queries can be matched up so that we can associate a private
45 // working set with a process ID.
46 struct PdhCounterPair {
ncarter (slow) 2015/06/26 21:46:15 A strict reading of the style guide requires these
brucedawson 2015/06/27 00:13:05 Done.
47 // The handle to the 'counter' that retrieves process IDs.
48 PDH_HCOUNTER process_id_handle = nullptr;
49 // The handle to the 'counter' that retrieves private working sets.
50 PDH_HCOUNTER private_ws_handle = nullptr;
ncarter (slow) 2015/06/26 21:46:15 These handles don't need to be closed because thei
brucedawson 2015/06/27 00:13:05 Done.
51 };
52 std::vector<PdhCounterPair> counter_pairs_;
53
54 struct PidAndPrivateWS {
ncarter (slow) 2015/06/26 21:46:15 WS -> WorkingSet http://google-styleguide.googlec
brucedawson 2015/06/27 00:13:05 Done. Although, I also have a few private_ws memb
55 base::ProcessId process_id;
56 size_t private_ws;
57 // Comparison function for sorting.
58 bool operator<(const PidAndPrivateWS& other) const {
59 return process_id < other.process_id;
60 }
61 // Comparison function for searching.
62 bool operator<(const base::ProcessId other_process_id) const {
63 return process_id < other_process_id;
64 }
65 };
66 // After each call to Sample this will hold the results, sorted by process id.
67 std::vector<PidAndPrivateWS> records_;
68
69 DISALLOW_COPY_AND_ASSIGN(PrivateWorkingSetSnapshot);
70 };
71
72 } // namespace base
73
74 #endif // defined(OS_WIN)
75
76 #endif // PRIVATE_WORKING_SET_SNAPSHOT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698