| 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 |
|
| 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 |