2022-01-20 03:38:26 +08:00
|
|
|
//===-- Instrumentation.cpp -----------------------------------------------===//
|
2019-02-06 02:46:36 +08: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-20 03:38:26 +08:00
|
|
|
#include "lldb/Utility/Instrumentation.h"
|
2022-02-03 20:26:10 +08:00
|
|
|
#include "lldb/Utility/LLDBLog.h"
|
2022-01-21 07:50:27 +08:00
|
|
|
#include "llvm/Support/Signposts.h"
|
|
|
|
|
2021-05-26 18:19:37 +08:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
2020-12-11 01:35:12 +08:00
|
|
|
#include <limits>
|
2020-04-21 00:37:07 +08:00
|
|
|
#include <thread>
|
2019-02-06 02:46:36 +08:00
|
|
|
|
|
|
|
using namespace lldb_private;
|
2022-01-20 03:38:26 +08:00
|
|
|
using namespace lldb_private::instrumentation;
|
2019-02-06 02:46:36 +08:00
|
|
|
|
2021-10-08 16:41:02 +08:00
|
|
|
// Whether we're currently across the API boundary.
|
|
|
|
static thread_local bool g_global_boundary = false;
|
|
|
|
|
2022-01-21 07:50:27 +08:00
|
|
|
// Instrument SB API calls with singposts when supported.
|
|
|
|
static llvm::ManagedStatic<llvm::SignpostEmitter> g_api_signposts;
|
|
|
|
|
2022-01-20 03:38:26 +08:00
|
|
|
Instrumenter::Instrumenter(llvm::StringRef pretty_func,
|
|
|
|
std::string &&pretty_args)
|
2022-03-15 04:32:03 +08:00
|
|
|
: m_pretty_func(pretty_func) {
|
2019-02-07 02:57:42 +08:00
|
|
|
if (!g_global_boundary) {
|
|
|
|
g_global_boundary = true;
|
|
|
|
m_local_boundary = true;
|
2022-01-21 07:50:27 +08:00
|
|
|
g_api_signposts->startInterval(this, m_pretty_func);
|
2019-02-07 02:57:42 +08:00
|
|
|
}
|
2022-01-31 22:57:48 +08:00
|
|
|
LLDB_LOG(GetLog(LLDBLog::API), "[{0}] {1} ({2})",
|
2022-01-21 07:50:27 +08:00
|
|
|
m_local_boundary ? "external" : "internal", m_pretty_func,
|
2022-01-20 03:38:26 +08:00
|
|
|
pretty_args);
|
2019-02-07 02:57:42 +08:00
|
|
|
}
|
|
|
|
|
2022-01-21 07:50:27 +08:00
|
|
|
Instrumenter::~Instrumenter() {
|
|
|
|
if (m_local_boundary) {
|
2021-10-08 16:41:02 +08:00
|
|
|
g_global_boundary = false;
|
2022-01-21 07:50:27 +08:00
|
|
|
g_api_signposts->endInterval(this, m_pretty_func);
|
|
|
|
}
|
2021-10-08 16:41:02 +08:00
|
|
|
}
|