LLDB  mainline
Instrumentation.cpp
Go to the documentation of this file.
1 //===-- Instrumentation.cpp -----------------------------------------------===//
2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 // See https://llvm.org/LICENSE.txt for license information.
4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5 //
6 //===----------------------------------------------------------------------===//
7 
9 #include "lldb/Utility/LLDBLog.h"
10 #include "llvm/Support/Signposts.h"
11 
12 #include <cstdio>
13 #include <cstdlib>
14 #include <limits>
15 #include <thread>
16 
17 using namespace lldb_private;
18 using namespace lldb_private::instrumentation;
19 
20 // Whether we're currently across the API boundary.
21 static thread_local bool g_global_boundary = false;
22 
23 // Instrument SB API calls with singposts when supported.
24 static llvm::ManagedStatic<llvm::SignpostEmitter> g_api_signposts;
25 
26 Instrumenter::Instrumenter(llvm::StringRef pretty_func,
27  std::string &&pretty_args)
28  : m_pretty_func(pretty_func) {
29  if (!g_global_boundary) {
30  g_global_boundary = true;
31  m_local_boundary = true;
32  g_api_signposts->startInterval(this, m_pretty_func);
33  }
34  LLDB_LOG(GetLog(LLDBLog::API), "[{0}] {1} ({2})",
35  m_local_boundary ? "external" : "internal", m_pretty_func,
36  pretty_args);
37 }
38 
40  if (m_local_boundary) {
41  g_global_boundary = false;
42  g_api_signposts->endInterval(this, m_pretty_func);
43  }
44 }
Instrumentation.h
lldb_private::instrumentation::Instrumenter::m_local_boundary
bool m_local_boundary
Whether this function call was the one crossing the API boundary.
Definition: Instrumentation.h:90
lldb_private::instrumentation::Instrumenter::~Instrumenter
~Instrumenter()
Definition: Instrumentation.cpp:39
lldb_private::LLDBLog::API
@ API
g_api_signposts
static llvm::ManagedStatic< llvm::SignpostEmitter > g_api_signposts
Definition: Instrumentation.cpp:24
lldb_private::instrumentation
Definition: Instrumentation.h:22
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
g_global_boundary
static thread_local bool g_global_boundary
Definition: Instrumentation.cpp:21
lldb_private::instrumentation::Instrumenter::Instrumenter
Instrumenter(llvm::StringRef pretty_func, std::string &&pretty_args={})
Definition: Instrumentation.cpp:26
LLDB_LOG
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:336
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::instrumentation::Instrumenter::m_pretty_func
llvm::StringRef m_pretty_func
Definition: Instrumentation.h:87
lldb_private::GetLog
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:308
LLDBLog.h