50 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8//9// Allows setting up a fake tracer for tests.10//11//===----------------------------------------------------------------------===//12 13#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_SUPPORT_TESTTRACER_H14#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_SUPPORT_TESTTRACER_H15 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 trace47} // namespace clangd48} // namespace clang49#endif50