2424#include "we_metric.h"
2525#include "we_perflib.h"
2626
27- double we_perflib_get_adjusted_counter_value (struct we_perflib_counter * counter )
27+ double we_perflib_get_adjusted_counter_value (struct we_perflib_counter * counter ,
28+ struct we_perflib_metric_source * source )
2829{
2930 double result ;
3031
32+ if (source -> use_secondary_value ) {
33+ return (double ) counter -> secondary_value .as_qword ;
34+ }
35+
3136 result = (double ) counter -> primary_value .as_qword ;
3237
3338 switch (counter -> definition -> type ) {
@@ -625,6 +630,7 @@ static int we_perflib_process_counter(
625630 struct we_perflib_counter * * out_counter )
626631{
627632 struct we_perflib_counter * perflib_instance_counter ;
633+ uint32_t counter_type = counter_definition -> type ;
628634
629635 perflib_instance_counter = we_perflib_create_counter (counter_definition );
630636
@@ -636,6 +642,18 @@ static int we_perflib_process_counter(
636642 & input_data_block [counter_definition -> offset ],
637643 counter_definition -> size );
638644
645+ if (counter_type == PERF_AVERAGE_BULK ||
646+ counter_type == PERF_RAW_FRACTION ||
647+ counter_type == PERF_100NSEC_TIMER_INV ||
648+ counter_type == PERF_COUNTER_TIMER_INV ||
649+ counter_type == PERF_100NSEC_MULTI_TIMER_INV ||
650+ counter_type == PERF_COUNTER_MULTI_TIMER_INV ) {
651+
652+ memcpy (& perflib_instance_counter -> secondary_value ,
653+ & input_data_block [counter_definition -> offset + counter_definition -> size ],
654+ sizeof (union we_perflib_value ));
655+ }
656+
639657 if (counter_definition -> size > sizeof (union we_perflib_value )) {
640658 we_perflib_destroy_counter (perflib_instance_counter );
641659
@@ -1024,12 +1042,12 @@ int we_perflib_update_counters(struct flb_we *ctx,
10241042
10251043 if (metric_source -> parent -> type == CMT_COUNTER ) {
10261044 cmt_counter_set (metric_entry , timestamp ,
1027- we_perflib_get_adjusted_counter_value (counter ),
1045+ we_perflib_get_adjusted_counter_value (counter , metric_source ),
10281046 metric_label_count , metric_label_list );
10291047 }
10301048 else if (metric_source -> parent -> type == CMT_GAUGE ) {
10311049 cmt_gauge_set (metric_entry , timestamp ,
1032- we_perflib_get_adjusted_counter_value (counter ),
1050+ we_perflib_get_adjusted_counter_value (counter , metric_source ),
10331051 metric_label_count , metric_label_list );
10341052 }
10351053 }
0 commit comments