jar@chromium.org | 3d6a82f | 2011-11-05 09:39:27 +0900 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | |
| 6 | #ifndef BASE_PROFILER_SCOPED_PROFILE_H_ |
| 7 | #define BASE_PROFILER_SCOPED_PROFILE_H_ |
| 8 | |
| 9 | //------------------------------------------------------------------------------ |
| 10 | // ScopedProfile provides basic helper functions for profiling a short |
| 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 |
| 13 | // macros listed below. |
| 14 | |
| 15 | #include "base/base_export.h" |
| 16 | #include "base/location.h" |
| 17 | #include "base/profiler/tracked_time.h" |
| 18 | |
| 19 | #define TRACK_RUN_IN_THIS_SCOPED_REGION_FOR_OFFICIAL_BUILDS(variable_name) \ |
| 20 | ::tracked_objects::ScopedProfile variable_name(FROM_HERE) |
| 21 | |
| 22 | #define TRACK_RUN_IN_IPC_HANDLER(dispatch_function_name) \ |
| 23 | ::tracked_objects::ScopedProfile some_tracking_variable_name( \ |
| 24 | FROM_HERE_WITH_EXPLICIT_FUNCTION(#dispatch_function_name)) |
| 25 | |
| 26 | |
| 27 | namespace tracked_objects { |
| 28 | class Births; |
| 29 | |
| 30 | class BASE_EXPORT ScopedProfile { |
| 31 | public: |
| 32 | explicit ScopedProfile(const Location& location); |
| 33 | ~ScopedProfile(); |
| 34 | |
| 35 | // Stop tracing prior to the end destruction of the instance. |
| 36 | void StopClockAndTally(); |
| 37 | |
| 38 | private: |
| 39 | Births* birth_; // Place in code where tracking started. |
| 40 | const TrackedTime start_of_run_; |
| 41 | |
| 42 | DISALLOW_COPY_AND_ASSIGN(ScopedProfile); |
| 43 | }; |
| 44 | |
| 45 | } // namespace tracked_objects |
| 46 | |
| 47 | #endif // BASE_PROFILER_SCOPED_PROFILE_H_ |