blob: 99602a25ab712b6649affdb142c8389363e832f3 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include <vespa/vespalib/trace/tracenode.h>
#include <vespa/vespalib/stllike/string.h>
#include <vespa/vespalib/data/memory.h>
namespace vespalib::slime {
struct Cursor;
struct Inspector;
}
namespace config {
/**
* Clock interface for acquiring time.
*/
struct Clock {
virtual vespalib::system_time currentTime() const = 0;
virtual ~Clock() {}
};
/**
* A simple trace interface which can be used to create a serial trace log of events. Each entry is given a timestamp. The trace
* can be serialized to/constructed from slime. Is not thread safe.
*/
class Trace
{
public:
Trace(const Trace & other);
Trace();
Trace(uint32_t traceLevel);
Trace(uint32_t traceLevel, const Clock & clock);
bool shouldTrace(uint32_t level) const;
void trace(uint32_t level, const vespalib::string & message);
void serialize(vespalib::slime::Cursor & cursor) const;
void deserialize(const vespalib::slime::Inspector & inspector);
const vespalib::TraceNode & getRoot() const { return _root; }
vespalib::string toString() const;
private:
void serializeTraceLog(vespalib::slime::Cursor & array) const;
void deserializeTraceLog(const vespalib::slime::Inspector & inspector);
static const vespalib::Memory TRACELOG;
static const vespalib::Memory TRACELEVEL;
vespalib::TraceNode _root;
uint32_t _traceLevel;
const Clock & _clock;
};
} // namespace config
|