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/. */
7 #ifndef VTuneProfiler_h
8 #define VTuneProfiler_h
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
20 # define VTUNE_SHUTDOWN()
22 # define VTUNE_TRACING(name, kind)
23 # define VTUNE_REGISTER_THREAD(name)
27 # include "GeckoProfiler.h"
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"
35 # include <unordered_map>
40 static void Initialize();
41 static void Shutdown();
45 TRACING_INTERVAL_START
,
49 static void Trace(const char* aName
, TracingKind aKind
) {
51 mInstance
->TraceInternal(aName
, aKind
);
54 static void RegisterThread(const char* aName
) {
56 mInstance
->RegisterThreadInternal(aName
);
61 void TraceInternal(const char* aName
, TracingKind aKind
);
62 void RegisterThreadInternal(const char* aName
);
64 // This is null when the ittnotify DLL could not be found.
65 static VTuneProfiler
* mInstance
;
67 std::unordered_map
<std::string
, __itt_event
> mStrings
;
70 # define VTUNE_INIT() VTuneProfiler::Initialize()
71 # define VTUNE_SHUTDOWN() VTuneProfiler::Shutdown()
73 # define VTUNE_TRACING(name, kind) VTuneProfiler::Trace(name, kind)
74 # define VTUNE_REGISTER_THREAD(name) VTuneProfiler::RegisterThread(name)
78 #endif /* VTuneProfiler_h */