| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This header is designed to give you trace_event macros without specifying | 5 // This header is designed to give you trace_event macros without specifying |
| 6 // how the events actually get collected and stored. If you need to expose trace | 6 // how the events actually get collected and stored. If you need to expose trace |
| 7 // event to some other universe, you can copy-and-paste this file, | 7 // event to some other universe, you can copy-and-paste this file, |
| 8 // implement the TRACE_EVENT_API macros, and do any other necessary fixup for | 8 // implement the TRACE_EVENT_API macros, and do any other necessary fixup for |
| 9 // the target platform. The end result is that multiple libraries can funnel | 9 // the target platform. The end result is that multiple libraries can funnel |
| 10 // events through to a shared trace event collector. | 10 // events through to a shared trace event collector. |
| 11 | 11 |
| 12 // Trace events are for tracking application performance and resource usage. | 12 // Trace events are for tracking application performance and resource usage. |
| 13 // Macros are provided to track: | 13 // Macros are provided to track: |
| 14 // Begin and end of function calls | 14 // Begin and end of function calls |
| 15 // Counters | 15 // Counters |
| 16 // | 16 // |
| 17 // Events are issued against categories. Whereas LOG's | 17 // Events are issued against categories. Whereas LOG's |
| 18 // categories are statically defined, TRACE categories are created | 18 // categories are statically defined, TRACE categories are created |
| 19 // implicitly with a string. For example: | 19 // implicitly with a string. For example: |
| 20 // TRACE_EVENT_INSTANT0("MY_SUBSYSTEM", "SomeImportantEvent") | 20 // TRACE_EVENT_INSTANT0("MY_SUBSYSTEM", "SomeImportantEvent") |
| 21 // | 21 // |
| 22 // A category can be made up of several tags, for example: |
| 23 // |
| 24 // TRACE_EVENT_INSTANT0("MY_SUBSYSTEM_1, MY_SUB_SYSTEM_2", "ImportantEvent") |
| 25 // |
| 26 // We can enable/disable tracing of ImportantEvent by enabling/disabling either |
| 27 // tag. |
| 28 // |
| 22 // Events can be INSTANT, or can be pairs of BEGIN and END in the same scope: | 29 // Events can be INSTANT, or can be pairs of BEGIN and END in the same scope: |
| 23 // TRACE_EVENT_BEGIN0("MY_SUBSYSTEM", "SomethingCostly") | 30 // TRACE_EVENT_BEGIN0("MY_SUBSYSTEM", "SomethingCostly") |
| 24 // doSomethingCostly() | 31 // doSomethingCostly() |
| 25 // TRACE_EVENT_END0("MY_SUBSYSTEM", "SomethingCostly") | 32 // TRACE_EVENT_END0("MY_SUBSYSTEM", "SomethingCostly") |
| 26 // Note: our tools can't always determine the correct BEGIN/END pairs unless | 33 // Note: our tools can't always determine the correct BEGIN/END pairs unless |
| 27 // these are used in the same scope. Use ASYNC_BEGIN/ASYNC_END macros if you | 34 // these are used in the same scope. Use ASYNC_BEGIN/ASYNC_END macros if you |
| 28 // need them to be in separate scopes. | 35 // need them to be in separate scopes. |
| 29 // | 36 // |
| 30 // A common use case is to trace entire function scopes. This | 37 // A common use case is to trace entire function scopes. This |
| 31 // issues a trace BEGIN and END automatically: | 38 // issues a trace BEGIN and END automatically: |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // By default, trace collection is compiled in, but turned off at runtime. | 101 // By default, trace collection is compiled in, but turned off at runtime. |
| 95 // Collecting trace data is the responsibility of the embedding | 102 // Collecting trace data is the responsibility of the embedding |
| 96 // application. In Chrome's case, navigating to about:tracing will turn on | 103 // application. In Chrome's case, navigating to about:tracing will turn on |
| 97 // tracing and display data collected across all active processes. | 104 // tracing and display data collected across all active processes. |
| 98 // | 105 // |
| 99 // | 106 // |
| 100 // Memory scoping note: | 107 // Memory scoping note: |
| 101 // Tracing copies the pointers, not the string content, of the strings passed | 108 // Tracing copies the pointers, not the string content, of the strings passed |
| 102 // in for category, name, and arg_names. Thus, the following code will | 109 // in for category, name, and arg_names. Thus, the following code will |
| 103 // cause problems: | 110 // cause problems: |
| 104 // char* str = strdup("impprtantName"); | 111 // char* str = strdup("importantName"); |
| 105 // TRACE_EVENT_INSTANT0("SUBSYSTEM", str); // BAD! | 112 // TRACE_EVENT_INSTANT0("SUBSYSTEM", str); // BAD! |
| 106 // free(str); // Trace system now has dangling pointer | 113 // free(str); // Trace system now has dangling pointer |
| 107 // | 114 // |
| 108 // To avoid this issue with the |name| and |arg_name| parameters, use the | 115 // To avoid this issue with the |name| and |arg_name| parameters, use the |
| 109 // TRACE_EVENT_COPY_XXX overloads of the macros at additional runtime overhead. | 116 // TRACE_EVENT_COPY_XXX overloads of the macros at additional runtime overhead. |
| 110 // Notes: The category must always be in a long-lived char* (i.e. static const). | 117 // Notes: The category must always be in a long-lived char* (i.e. static const). |
| 111 // The |arg_values|, when used, are always deep copied with the _COPY | 118 // The |arg_values|, when used, are always deep copied with the _COPY |
| 112 // macros. | 119 // macros. |
| 113 // | 120 // |
| 114 // When are string argument values copied: | 121 // When are string argument values copied: |
| 115 // const char* arg_values are only referenced by default: | 122 // const char* arg_values are only referenced by default: |
| 116 // TRACE_EVENT1("category", "name", | 123 // TRACE_EVENT1("category_tag1", "name", |
| 117 // "arg1", "literal string is only referenced"); | 124 // "arg1", "literal string is only referenced"); |
| 118 // Use TRACE_STR_COPY to force copying of a const char*: | 125 // Use TRACE_STR_COPY to force copying of a const char*: |
| 119 // TRACE_EVENT1("category", "name", | 126 // TRACE_EVENT1("category_tag1", "name", |
| 120 // "arg1", TRACE_STR_COPY("string will be copied")); | 127 // "arg1", TRACE_STR_COPY("string will be copied")); |
| 121 // std::string arg_values are always copied: | 128 // std::string arg_values are always copied: |
| 122 // TRACE_EVENT1("category", "name", | 129 // TRACE_EVENT1("category_tag1", "name", |
| 123 // "arg1", std::string("string will be copied")); | 130 // "arg1", std::string("string will be copied")); |
| 124 // | 131 // |
| 125 // | 132 // |
| 126 // Thread Safety: | 133 // Thread Safety: |
| 127 // A thread safe singleton and mutex are used for thread safety. Category | 134 // A thread safe singleton and mutex are used for thread safety. Category |
| 128 // enabled flags are used to limit the performance impact when the system | 135 // enabled flags are used to limit the performance impact when the system |
| 129 // is not enabled. | 136 // is not enabled. |
| 130 // | 137 // |
| 131 // TRACE_EVENT macros first cache a pointer to a category. The categories are | 138 // TRACE_EVENT macros first cache a pointer to a category. The categories are |
| 132 // statically allocated and safe at all times, even after exit. Fetching a | 139 // statically allocated and safe at all times, even after exit. Fetching a |
| (...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 const char* name; | 920 const char* name; |
| 914 }; | 921 }; |
| 915 Data* p_data_; | 922 Data* p_data_; |
| 916 Data data_; | 923 Data data_; |
| 917 }; | 924 }; |
| 918 | 925 |
| 919 | 926 |
| 920 } // namespace trace_event_internal | 927 } // namespace trace_event_internal |
| 921 | 928 |
| 922 #endif // BASE_DEBUG_TRACE_EVENT_H_ | 929 #endif // BASE_DEBUG_TRACE_EVENT_H_ |
| OLD | NEW |