tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

VTuneProfiler.h (2513B)


      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 "mozilla/BaseProfiler.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 <unordered_map>
     35 #  include <string>
     36 
     37 namespace mozilla {
     38 namespace baseprofiler {
     39 
     40 class VTuneProfiler {
     41 public:
     42  static void Initialize();
     43  static void Shutdown();
     44 
     45  enum TracingKind {
     46    TRACING_EVENT,
     47    TRACING_INTERVAL_START,
     48    TRACING_INTERVAL_END,
     49  };
     50 
     51  static void Trace(const char* aName, TracingKind aKind) {
     52    if (mInstance) {
     53      mInstance->TraceInternal(aName, aKind);
     54    }
     55  }
     56  static void RegisterThread(const char* aName) {
     57    if (mInstance) {
     58      mInstance->RegisterThreadInternal(aName);
     59    }
     60  }
     61 
     62 private:
     63  void TraceInternal(const char* aName, TracingKind aKind);
     64  void RegisterThreadInternal(const char* aName);
     65 
     66  // This is null when the ittnotify DLL could not be found.
     67  static VTuneProfiler* mInstance;
     68 
     69  std::unordered_map<std::string, __itt_event> mStrings;
     70 };
     71 
     72 #  define VTUNE_INIT() VTuneProfiler::Initialize()
     73 #  define VTUNE_SHUTDOWN() VTuneProfiler::Shutdown()
     74 
     75 #  define VTUNE_TRACING(name, kind) VTuneProfiler::Trace(name, kind)
     76 #  define VTUNE_REGISTER_THREAD(name) VTuneProfiler::RegisterThread(name)
     77 
     78 }  // namespace baseprofiler
     79 }  // namespace mozilla
     80 
     81 #endif
     82 
     83 #endif /* VTuneProfiler_h */