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/. */
12 #include "VTuneProfiler.h"
13 #include "mozilla/Bootstrap.h"
16 VTuneProfiler
* VTuneProfiler::mInstance
= nullptr;
18 void VTuneProfiler::Initialize() {
19 // This is just a 'dirty trick' to find out if the ittnotify DLL was found.
20 // If it wasn't this function always returns 0, otherwise it returns
21 // incrementing numbers, if the library was found this wastes 2 events but
22 // that should be okay.
23 __itt_event testEvent
=
24 __itt_event_create("Test event", strlen("Test event"));
25 testEvent
= __itt_event_create("Test event 2", strlen("Test event 2"));
28 mInstance
= new VTuneProfiler();
32 void VTuneProfiler::Shutdown() {}
34 void VTuneProfiler::TraceInternal(const char* aName
, TracingKind aKind
) {
35 std::string
str(aName
);
37 auto iter
= mStrings
.find(str
);
40 if (iter
!= mStrings
.end()) {
43 event
= __itt_event_create(aName
, str
.length());
44 mStrings
.insert({str
, event
});
47 if (aKind
== TRACING_INTERVAL_START
|| aKind
== TRACING_EVENT
) {
48 // VTune will consider starts not matched with an end to be single point in
50 __itt_event_start(event
);
52 __itt_event_end(event
);
56 void VTuneProfiler::RegisterThreadInternal(const char* aName
) {
57 std::string
str(aName
);
59 if (!str
.compare("GeckoMain")) {
60 // Process main thread.
61 switch (XRE_GetProcessType()) {
62 case GeckoProcessType::GeckoProcessType_Default
:
63 __itt_thread_set_name("Main Process");
65 case GeckoProcessType::GeckoProcessType_Content
:
66 __itt_thread_set_name("Content Process");
68 case GeckoProcessType::GeckoProcessType_GMPlugin
:
69 __itt_thread_set_name("Plugin Process");
71 case GeckoProcessType::GeckoProcessType_GPU
:
72 __itt_thread_set_name("GPU Process");
75 __itt_thread_set_name("Unknown Process");
79 __itt_thread_set_name(aName
);