clang-tools 20.0.0git
TestTracer.h
Go to the documentation of this file.
1//===-- TestTracer.h --------------------------------------------*- 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//
9// Allows setting up a fake tracer for tests.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_SUPPORT_TESTTRACER_H
14#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_SUPPORT_TESTTRACER_H
15
16#include "support/Trace.h"
17#include "llvm/ADT/StringMap.h"
18#include "llvm/ADT/StringRef.h"
19#include <mutex>
20#include <string>
21#include <vector>
22
23namespace clang {
24namespace clangd {
25namespace trace {
26
27/// A RAII Tracer that can be used by tests.
28class TestTracer : public EventTracer {
29public:
30 TestTracer() : S(*this) {}
31 /// Stores all the measurements to be returned with take later on.
32 void record(const Metric &Metric, double Value,
33 llvm::StringRef Label) override;
34
35 /// Returns recorded measurements for \p Metric and clears them.
36 std::vector<double> takeMetric(llvm::StringRef Metric,
37 llvm::StringRef Label = "");
38
39private:
40 std::mutex Mu;
41 /// Measurements recorded per metric per label.
42 llvm::StringMap<llvm::StringMap<std::vector<double>>> Measurements;
43 Session S;
44};
45
46} // namespace trace
47} // namespace clangd
48} // namespace clang
49#endif
A consumer of trace events and measurements.
Definition: Trace.h:74
Sets up a global EventTracer that consumes events produced by Span and trace::log.
Definition: Trace.h:107
A RAII Tracer that can be used by tests.
Definition: TestTracer.h:28
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