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
10#include "llvm/Support/Signposts.h"
11
12#include <cstdio>
13#include <cstdlib>
14#include <limits>
15#include <thread>
16
17using namespace lldb_private;
18using namespace lldb_private::instrumentation;
19
20// Whether we're currently across the API boundary.
21static thread_local bool g_global_boundary = false;
22
23// Instrument SB API calls with singposts when supported.
24static llvm::ManagedStatic<llvm::SignpostEmitter> g_api_signposts;
25
26Instrumenter::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}
static llvm::ManagedStatic< llvm::SignpostEmitter > g_api_signposts
static thread_local bool g_global_boundary
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:359
Instrumenter(llvm::Module &module, std::shared_ptr< UtilityFunction > checker_function)
Constructor.
bool m_local_boundary
Whether this function call was the one crossing the API boundary.
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:331