10
10
/*
11
11
* Class Structure Diagram:
12
12
*
13
- * +------------------+
14
- * | QueryStats |
15
- * Temp. storing folly thread root +------------------+
16
- * layer. Will be aggregated to <...| - child_layers_[]| +---------------------+
17
- * root_layer when func. is finished | - root_layer_ ---|------------------->| StatsGroupLayer |
18
- * | - is_enabled_ | +---------------------+
19
- * Ref. pointer to the layer <...| - current_layer_ | | - stats_[] | .......> Storing non-groupable stats
20
- * in use +------------------+ | - next_layer_maps_[]|
21
- * ^ +---------------------+
22
- * | |
23
- * | |
24
- * | |
25
- * | Extend the chain |
26
- * | and temporarily update |
27
- * +-------+-------+ QueryStats's current_layer_ |
28
- * | StatsGroup |................................|
29
- * +---------------+ v
13
+ * +--------------------+
14
+ * | QueryStats |
15
+ * +--------------------+
16
+ * | - is_enabled_ |
17
+ * | - root_layers_[] |
18
+ * | - thread_local_var_|
19
+ * +------|-------------+
20
+ * |
21
+ * v
22
+ * +-------------------------+ +---------------------+
23
+ * | ThreadLocalQueryStatsVar| | StatsGroupLayer |
24
+ * +-------------------------+ +---------------------+
25
+ * Temp. storing folly thread<-| - child_layers_[] | | - stats_[] | --> Storing non-groupable stats
26
+ * layer. Will be aggregated | - root_layer_ | | - next_layer_maps_[]|
27
+ * to root_layer when | - current_layer_ -------|------------------>+---------------------+
28
+ * function is finished +-------------------------+ |
29
+ * | |
30
+ * | Extend the chain |
31
+ * | and temporarily update |
32
+ * v current_layer_ |
33
+ * +---------------+ |
34
+ * | StatsGroup |-------------------------------|
35
+ * +---------------+ v
30
36
* | - prev_layer_ | +-------------------+
31
- * | - start_ | | StatsGroupLayer |-----> ... (more layers)
32
- * | - log_time_ | +-------------------+
33
- * +---------------+
34
- *
37
+ * | - start_ | | StatsGroupLayer |
38
+ * | | +-------------------+
39
+ * +---------------+ |
40
+ * v
41
+ * .. (more layers)
42
+ *
43
+ *
44
+ *
45
+ *
35
46
* Structure:
36
47
* - QueryStats: Singleton manager class holding the stats collection framework
48
+ * - ThreadLocalQueryStatsVar: Thread-local storage for stats layers and management
37
49
* - StatsGroupLayer: Hierarchical node containing stats and references to child layers
38
50
* - StatsGroup: RAII wrapper that temporarily extends the layer chain during its lifetime
39
51
* When created, it adds a new layer and when destroyed, it restores the previous layer state
61
73
#include < fmt/format.h>
62
74
63
75
namespace arcticdb ::util::query_stats {
64
- using StatsGroups = std::vector<std::shared_ptr<std::pair<std::string, std::string>>>;
65
-
66
-
67
- // process-global stats entry list
68
76
enum class StatsGroupName : size_t {
69
77
arcticdb_call = 0 ,
70
78
key_type = 1 ,
@@ -85,9 +93,15 @@ class StatsGroupLayer {
85
93
void merge_from (const StatsGroupLayer& other);
86
94
};
87
95
96
+ struct ChildLayer {
97
+ std::shared_ptr<StatsGroupLayer> parent_layer_;
98
+ std::shared_ptr<StatsGroupLayer> root_layer_;
99
+ };
100
+
101
+ // Collection of thread-local variables that reside in class QueryStats simply for the sake of convenience
88
102
struct ThreadLocalQueryStatsVar {
89
103
std::mutex child_layer_creation_mutex_;
90
- std::vector<std::pair<std::shared_ptr<StatsGroupLayer>, std::shared_ptr<StatsGroupLayer>> > child_layers_;
104
+ std::vector<ChildLayer > child_layers_;
91
105
std::shared_ptr<StatsGroupLayer> root_layer_ = nullptr ;
92
106
std::shared_ptr<StatsGroupLayer> current_layer_ = nullptr ;
93
107
};
0 commit comments