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

Unified 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, 6 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 side-by-side diff with in-line comments
Download patch
Index: base/process/private_working_set_snapshot.h
diff --git a/base/process/private_working_set_snapshot.h b/base/process/private_working_set_snapshot.h
new file mode 100644
index 0000000000000000000000000000000000000000..ce6f09c926e4bd301a6cb7f81112bb562f38ddfe
--- /dev/null
+++ b/base/process/private_working_set_snapshot.h
@@ -0,0 +1,76 @@
+// 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
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#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.
+#define PRIVATE_WORKING_SET_SNAPSHOT_H_
+
+#include <vector>
+
+#include "base/base_export.h"
+#include "base/process/process_handle.h"
+
+#if defined(OS_WIN)
+
+#include <pdh.h>
+
+namespace base {
+
+// This class can be used to do bulk collection of private working sets. This
+// exists because on Windows it is much faster to collect a group of private
+// working sets all at once using PdhOpenQuery than to calculate the private
+// working sets for each process individually.
+class BASE_EXPORT PrivateWorkingSetSnapshot {
+ public:
+ PrivateWorkingSetSnapshot();
+ ~PrivateWorkingSetSnapshot();
+ // Add a process name that this object should monitor, such as "chrome". All
+ // processes whose name starts with this string will be monitored.
+ void AddToMonitorList(const std::string& process_name);
+ // Query the system for working-set information for all monitored processes
+ // and update the results cache. This function may take a few ms to run.
+ 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.
+ // Ask for the working set for a specific process, from the most recent call
+ // to Sample. If no data is available then zero will be returned. The result
+ // is in bytes.
+ size_t GetPrivateWorkingSet(base::ProcessId process_id) const;
+
+ private:
+ // The handle to the query object.
+ 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.
+
+ // This holds a pair of Pdh counters to queries for the process ID and private
+ // working set for a particular process name being monitored. The results from
+ // the two queries can be matched up so that we can associate a private
+ // working set with a process ID.
+ 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.
+ // The handle to the 'counter' that retrieves process IDs.
+ PDH_HCOUNTER process_id_handle = nullptr;
+ // The handle to the 'counter' that retrieves private working sets.
+ 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.
+ };
+ std::vector<PdhCounterPair> counter_pairs_;
+
+ 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
+ base::ProcessId process_id;
+ size_t private_ws;
+ // Comparison function for sorting.
+ bool operator<(const PidAndPrivateWS& other) const {
+ return process_id < other.process_id;
+ }
+ // Comparison function for searching.
+ bool operator<(const base::ProcessId other_process_id) const {
+ return process_id < other_process_id;
+ }
+ };
+ // After each call to Sample this will hold the results, sorted by process id.
+ std::vector<PidAndPrivateWS> records_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrivateWorkingSetSnapshot);
+};
+
+} // namespace base
+
+#endif // defined(OS_WIN)
+
+#endif // PRIVATE_WORKING_SET_SNAPSHOT_H_

Powered by Google App Engine
This is Rietveld 408576698