variable¶
- group turbo_profiling_variable
-
class Variable¶
- #include <variable.h>
Variableis the base class for all variables.It provides the basic functionality for exposing and hiding variables. The Variable is Uniqued by name in global scope. the Variable is designed to hold variables that are written many threads and read by one thread. Most of time, the Variable is used to hold the metrics of the system. all the Metric type like Counter, Gauge, UniqueGauge, MinerGauge, AverageGauge are derived from Variable. The Variable is thread-safe. derived class should be implemented the virtual function describe_impl. more detail see the derived class, like Counter, Gauge, UniqueGauge, MinerGauge, AverageGauge. the main purpose of Variable is to provide a unified interface for all the metrics ,and when using the Variable, it cost little performance. for example, we want to record the number of the request. we can use the Counter like this:
and we can get the value of the request_counter like this:Counter<int> request_counter("request_counter","the number of the request"); request_counter++;
it will cost little when call it because erery thread has a local copy of the request_counter. and when write , it only atomicly write it to the local copy. and when read, the combine will combine all the thread local copy to the global copy. so it cost little performance. so that do not read the value of the Variable frequently.int request_count = request_counter.get_value();
Subclassed by turbo::AverageGauge< T >, turbo::Histogram< T, N, typename >, turbo::MaxerGauge< T >, turbo::MinerGauge< T >
Public Functions
-
turbo::Status expose(const std::string_view &name, const std::string_view &description, const std::map<std::string, std::string> &labels, const VariableAttr &type)¶
expose to the global scope.
- Parameters:
name –
description –
labels –
type –
- Returns:
-
bool is_exposed() const¶
check if the variable is exposed.
- Returns:
-
inline const std::string &name() const¶
get the name of the variable.
- Returns:
-
inline const std::string &description() const¶
get the description of the variable.
- Returns:
-
inline const std::map<std::string, std::string> &labels() const¶
get the labels of the variable.
- Returns:
-
inline const VariableAttr &attr() const¶
get the attr of the variable.
- Returns:
-
inline void describe(std::ostream &os, const DescriberOptions &options = DescriberOptions()) const¶
describe variable to stream, for debug
- Returns:
-
inline std::string describe(const DescriberOptions &options = DescriberOptions()) const¶
describe variable to stream, for debug
- Returns:
-
inline VariableSnapshot get_snapshot() const¶
get the snapshot of the variable.
- Returns:
Public Static Functions
-
static void list_exposed(std::vector<std::string> &names, const VariableFilter *filter = nullptr)¶
list all the exposed variable names.
- Parameters:
names –
filter –
-
static size_t count_exposed(const VariableFilter *filter = nullptr)¶
count exposed variable number.
- Parameters:
filter –
- Returns:
-
turbo::Status expose(const std::string_view &name, const std::string_view &description, const std::map<std::string, std::string> &labels, const VariableAttr &type)¶
-
class Variable¶
counter¶
- group turbo_profiling_counters
gauge¶
histogram¶
- group turbo_profiling_histogram
dumper¶
- group turbo_profiling_dumper
Typedefs
-
using VariableSnapshot = std::variant<PlainStringSnapshot, CounterSnapshot, GaugeSnapshot, HistogramSnapshot, ObjectSnapshot>¶
The VariableSnapshot struct is the base class for all snapshots.
Dumper serializers should use this class to access the variable snapshot. Example:
VariableSnapshot snapshot = variable->get_snapshot(); const CounterSnapshot* counter = std::get_if<CounterSnapshot>(&snapshot); if(counter) { // do something }
-
struct VariableDumper¶
- #include <dumper.h>
VariableDumper is the base class for all dumpers.
drivers need to implement the dump function.
Subclassed by turbo::PrometheusDumper
-
struct SnapshotFamily¶
- #include <snapshot.h>
The SnapshotFamily struct is the base class for all snapshots.
Dumper implementations should use this class to access the common fields of all snapshots. drives hold the data field.
Subclassed by turbo::CounterSnapshot, turbo::GaugeSnapshot, turbo::HistogramSnapshot, turbo::ObjectSnapshot, turbo::PlainStringSnapshot
-
struct PrometheusDumper : public turbo::VariableDumper¶
- #include <prometheus_dumper.h>
PrometheusDumper dumps the variable snapshot in prometheus format.
-
using VariableSnapshot = std::variant<PlainStringSnapshot, CounterSnapshot, GaugeSnapshot, HistogramSnapshot, ObjectSnapshot>¶