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

Side by Side Diff: chrome/browser/task_management/sampling/shared_sampler.h

Issue 2178733002: Task manager should support Idle Wakeups on Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed build error on win_clang. Created 4 years, 4 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 2016 The Chromium Authors. All rights reserved.
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 CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_SHARED_SAMPLER_H_
6 #define CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_SHARED_SAMPLER_H_
7
8 #include <map>
9 #include <memory>
10 #include <utility>
11 #include <vector>
12
13 #include "base/callback.h"
14 #include "base/files/file_path.h"
15 #include "base/macros.h"
16 #include "base/memory/ref_counted.h"
17 #include "base/process/process_handle.h"
18 #include "base/sequence_checker.h"
19 #include "base/sequenced_task_runner.h"
20 #include "build/build_config.h"
21
22 namespace task_management {
23
24 struct ProcessDataSnapshot;
25
26 // Defines sampler that will calculate resources for all processes all at once,
27 // on the worker thread. Created by TaskManagerImpl the UI thread, but used
28 // mainly on a blocking pool thread.
ncarter (slow) 2016/07/28 21:37:26 PrivateWorkingSetSnapshot had the following commen
stanisc 2016/07/28 22:38:43 Good idea!
stanisc 2016/08/01 22:34:26 Done.
29 class SharedSampler : public base::RefCountedThreadSafe<SharedSampler> {
30 public:
31 SharedSampler(
ncarter (slow) 2016/07/28 21:37:26 single-arg ctor should be explicit
stanisc 2016/08/01 22:34:26 Done.
32 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner);
33
34 // The below are the types of the callbacks to the UI thread upon their
35 // corresponding refresh are done on the worker thread.
36 using OnIdleWakeupsCallback = base::Callback<void(int)>;
37
38 // Returns a combination of refresh flags supported by the shared sampler.
39 int64_t SupportsFlags() const;
40
41 // Registers task group specific callbacks.
42 void RegisterCallbacks(base::ProcessId process_id,
43 const OnIdleWakeupsCallback& on_idle_wakeups);
44
45 // Unregisters task group specific callbacks.
46 void UnregisterCallbacks(base::ProcessId process_id);
47
48 // Refreshes the expensive process' stats (for now only idle wakeups per
49 // second) on the worker thread.
50 void Refresh(base::ProcessId process_id, int64_t refresh_flags);
51
52 private:
53 friend class base::RefCountedThreadSafe<SharedSampler>;
54 ~SharedSampler();
55
56 #if defined(OS_WIN)
57 // The UI-thread callbacks in TaskGroup registered with RegisterCallbacks and
58 // to be called when refresh on the worker thread is done.
59 struct Callbacks {
60 Callbacks();
61 Callbacks(Callbacks&& other);
ncarter (slow) 2016/07/28 21:37:26 could this be = default? That saves us from havin
stanisc 2016/07/28 22:38:43 I tried '= default' but that still generated an er
stanisc 2016/08/01 22:34:26 See win_clang error in patchset #5: https://build.
ncarter (slow) 2016/08/03 22:28:55 OK. Thanks for trying.
62 ~Callbacks();
63
64 OnIdleWakeupsCallback on_idle_wakeups;
65
66 private:
67 DISALLOW_COPY_AND_ASSIGN(Callbacks);
68 };
69
70 typedef std::map<base::ProcessId, Callbacks> CallbacksMap;
71
72 // Contains all results of refresh for a single process.
73 struct RefreshResult {
74 int idle_wakeups_per_second;
75 };
76
77 typedef std::map<base::ProcessId, RefreshResult> RefreshResultMap;
ncarter (slow) 2016/07/28 21:37:26 A vector would probably be faster.
stanisc 2016/07/28 22:38:43 I thought about that but then I'd have to deal wit
stanisc 2016/08/01 22:34:26 Done.
78
79 // Posted on the worker thread to do the actual refresh.
80 std::unique_ptr<RefreshResultMap> RefreshOnWorkerThread();
81
82 // Called on UI thread when the refresh is done.
83 void OnRefreshDone(std::unique_ptr<RefreshResultMap> refresh_results);
84
85 // Used to filter process information.
86 bool IsChromeImageName(const wchar_t* image_name) const;
87
88 // Captures a snapshot of data for all chrome processes.
89 // Runs on the worker thread.
90 std::unique_ptr<ProcessDataSnapshot> CaptureSnapshot();
91
92 // Produce refresh results by diffing two snapshots.
93 static void MakeResultsFromTwoSnapshots(
94 const ProcessDataSnapshot& prev_snapshot,
95 const ProcessDataSnapshot& snapshot,
96 RefreshResultMap* results);
97
98 // Produce refresh results from one snapshot.
99 // This is used only the first time when only one snapshot is available.
100 static void MakeResultsFromSnapshot(
101 const ProcessDataSnapshot& snapshot,
102 RefreshResultMap* results);
103
104 // Accumulates callbacks passed from TaskGroup objects passed via
105 // RegisterCallbacks calls.
106 CallbacksMap callbacks_map_;
107
108 // Accumulates per-process refresh flags passed via Refresh calls.
109 std::vector<std::pair<base::ProcessId, int64_t>> refresh_flags_;
ncarter (slow) 2016/07/28 21:37:26 I don't think we really need to track the refresh
stanisc 2016/07/28 22:38:43 I see. I was wondering about that. So basically al
stanisc 2016/08/01 22:34:26 Done.
110
111 // Snapshot of previously captured resources used to calculate the delta.
112 std::unique_ptr<ProcessDataSnapshot> previous_snapshot_;
113
114 // Size of the buffer previously used to query system information.
115 uint32_t previous_buffer_size_;
116
117 // The current process image name for process filtering purposes.
118 const base::FilePath current_process_image_name_;
ncarter (slow) 2016/07/28 21:37:26 maybe this should be a vector of FilePaths, which
stanisc 2016/07/28 22:38:43 Hmm... The implementation would have to iterate ov
stanisc 2016/08/01 22:34:26 Done.
119
120 // The specific blocking pool SequencedTaskRunner that will be used to post
121 // the refresh tasks onto serially.
122 scoped_refptr<base::SequencedTaskRunner> blocking_pool_runner_;
123
124 // To assert we're running on the correct thread.
125 base::SequenceChecker worker_pool_sequenced_checker_;
126 #endif // defined(OS_WIN)
127
128 DISALLOW_COPY_AND_ASSIGN(SharedSampler);
129 };
130
131 } // namespace task_management
132
133 #endif // CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_SHARED_SAMPLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698