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/location.h" | 14 #include "base/location.h" |
14 #include "base/profiler/scoped_profile.h" | 15 #include "base/profiler/scoped_profile.h" |
15 | 16 |
16 namespace tracked_objects { | 17 namespace tracked_objects { |
17 | 18 |
18 // ScopedTracker instruments a region within the code if the instrumentation is | 19 // ScopedTracker instruments a region within the code if the instrumentation is |
19 // 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 |
20 // inside the instrumented code region. | 21 // inside the instrumented code region. |
21 class BASE_EXPORT ScopedTracker { | 22 class BASE_EXPORT ScopedTracker { |
22 public: | 23 public: |
23 ScopedTracker(const Location& location); | 24 ScopedTracker(const Location& location); |
24 | 25 |
25 // Enables instrumentation for the remainder of the current process' life. If | 26 // Enables instrumentation for the remainder of the current process' life. If |
26 // this function is not called, all profiler instrumentations are no-ops. | 27 // this function is not called, all profiler instrumentations are no-ops. |
27 static void Enable(); | 28 static void Enable(); |
28 | 29 |
| 30 // 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 |
| 32 // 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 |
| 34 // passes the janky callback. |
| 35 static base::Closure TrackCallback(const Location& location, |
| 36 const base::Closure& callback); |
| 37 |
29 private: | 38 private: |
30 const ScopedProfile scoped_profile_; | 39 const ScopedProfile scoped_profile_; |
31 | 40 |
32 DISALLOW_COPY_AND_ASSIGN(ScopedTracker); | 41 DISALLOW_COPY_AND_ASSIGN(ScopedTracker); |
33 }; | 42 }; |
34 | 43 |
35 } // namespace tracked_objects | 44 } // namespace tracked_objects |
36 | 45 |
37 #endif // BASE_PROFILER_SCOPED_TRACKER_H_ | 46 #endif // BASE_PROFILER_SCOPED_TRACKER_H_ |
OLD | NEW |