Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / tools / profiler / core / VTuneProfiler.cpp
blob58a39c51eeff8ad0659c0d6e3f055877c9384ff6
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 #ifdef XP_WIN
8 # undef UNICODE
9 # undef _UNICODE
10 #endif
12 #include "VTuneProfiler.h"
13 #include "mozilla/Bootstrap.h"
14 #include <memory>
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"));
27 if (testEvent) {
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);
39 __itt_event event;
40 if (iter != mStrings.end()) {
41 event = iter->second;
42 } else {
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
49 // time events.
50 __itt_event_start(event);
51 } else {
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");
64 break;
65 case GeckoProcessType::GeckoProcessType_Content:
66 __itt_thread_set_name("Content Process");
67 break;
68 case GeckoProcessType::GeckoProcessType_GMPlugin:
69 __itt_thread_set_name("Plugin Process");
70 break;
71 case GeckoProcessType::GeckoProcessType_GPU:
72 __itt_thread_set_name("GPU Process");
73 break;
74 default:
75 __itt_thread_set_name("Unknown Process");
77 return;
79 __itt_thread_set_name(aName);