Source code

Revision control

Other Tools

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 "GeckoProfiler.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
class VTuneProfiler {
39
public:
40
static void Initialize();
41
static void Shutdown();
42
43
static void Trace(const char* aName, TracingKind aKind) {
44
if (mInstance) {
45
mInstance->TraceInternal(aName, aKind);
46
}
47
}
48
static void RegisterThread(const char* aName) {
49
if (mInstance) {
50
mInstance->RegisterThreadInternal(aName);
51
}
52
}
53
54
private:
55
void TraceInternal(const char* aName, TracingKind aKind);
56
void RegisterThreadInternal(const char* aName);
57
58
// This is null when the ittnotify DLL could not be found.
59
static VTuneProfiler* mInstance;
60
61
std::unordered_map<std::string, __itt_event> mStrings;
62
};
63
64
# define VTUNE_INIT() VTuneProfiler::Initialize()
65
# define VTUNE_SHUTDOWN() VTuneProfiler::Shutdown()
66
67
# define VTUNE_TRACING(name, kind) VTuneProfiler::Trace(name, kind)
68
# define VTUNE_REGISTER_THREAD(name) VTuneProfiler::RegisterThread(name)
69
70
#endif
71
72
#endif /* VTuneProfiler_h */