clang-tools 19.0.0git
TestTracer.cpp
Go to the documentation of this file.
1//===-- TestTracer.cpp - Tracing unit tests ---------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8#include "TestTracer.h"
9#include "support/Trace.h"
10#include "llvm/ADT/StringRef.h"
11#include <mutex>
12
13namespace clang {
14namespace clangd {
15namespace trace {
16
18 llvm::StringRef Label) {
19 std::lock_guard<std::mutex> Lock(Mu);
20 Measurements[Metric.Name][Label].push_back(Value);
21}
22
23std::vector<double> TestTracer::takeMetric(llvm::StringRef Metric,
24 llvm::StringRef Label) {
25 std::lock_guard<std::mutex> Lock(Mu);
26 auto LabelsIt = Measurements.find(Metric);
27 if (LabelsIt == Measurements.end())
28 return {};
29 auto &Labels = LabelsIt->getValue();
30 auto ValuesIt = Labels.find(Label);
31 if (ValuesIt == Labels.end())
32 return {};
33 auto Res = std::move(ValuesIt->getValue());
34 ValuesIt->getValue().clear();
35 return Res;
36}
37} // namespace trace
38} // namespace clangd
39} // namespace clang
void record(const Metric &Metric, double Value, llvm::StringRef Label) override
Stores all the measurements to be returned with take later on.
Definition: TestTracer.cpp:17
std::vector< double > takeMetric(llvm::StringRef Metric, llvm::StringRef Label="")
Returns recorded measurements for Metric and clears them.
Definition: TestTracer.cpp:23
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Represents measurements of clangd events, e.g.
Definition: Trace.h:38
const llvm::StringLiteral Name
Uniquely identifies the metric.
Definition: Trace.h:63