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
17void 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(x: 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(Key: Metric);
27 if (LabelsIt == Measurements.end())
28 return {};
29 auto &Labels = LabelsIt->getValue();
30 auto ValuesIt = Labels.find(Key: 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
40

source code of clang-tools-extra/clangd/unittests/support/TestTracer.cpp