OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef BASE_PROFILER_SCOPED_TRACKER_H_ | 5 #ifndef BASE_PROFILER_SCOPED_TRACKER_H_ |
6 #define BASE_PROFILER_SCOPED_TRACKER_H_ | 6 #define BASE_PROFILER_SCOPED_TRACKER_H_ |
7 | 7 |
8 //------------------------------------------------------------------------------ | 8 //------------------------------------------------------------------------------ |
9 // Utilities for temporarily instrumenting code to dig into issues that were | 9 // Utilities for temporarily instrumenting code to dig into issues that were |
10 // found using profiler data. | 10 // found using profiler data. |
11 | 11 |
12 #include "base/base_export.h" | 12 #include "base/base_export.h" |
13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/profiler/scoped_profile.h" | 15 #include "base/profiler/scoped_profile.h" |
16 | 16 |
17 namespace tracked_objects { | 17 namespace tracked_objects { |
18 | 18 |
19 // ScopedTracker instruments a region within the code if the instrumentation is | 19 // ScopedTracker instruments a region within the code if the instrumentation is |
20 // enabled. It can be used, for example, to find out if a source of jankiness is | 20 // enabled. It can be used, for example, to find out if a source of jankiness is |
21 // inside the instrumented code region. | 21 // inside the instrumented code region. |
22 // Details: | |
23 // 1. This class creates a task (like ones created by PostTask calls or IPC | |
24 // message handlers). This task can be seen in chrome://profiler and is sent as | |
25 // a part of profiler data to the UMA server. See profiler_event.proto. | |
26 // 2. That task extends from the object's constructor to its destructor | |
Mark Mentovai
2014/11/04 20:53:41
I had to read this a few times to make maximum sen
vadimt
2014/11/04 21:11:14
Done.
| |
27 // executions. | |
28 // 3. The execution time associated with the task is the wallclock time between | |
29 // its constructor and destructor, minus wallclock times of directly nested | |
30 // tasks. | |
31 // 4. Task creation that this class utilizes was highly optimized by jar@. | |
Mark Mentovai
2014/11/04 20:53:41
Only if jar is OK being called out by name.
vadimt
2014/11/04 21:11:14
Done.
| |
32 // 5. The class doesn't create a task unless this was enabled for the current | |
33 // process. Search for ScopedTracker::Enable for the current list of processes | |
34 // and channels where it's activated. | |
35 // 6. The class is designed for temporarily instrumenting code to find | |
36 // performance problems, after which the instrumentation has to be removed. | |
Mark Mentovai
2014/11/04 20:53:42
Make this stronger: “has to be”→“must”.
vadimt
2014/11/04 21:11:14
Done.
| |
37 // However, in rare cases it might be added permanently, as an exception. | |
Mark Mentovai
2014/11/04 20:53:42
This is kind of wishy-washy. If there are cases wh
vadimt
2014/11/04 21:11:14
Let's remove for now. If I or someone else wants t
| |
22 class BASE_EXPORT ScopedTracker { | 38 class BASE_EXPORT ScopedTracker { |
23 public: | 39 public: |
24 ScopedTracker(const Location& location); | 40 ScopedTracker(const Location& location); |
25 | 41 |
26 // Enables instrumentation for the remainder of the current process' life. If | 42 // Enables instrumentation for the remainder of the current process' life. If |
27 // this function is not called, all profiler instrumentations are no-ops. | 43 // this function is not called, all profiler instrumentations are no-ops. |
28 static void Enable(); | 44 static void Enable(); |
29 | 45 |
30 // Augments a |callback| with provided |location|. This is useful for | 46 // Augments a |callback| with provided |location|. This is useful for |
31 // instrumenting cases when we know that a jank is in a callback and there are | 47 // instrumenting cases when we know that a jank is in a callback and there are |
32 // many possible callbacks, but they come from a relatively small number of | 48 // many possible callbacks, but they come from a relatively small number of |
33 // places. We can instrument these few places and at least know which one | 49 // places. We can instrument these few places and at least know which one |
34 // passes the janky callback. | 50 // passes the janky callback. |
35 static base::Closure TrackCallback(const Location& location, | 51 static base::Closure TrackCallback(const Location& location, |
36 const base::Closure& callback); | 52 const base::Closure& callback); |
37 | 53 |
38 private: | 54 private: |
39 const ScopedProfile scoped_profile_; | 55 const ScopedProfile scoped_profile_; |
40 | 56 |
41 DISALLOW_COPY_AND_ASSIGN(ScopedTracker); | 57 DISALLOW_COPY_AND_ASSIGN(ScopedTracker); |
42 }; | 58 }; |
43 | 59 |
44 } // namespace tracked_objects | 60 } // namespace tracked_objects |
45 | 61 |
46 #endif // BASE_PROFILER_SCOPED_TRACKER_H_ | 62 #endif // BASE_PROFILER_SCOPED_TRACKER_H_ |
OLD | NEW |