@@ -107,6 +107,7 @@ static int copy_map(struct cmt_opts *opts, struct cmt_map *dst, struct cmt_map *
107107 struct cfl_list * head ;
108108 struct cmt_metric * metric_dst ;
109109 struct cmt_metric * metric_src ;
110+ struct cmt_histogram * histogram ;
110111
111112 /* Handle static metric (no labels case) */
112113 if (src -> metric_static_set ) {
@@ -116,6 +117,37 @@ static int copy_map(struct cmt_opts *opts, struct cmt_map *dst, struct cmt_map *
116117 metric_dst = & dst -> metric ;
117118 metric_src = & src -> metric ;
118119
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+
119151 ts = cmt_metric_get_timestamp (metric_src );
120152 val = cmt_metric_get_value (metric_src );
121153
@@ -140,13 +172,16 @@ static int copy_map(struct cmt_opts *opts, struct cmt_map *dst, struct cmt_map *
140172 }
141173
142174 if (src -> type == CMT_HISTOGRAM ) {
175+ histogram = (struct cmt_histogram * ) src -> parent ;
176+
143177 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 ));
145179 if (!metric_dst -> hist_buckets ) {
146180 return -1 ;
147181 }
148182 }
149- for (i = 0 ; i < metric_src -> hist_count ; i ++ ) {
183+
184+ for (i = 0 ; i < histogram -> buckets -> count ; i ++ ) {
150185 metric_dst -> hist_buckets [i ] = metric_src -> hist_buckets [i ];
151186 }
152187 metric_dst -> hist_count = metric_src -> hist_count ;
@@ -313,16 +348,12 @@ int cmt_cat_histogram(struct cmt *cmt, struct cmt_histogram *histogram)
313348 opts -> name , opts -> description ,
314349 buckets ,
315350 map -> label_count , labels );
351+ free (labels );
352+
316353 if (!hist ) {
317354 return -1 ;
318355 }
319356
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-
326357 ret = copy_map (& hist -> opts , hist -> map , map );
327358 if (ret == -1 ) {
328359 return -1 ;
0 commit comments