1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 // This contains things related to the Gecko profiler, for use in third_party
8 // code. It is very minimal and is designed to be used by patching over
9 // upstream code.
10 // Only use the C ABI and guard C++ code with #ifdefs, don't pull anything from
11 // Gecko, it must be possible to include the header file into any C++ codebase.
12 
13 #ifndef MICRO_GECKO_PROFILER
14 #define MICRO_GECKO_PROFILER
15 
16 void uprofiler_register_thread(const char* aName, void* aGuessStackTop);
17 void uprofiler_unregister_thread();
18 
19 #ifdef __cplusplus
20 struct AutoRegisterProfiler {
AutoRegisterProfilerAutoRegisterProfiler21   AutoRegisterProfiler(const char* name, char* stacktop) {
22     if (getenv("MOZ_UPROFILER_LOG_THREAD_CREATION")) {
23       printf("### UProfiler: new thread: '%s'\n", name);
24     }
25     uprofiler_register_thread(name, stacktop);
26   }
~AutoRegisterProfilerAutoRegisterProfiler27   ~AutoRegisterProfiler() { uprofiler_unregister_thread(); }
28 };
29 #endif  // __cplusplus
30 
31 void uprofiler_simple_event_marker(const char* name, const char* category,
32                                    char phase);
33 
34 #ifdef __cplusplus
35 class AutoTrace {
36  public:
AutoTrace(const char * name,const char * category)37   AutoTrace(const char* name, const char* category)
38       : name(name), category(category) {
39     uprofiler_simple_event_marker(name, category, 'B');
40   }
~AutoTrace()41   ~AutoTrace() { uprofiler_simple_event_marker(name, category, 'E'); }
42 
43  private:
44   const char* name;
45   const char* category;
46 };
47 
48 #endif
49 
50 #endif  // MICRO_GECKO_PROFILER
51