Debian Codegraph @

mozglue/baseprofiler/core/VTuneProfiler.h

raw
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 #ifndef VTuneProfiler_h
8 #define VTuneProfiler_h
9
10 // The intent here is to add 0 overhead for regular users. In order to build
11 // the VTune profiler code at all --enable-vtune-instrumentation needs to be
12 // set as a build option. Even then, when none of the environment variables
13 // is specified that allow us to find the ittnotify DLL, these functions
14 // should be minimal overhead. When starting Firefox under VTune, these
15 // env vars will be automatically defined, otherwise INTEL_LIBITTNOTIFY32/64
16 // should be set to point at the ittnotify DLL.
17 #ifndef MOZ_VTUNE_INSTRUMENTATION
18
19 # define VTUNE_INIT()
20 # define VTUNE_SHUTDOWN()
21
22 # define VTUNE_TRACING(name, kind)
23 # define VTUNE_REGISTER_THREAD(name)
24
25 #else
26
27 # include "BaseProfiler.h"
28
29 // This is the regular Intel header, these functions are actually defined for
30 // us inside js/src/vtune by an intel C file which actually dynamically resolves
31 // them to the correct DLL. Through libxul these will 'magically' resolve.
32 # include "vtune/ittnotify.h"
33
34 # include <stddef.h>
35 # include <unordered_map>
36 # include <string>
37
38 namespace mozilla {
39 namespace baseprofiler {
40
41 class VTuneProfiler {
42 public:
43 static void Initialize();
44 static void Shutdown();
45
46 enum TracingKind {
47 TRACING_EVENT,
48 TRACING_INTERVAL_START,
49 TRACING_INTERVAL_END,
50 };
51
52 static void Trace(const char* aName, TracingKind aKind) {
53 if (mInstance) {
54 mInstance->TraceInternal(aName, aKind);
55 }
56 }
57 static void RegisterThread(const char* aName) {
58 if (mInstance) {
59 mInstance->RegisterThreadInternal(aName);
60 }
61 }
62
63 private:
64 void TraceInternal(const char* aName, TracingKind aKind);
65 void RegisterThreadInternal(const char* aName);
66
67 // This is null when the ittnotify DLL could not be found.
68 static VTuneProfiler* mInstance;
69
70 std::unordered_map<std::string, __itt_event> mStrings;
71 };
72
73 # define VTUNE_INIT() VTuneProfiler::Initialize()
74 # define VTUNE_SHUTDOWN() VTuneProfiler::Shutdown()
75
76 # define VTUNE_TRACING(name, kind) VTuneProfiler::Trace(name, kind)
77 # define VTUNE_REGISTER_THREAD(name) VTuneProfiler::RegisterThread(name)
78
79 } // namespace baseprofiler
80 } // namespace mozilla
81
82 #endif
83
84 #endif /* VTuneProfiler_h */