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

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: Handling missing results in OnRefreshDone. 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;
ncarter (slow) 2016/08/03 22:39:43 Can ProcessDataSnapshot move into SharedSampler?
stanisc 2016/08/04 01:36:00 If I move into SharedSampler I'll have to define i
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
brucedawson 2016/08/03 00:36:55 Missing "on" before "the UI thread"
stanisc 2016/08/04 01:36:00 Done.
28 // mainly on a blocking pool thread.
29 //
30 // This exists because on Windows it is much faster to collect a group of
31 // process metrics for all processes all at once using NtQuerySystemInformation
32 // than to query the same data for for each process individually.
brucedawson 2016/08/03 00:36:55 and because some types of data can only be collect
stanisc 2016/08/04 01:36:00 Thanks, this is a good suggestion. Done.
33 class SharedSampler : public base::RefCountedThreadSafe<SharedSampler> {
34 public:
35 explicit SharedSampler(
36 const scoped_refptr<base::SequencedTaskRunner>& blocking_pool_runner);
37
38 // The below are the types of the callbacks to the UI thread upon their
39 // corresponding refresh are done on the worker thread.
brucedawson 2016/08/03 00:36:55 I can't quite parse this sentence.
stanisc 2016/08/04 01:36:00 Well, I copied this from TaskGroupSampler.h but ap
40 using OnIdleWakeupsCallback = base::Callback<void(int)>;
41
42 // Returns a combination of refresh flags supported by the shared sampler.
43 int64_t SupportsFlags() const;
ncarter (slow) 2016/08/03 22:28:55 Rename this to GetSupportedFlags() or something si
stanisc 2016/08/04 01:36:00 Done.
44
45 // Registers task group specific callbacks.
46 void RegisterCallbacks(base::ProcessId process_id,
47 const OnIdleWakeupsCallback& on_idle_wakeups);
48
49 // Unregisters task group specific callbacks.
50 void UnregisterCallbacks(base::ProcessId process_id);
51
52 // Refreshes the expensive process' stats (for now only idle wakeups per
53 // second) on the worker thread.
54 void Refresh(base::ProcessId process_id, int64_t refresh_flags);
55
56 private:
57 friend class base::RefCountedThreadSafe<SharedSampler>;
58 ~SharedSampler();
59
60 #if defined(OS_WIN)
61 // The UI-thread callbacks in TaskGroup registered with RegisterCallbacks and
62 // to be called when refresh on the worker thread is done.
63 struct Callbacks {
64 Callbacks();
65 Callbacks(Callbacks&& other);
66 ~Callbacks();
67
68 OnIdleWakeupsCallback on_idle_wakeups;
69
70 private:
71 DISALLOW_COPY_AND_ASSIGN(Callbacks);
72 };
73
74 typedef std::map<base::ProcessId, Callbacks> CallbacksMap;
75
76 // Contains all results of refresh for a single process.
77 struct RefreshResult {
78 base::ProcessId process_id;
79 int idle_wakeups_per_second;
80 };
81
82 typedef std::vector<RefreshResult> RefreshResults;
83
84 // Posted on the worker thread to do the actual refresh.
85 std::unique_ptr<RefreshResults> RefreshOnWorkerThread();
86
87 // Called on UI thread when the refresh is done.
88 void OnRefreshDone(std::unique_ptr<RefreshResults> refresh_results);
89
90 // Clear cached data.
91 void ClearState();
92
93 // Used to filter process information.
94 static std::vector<base::FilePath> GetSupportedImageNames();
95 bool IsSupportedImageName(base::FilePath::StringPieceType image_name) const;
96
97 // Captures a snapshot of data for all chrome processes.
98 // Runs on the worker thread.
99 std::unique_ptr<ProcessDataSnapshot> CaptureSnapshot();
100
101 // Produce refresh results by diffing two snapshots.
102 static void MakeResultsFromTwoSnapshots(
103 const ProcessDataSnapshot& prev_snapshot,
104 const ProcessDataSnapshot& snapshot,
105 RefreshResults* results);
106
107 // Produce refresh results from one snapshot.
108 // This is used only the first time when only one snapshot is available.
109 static void MakeResultsFromSnapshot(
110 const ProcessDataSnapshot& snapshot,
111 RefreshResults* results);
112
113 // Accumulates callbacks passed from TaskGroup objects passed via
114 // RegisterCallbacks calls.
115 CallbacksMap callbacks_map_;
116
117 // Refresh flags passed via Refresh.
118 int64_t refresh_flags_;
119
120 // Snapshot of previously captured resources used to calculate the delta.
121 std::unique_ptr<ProcessDataSnapshot> previous_snapshot_;
122
123 // Size of the buffer previously used to query system information.
124 uint32_t previous_buffer_size_;
125
126 // Image names that CaptureSnapshot uses to filter processes.
127 const std::vector<base::FilePath> supported_image_names_;
128
129 // The specific blocking pool SequencedTaskRunner that will be used to post
130 // the refresh tasks onto serially.
131 scoped_refptr<base::SequencedTaskRunner> blocking_pool_runner_;
132
133 // To assert we're running on the correct thread.
134 base::SequenceChecker worker_pool_sequenced_checker_;
135 #endif // defined(OS_WIN)
136
137 DISALLOW_COPY_AND_ASSIGN(SharedSampler);
138 };
139
140 } // namespace task_management
141
142 #endif // CHROME_BROWSER_TASK_MANAGEMENT_SAMPLING_SHARED_SAMPLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698