| 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 |
#ifdef XP_WIN |
| 8 |
# undef UNICODE |
| 9 |
# undef _UNICODE |
| 10 |
#endif |
| 11 |
|
| 12 |
#include "VTuneProfiler.h" |
| 13 |
|
| 14 |
#include <memory> |
| 15 |
|
| 16 |
#include "BaseProfiler.h" |
| 17 |
|
| 18 |
namespace mozilla { |
| 19 |
namespace baseprofiler { |
| 20 |
|
| 21 |
VTuneProfiler* VTuneProfiler::mInstance = nullptr; |
| 22 |
|
| 23 |
void VTuneProfiler::Initialize() { |
| 24 |
// This is just a 'dirty trick' to find out if the ittnotify DLL was found. |
| 25 |
// If it wasn't this function always returns 0, otherwise it returns |
| 26 |
// incrementing numbers, if the library was found this wastes 2 events but |
| 27 |
// that should be okay. |
| 28 |
// TODO re-implement here if vtune is needed |
| 29 |
// __itt_event testEvent = |
| 30 |
// __itt_event_create("Test event", strlen("Test event")); |
| 31 |
// testEvent = __itt_event_create("Test event 2", strlen("Test event 2")); |
| 32 |
|
| 33 |
// if (testEvent) { |
| 34 |
// mInstance = new VTuneProfiler(); |
| 35 |
// } |
| 36 |
} |
| 37 |
|
| 38 |
void VTuneProfiler::Shutdown() {} |
| 39 |
|
| 40 |
void VTuneProfiler::TraceInternal(const char* aName, TracingKind aKind) { |
| 41 |
// TODO re-implement here if vtune is needed |
| 42 |
// std::string str(aName); |
| 43 |
|
| 44 |
// auto iter = mStrings.find(str); |
| 45 |
|
| 46 |
// __itt_event event; |
| 47 |
// if (iter != mStrings.end()) { |
| 48 |
// event = iter->second; |
| 49 |
// } else { |
| 50 |
// event = __itt_event_create(aName, str.length()); |
| 51 |
// mStrings.insert({str, event}); |
| 52 |
// } |
| 53 |
|
| 54 |
// if (aKind == TRACING_INTERVAL_START || aKind == TRACING_EVENT) { |
| 55 |
// // VTune will consider starts not matched with an end to be single point |
| 56 |
// in |
| 57 |
// // time events. |
| 58 |
// __itt_event_start(event); |
| 59 |
// } else { |
| 60 |
// __itt_event_end(event); |
| 61 |
// } |
| 62 |
} |
| 63 |
|
| 64 |
void VTuneProfiler::RegisterThreadInternal(const char* aName) { |
| 65 |
// TODO re-implement here if vtune is needed |
| 66 |
// std::string str(aName); |
| 67 |
|
| 68 |
// if (!str.compare("Main Thread (Base Profiler)")) { |
| 69 |
// // Process main thread. |
| 70 |
// switch (XRE_GetProcessType()) { |
| 71 |
// case GeckoProcessType::GeckoProcessType_Default: |
| 72 |
// __itt_thread_set_name("Main Process"); |
| 73 |
// break; |
| 74 |
// case GeckoProcessType::GeckoProcessType_Content: |
| 75 |
// __itt_thread_set_name("Content Process"); |
| 76 |
// break; |
| 77 |
// case GeckoProcessType::GeckoProcessType_GMPlugin: |
| 78 |
// __itt_thread_set_name("Plugin Process"); |
| 79 |
// break; |
| 80 |
// case GeckoProcessType::GeckoProcessType_GPU: |
| 81 |
// __itt_thread_set_name("GPU Process"); |
| 82 |
// break; |
| 83 |
// default: |
| 84 |
// __itt_thread_set_name("Unknown Process"); |
| 85 |
// } |
| 86 |
// return; |
| 87 |
// } |
| 88 |
// __itt_thread_set_name(aName); |
| 89 |
} |
| 90 |
|
| 91 |
} // namespace baseprofiler |
| 92 |
} // namespace mozilla |