OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 5 |
6 #ifndef BASE_PROFILER_SCOPED_PROFILE_H_ | 6 #ifndef BASE_PROFILER_SCOPED_PROFILE_H_ |
7 #define BASE_PROFILER_SCOPED_PROFILE_H_ | 7 #define BASE_PROFILER_SCOPED_PROFILE_H_ |
8 | 8 |
9 //------------------------------------------------------------------------------ | 9 //------------------------------------------------------------------------------ |
10 // ScopedProfile provides basic helper functions for profiling a short | 10 // ScopedProfile provides basic helper functions for profiling a short |
11 // region of code within a scope. It is separate from the related ThreadData | 11 // region of code within a scope. It is separate from the related ThreadData |
12 // class so that it can be included without much other cruft, and provide the | 12 // class so that it can be included without much other cruft, and provide the |
13 // macros listed below. | 13 // macros listed below. |
14 | 14 |
15 #include "base/base_export.h" | 15 #include "base/base_export.h" |
16 #include "base/location.h" | 16 #include "base/location.h" |
17 #include "base/profiler/tracked_time.h" | 17 #include "base/profiler/tracked_time.h" |
18 | 18 |
19 #define TRACK_RUN_IN_THIS_SCOPED_REGION_FOR_OFFICIAL_BUILDS(variable_name) \ | 19 #if defined(GOOGLE_CHROME_BUILD) |
ian fette
2011/12/13 01:02:16
There seems to be active discussion around GOOGLE_
jar (doing other things)
2011/12/13 06:36:37
It is hard to tell the outcome of the discussion y
| |
20 ::tracked_objects::ScopedProfile variable_name(FROM_HERE) | |
21 | 20 |
22 #define TRACK_RUN_IN_IPC_HANDLER(dispatch_function_name) \ | 21 // We don't ship these profiled regions. This is for developer builds only. |
23 ::tracked_objects::ScopedProfile some_tracking_variable_name( \ | 22 // It allows developers to do some profililng of their code, and see results on |
ramant (doing other things)
2011/12/13 00:02:54
nit: profililng -> profiling
jar (doing other things)
2011/12/13 06:36:37
Done.
| |
23 // their about:profiler page. | |
24 #define TRACK_RUN_IN_THIS_SCOPED_REGION_FOR_DEVELOPER_BUILDS(scope_name) \ | |
25 ((void)0) | |
26 | |
27 #else | |
28 | |
29 #define TRACK_RUN_IN_THIS_SCOPED_REGION_FOR_DEVELOPER_BUILDS(scope_name) \ | |
30 ::tracked_objects::ScopedProfile LINE_BASED_VARIABLE_NAME_FOR_PROFILING( \ | |
31 FROM_HERE_WITH_EXPLICIT_FUNCTION(#scope_name)) | |
32 | |
33 #endif | |
34 | |
35 | |
36 | |
37 #define PASTE_LINE_NUMBER_ON_NAME(name, line) name##line | |
38 | |
39 #define LINE_BASED_VARIABLE_NAME_FOR_PROFILING \ | |
ramant (doing other things)
2011/12/13 00:02:54
nit: more than 80 chars
jar (doing other things)
2011/12/13 06:36:37
Done.
| |
40 PASTE_LINE_NUMBER_ON_NAME(some_profiler_variable_, __LINE__) | |
41 | |
42 #define TRACK_RUN_IN_IPC_HANDLER(dispatch_function_name) \ | |
43 ::tracked_objects::ScopedProfile some_tracking_variable_name( \ | |
24 FROM_HERE_WITH_EXPLICIT_FUNCTION(#dispatch_function_name)) | 44 FROM_HERE_WITH_EXPLICIT_FUNCTION(#dispatch_function_name)) |
25 | 45 |
26 | 46 |
27 namespace tracked_objects { | 47 namespace tracked_objects { |
28 class Births; | 48 class Births; |
29 | 49 |
30 class BASE_EXPORT ScopedProfile { | 50 class BASE_EXPORT ScopedProfile { |
31 public: | 51 public: |
32 explicit ScopedProfile(const Location& location); | 52 explicit ScopedProfile(const Location& location); |
33 ~ScopedProfile(); | 53 ~ScopedProfile(); |
34 | 54 |
35 // Stop tracing prior to the end destruction of the instance. | 55 // Stop tracing prior to the end destruction of the instance. |
36 void StopClockAndTally(); | 56 void StopClockAndTally(); |
37 | 57 |
38 private: | 58 private: |
39 Births* birth_; // Place in code where tracking started. | 59 Births* birth_; // Place in code where tracking started. |
40 const TrackedTime start_of_run_; | 60 const TrackedTime start_of_run_; |
41 | 61 |
42 DISALLOW_COPY_AND_ASSIGN(ScopedProfile); | 62 DISALLOW_COPY_AND_ASSIGN(ScopedProfile); |
43 }; | 63 }; |
44 | 64 |
45 } // namespace tracked_objects | 65 } // namespace tracked_objects |
46 | 66 |
47 #endif // BASE_PROFILER_SCOPED_PROFILE_H_ | 67 #endif // BASE_PROFILER_SCOPED_PROFILE_H_ |
OLD | NEW |