clang-tools  14.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 
13 namespace clang {
14 namespace clangd {
15 namespace trace {
16 
17 void TestTracer::record(const Metric &Metric, double Value,
18  llvm::StringRef Label) {
19  std::lock_guard<std::mutex> Lock(Mu);
20  Measurements[Metric.Name][Label].push_back(Value);
21 }
22 
23 std::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
Label
std::string Label
Definition: InlayHintTests.cpp:38
clang::clangd::trace::TestTracer::record
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
clang::clangd::trace::Metric::Name
const llvm::StringLiteral Name
Uniquely identifies the metric.
Definition: Trace.h:63
Trace.h
TestTracer.h
clang::clangd::trace::Metric
Represents measurements of clangd events, e.g.
Definition: Trace.h:38
clang::clangd::trace::TestTracer::takeMetric
std::vector< double > takeMetric(llvm::StringRef Metric, llvm::StringRef Label="")
Returns recorded measurements for Metric and clears them.
Definition: TestTracer.cpp:23
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27