2022-01-19 11:38:26 -08:00
|
|
|
//===-- Instrumentation.cpp -----------------------------------------------===//
|
2019-02-05 18:46:36 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
2022-01-19 11:38:26 -08:00
|
|
|
#include "lldb/Utility/Instrumentation.h"
|
2022-02-03 13:26:10 +01:00
|
|
|
#include "lldb/Utility/LLDBLog.h"
|
2022-01-20 15:50:27 -08:00
|
|
|
#include "llvm/Support/Signposts.h"
|
|
|
|
|
|
2021-05-26 12:19:37 +02:00
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstdlib>
|
2020-12-10 09:35:12 -08:00
|
|
|
#include <limits>
|
2020-04-20 09:37:07 -07:00
|
|
|
#include <thread>
|
2019-02-05 18:46:36 +00:00
|
|
|
|
|
|
|
|
using namespace lldb_private;
|
2022-01-19 11:38:26 -08:00
|
|
|
using namespace lldb_private::instrumentation;
|
2019-02-05 18:46:36 +00:00
|
|
|
|
2021-10-08 11:41:02 +03:00
|
|
|
// Whether we're currently across the API boundary.
|
|
|
|
|
static thread_local bool g_global_boundary = false;
|
|
|
|
|
|
2024-09-12 22:52:46 -07:00
|
|
|
// Instrument SB API calls with signposts when supported.
|
2022-01-20 15:50:27 -08:00
|
|
|
static llvm::ManagedStatic<llvm::SignpostEmitter> g_api_signposts;
|
|
|
|
|
|
2022-01-19 11:38:26 -08:00
|
|
|
Instrumenter::Instrumenter(llvm::StringRef pretty_func,
|
|
|
|
|
std::string &&pretty_args)
|
2022-03-14 13:32:03 -07:00
|
|
|
: m_pretty_func(pretty_func) {
|
2019-02-06 18:57:42 +00:00
|
|
|
if (!g_global_boundary) {
|
|
|
|
|
g_global_boundary = true;
|
|
|
|
|
m_local_boundary = true;
|
2022-01-20 15:50:27 -08:00
|
|
|
g_api_signposts->startInterval(this, m_pretty_func);
|
2019-02-06 18:57:42 +00:00
|
|
|
}
|
2022-01-31 15:57:48 +01:00
|
|
|
LLDB_LOG(GetLog(LLDBLog::API), "[{0}] {1} ({2})",
|
2022-01-20 15:50:27 -08:00
|
|
|
m_local_boundary ? "external" : "internal", m_pretty_func,
|
2022-01-19 11:38:26 -08:00
|
|
|
pretty_args);
|
2019-02-06 18:57:42 +00:00
|
|
|
}
|
|
|
|
|
|
2022-01-20 15:50:27 -08:00
|
|
|
Instrumenter::~Instrumenter() {
|
|
|
|
|
if (m_local_boundary) {
|
2021-10-08 11:41:02 +03:00
|
|
|
g_global_boundary = false;
|
2022-01-20 15:50:27 -08:00
|
|
|
g_api_signposts->endInterval(this, m_pretty_func);
|
|
|
|
|
}
|
2021-10-08 11:41:02 +03:00
|
|
|
}
|