clang-tools  14.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_UNITTESTS_CLANGD_SUPPORT_TESTTRACER_H
14 #define LLVM_CLANG_TOOLS_EXTRA_UNITTESTS_CLANGD_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 
23 namespace clang {
24 namespace clangd {
25 namespace trace {
26 
27 /// A RAII Tracer that can be used by tests.
28 class TestTracer : public EventTracer {
29 public:
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 
39 private:
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
clang::clangd::trace::TestTracer
A RAII Tracer that can be used by tests.
Definition: TestTracer.h:28
Label
std::string Label
Definition: InlayHintTests.cpp:38
clang::clangd::trace::EventTracer
A consumer of trace events and measurements.
Definition: Trace.h:74
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
Trace.h
clang::clangd::trace::TestTracer::TestTracer
TestTracer()
Definition: TestTracer.h:30
clang::clangd::trace::Session
Sets up a global EventTracer that consumes events produced by Span and trace::log.
Definition: Trace.h:107
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