| 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 #include "base/tracked_objects.h" | 18 #include "base/tracked_objects.h" |
| 19 | 19 |
| 20 #if defined(GOOGLE_CHROME_BUILD) | |
| 21 | |
| 22 // We don't ship these profiled regions. This is for developer builds only. | |
| 23 // It allows developers to do some profiling of their code, and see results on | |
| 24 // their about:profiler page. | |
| 25 #define TRACK_RUN_IN_THIS_SCOPED_REGION_FOR_DEVELOPER_BUILDS(scope_name) \ | |
| 26 ((void)0) | |
| 27 | |
| 28 #else | |
| 29 | |
| 30 #define TRACK_RUN_IN_THIS_SCOPED_REGION_FOR_DEVELOPER_BUILDS(scope_name) \ | |
| 31 ::tracked_objects::ScopedProfile LINE_BASED_VARIABLE_NAME_FOR_PROFILING( \ | |
| 32 FROM_HERE_WITH_EXPLICIT_FUNCTION(#scope_name)) | |
| 33 | |
| 34 #endif | |
| 35 | |
| 36 | |
| 37 | |
| 38 #define PASTE_LINE_NUMBER_ON_NAME(name, line) name##line | 20 #define PASTE_LINE_NUMBER_ON_NAME(name, line) name##line |
| 39 | 21 |
| 40 #define LINE_BASED_VARIABLE_NAME_FOR_PROFILING \ | 22 #define LINE_BASED_VARIABLE_NAME_FOR_PROFILING \ |
| 41 PASTE_LINE_NUMBER_ON_NAME(some_profiler_variable_, __LINE__) | 23 PASTE_LINE_NUMBER_ON_NAME(some_profiler_variable_, __LINE__) |
| 42 | 24 |
| 43 #define TRACK_RUN_IN_IPC_HANDLER(dispatch_function_name) \ | 25 // Defines the containing scope as a profiled region. This allows developers to |
| 44 ::tracked_objects::ScopedProfile some_tracking_variable_name( \ | 26 // profile their code and see results on their about:profiler page, as well as |
| 27 // on the UMA dashboard. |
| 28 #define TRACK_RUN_IN_THIS_SCOPED_REGION(dispatch_function_name) \ |
| 29 ::tracked_objects::ScopedProfile LINE_BASED_VARIABLE_NAME_FOR_PROFILING( \ |
| 45 FROM_HERE_WITH_EXPLICIT_FUNCTION(#dispatch_function_name)) | 30 FROM_HERE_WITH_EXPLICIT_FUNCTION(#dispatch_function_name)) |
| 46 | 31 |
| 47 | 32 |
| 48 namespace tracked_objects { | 33 namespace tracked_objects { |
| 49 class Births; | 34 class Births; |
| 50 | 35 |
| 51 class BASE_EXPORT ScopedProfile { | 36 class BASE_EXPORT ScopedProfile { |
| 52 public: | 37 public: |
| 53 explicit ScopedProfile(const Location& location); | 38 explicit ScopedProfile(const Location& location); |
| 54 ~ScopedProfile(); | 39 ~ScopedProfile(); |
| 55 | 40 |
| 56 // Stop tracing prior to the end destruction of the instance. | 41 // Stop tracing prior to the end destruction of the instance. |
| 57 void StopClockAndTally(); | 42 void StopClockAndTally(); |
| 58 | 43 |
| 59 private: | 44 private: |
| 60 Births* birth_; // Place in code where tracking started. | 45 Births* birth_; // Place in code where tracking started. |
| 61 TaskStopwatch stopwatch_; | 46 TaskStopwatch stopwatch_; |
| 62 | 47 |
| 63 DISALLOW_COPY_AND_ASSIGN(ScopedProfile); | 48 DISALLOW_COPY_AND_ASSIGN(ScopedProfile); |
| 64 }; | 49 }; |
| 65 | 50 |
| 66 } // namespace tracked_objects | 51 } // namespace tracked_objects |
| 67 | 52 |
| 68 #endif // BASE_PROFILER_SCOPED_PROFILE_H_ | 53 #endif // BASE_PROFILER_SCOPED_PROFILE_H_ |
| OLD | NEW |