17#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_SUPPORT_TRACE_H
18#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_SUPPORT_TRACE_H
21#include "llvm/ADT/StringRef.h"
22#include "llvm/ADT/Twine.h"
23#include "llvm/Support/JSON.h"
24#include "llvm/Support/raw_ostream.h"
55 llvm::StringLiteral
LabelName = llvm::StringLiteral(
""))
63 const llvm::StringLiteral
Name;
88 llvm::function_ref<
void(llvm::json::Object *)> AttachDetails);
101 llvm::StringRef
Label) {}
121 bool Pretty =
false);
129void log(
const llvm::Twine &
Name);
154 llvm::json::Object *
const Args;
158 Span(std::pair<Context, llvm::json::Object *>);
164#define SPAN_ATTACH(S, Name, Expr) \
166 if (auto *Args = (S).Args) \
167 (*Args)[Name] = Expr; \
llvm::SmallString< 256U > Name
llvm::raw_string_ostream OS
A context is an immutable container for per-request data that must be propagated through layers that ...
WithContext replaces Context::current() with a provided scope.
A consumer of trace events and measurements.
virtual void record(const Metric &Metric, double Value, llvm::StringRef Label)
Called whenever a metrics records a measurement.
virtual Context beginSpan(llvm::StringRef Name, llvm::function_ref< void(llvm::json::Object *)> AttachDetails)
Called when event that has a duration starts.
virtual ~EventTracer()=default
virtual void instant(llvm::StringRef Name, llvm::json::Object &&Args)
Called for instant events.
Sets up a global EventTracer that consumes events produced by Span and trace::log.
Records an event whose duration is the lifetime of the Span object.
llvm::json::Object *const Args
Mutable metadata, if this span is interested.
std::unique_ptr< EventTracer > createJSONTracer(llvm::raw_ostream &OS, bool Pretty)
Create an instance of EventTracer that produces an output in the Trace Event format supported by Chro...
std::unique_ptr< EventTracer > createCSVMetricTracer(llvm::raw_ostream &OS)
Create an instance of EventTracer that outputs metric measurements as CSV.
void log(const llvm::Twine &Message)
Records a single instant event, associated with the current thread.
bool enabled()
Returns true if there is an active tracer.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Represents measurements of clangd events, e.g.
const llvm::StringLiteral Name
Uniquely identifies the metric.
const llvm::StringLiteral LabelName
Indicates what measurement labels represent, e.g.
@ Value
A number whose value is meaningful, and may vary over time.
@ Counter
An aggregate number whose rate of change over time is meaningful.
@ Distribution
A distribution of values with a meaningful mean and count.
constexpr Metric(llvm::StringLiteral Name, MetricType Type, llvm::StringLiteral LabelName=llvm::StringLiteral(""))
void record(double Value, llvm::StringRef Label="") const
Records a measurement for this metric to active tracer.