@@ -107,6 +107,7 @@ static int copy_map(struct cmt_opts *opts, struct cmt_map *dst, struct cmt_map *
107
107
struct cfl_list * head ;
108
108
struct cmt_metric * metric_dst ;
109
109
struct cmt_metric * metric_src ;
110
+ struct cmt_histogram * histogram ;
110
111
111
112
/* Handle static metric (no labels case) */
112
113
if (src -> metric_static_set ) {
@@ -116,6 +117,37 @@ static int copy_map(struct cmt_opts *opts, struct cmt_map *dst, struct cmt_map *
116
117
metric_dst = & dst -> metric ;
117
118
metric_src = & src -> metric ;
118
119
120
+ if (src -> type == CMT_HISTOGRAM ) {
121
+ histogram = (struct cmt_histogram * ) src -> parent ;
122
+
123
+ if (!metric_dst -> hist_buckets ) {
124
+ metric_dst -> hist_buckets = calloc (1 , sizeof (uint64_t ) * (histogram -> buckets -> count + 1 ));
125
+ if (!metric_dst -> hist_buckets ) {
126
+ return -1 ;
127
+ }
128
+ }
129
+ for (i = 0 ; i < histogram -> buckets -> count ; i ++ ) {
130
+ metric_dst -> hist_buckets [i ] = metric_src -> hist_buckets [i ];
131
+ }
132
+ metric_dst -> hist_count = metric_src -> hist_count ;
133
+ metric_dst -> hist_sum = metric_src -> hist_sum ;
134
+ }
135
+ else if (src -> type == CMT_SUMMARY ) {
136
+ metric_dst -> sum_quantiles_count = metric_src -> sum_quantiles_count ;
137
+ metric_dst -> sum_quantiles_set = metric_src -> sum_quantiles_set ;
138
+ if (!metric_dst -> sum_quantiles ) {
139
+ metric_dst -> sum_quantiles = calloc (1 , sizeof (uint64_t ) * (metric_src -> sum_quantiles_count ));
140
+ if (!metric_dst -> sum_quantiles ) {
141
+ return -1 ;
142
+ }
143
+ }
144
+ for (i = 0 ; i < metric_src -> sum_quantiles_count ; i ++ ) {
145
+ metric_dst -> sum_quantiles [i ] = metric_src -> sum_quantiles [i ];
146
+ }
147
+ metric_dst -> sum_count = metric_src -> sum_count ;
148
+ metric_dst -> sum_sum = metric_src -> sum_sum ;
149
+ }
150
+
119
151
ts = cmt_metric_get_timestamp (metric_src );
120
152
val = cmt_metric_get_value (metric_src );
121
153
@@ -140,13 +172,16 @@ static int copy_map(struct cmt_opts *opts, struct cmt_map *dst, struct cmt_map *
140
172
}
141
173
142
174
if (src -> type == CMT_HISTOGRAM ) {
175
+ histogram = (struct cmt_histogram * ) src -> parent ;
176
+
143
177
if (!metric_dst -> hist_buckets ) {
144
- metric_dst -> hist_buckets = calloc (1 , sizeof (uint64_t ) * (metric_src -> hist_count + 1 ));
178
+ metric_dst -> hist_buckets = calloc (1 , sizeof (uint64_t ) * (histogram -> buckets -> count + 1 ));
145
179
if (!metric_dst -> hist_buckets ) {
146
180
return -1 ;
147
181
}
148
182
}
149
- for (i = 0 ; i < metric_src -> hist_count ; i ++ ) {
183
+
184
+ for (i = 0 ; i < histogram -> buckets -> count ; i ++ ) {
150
185
metric_dst -> hist_buckets [i ] = metric_src -> hist_buckets [i ];
151
186
}
152
187
metric_dst -> hist_count = metric_src -> hist_count ;
@@ -313,16 +348,12 @@ int cmt_cat_histogram(struct cmt *cmt, struct cmt_histogram *histogram)
313
348
opts -> name , opts -> description ,
314
349
buckets ,
315
350
map -> label_count , labels );
351
+ free (labels );
352
+
316
353
if (!hist ) {
317
354
return -1 ;
318
355
}
319
356
320
- for (i = 0 ; i < buckets_count ; i ++ ) {
321
- val = histogram -> buckets -> upper_bounds [i ];
322
- cmt_histogram_observe (hist , timestamp , val , map -> label_count , labels );
323
- }
324
- free (labels );
325
-
326
357
ret = copy_map (& hist -> opts , hist -> map , map );
327
358
if (ret == -1 ) {
328
359
return -1 ;
0 commit comments