@@ -76,3 +76,103 @@ yanet_get_counter_value(
7676
7777void
7878yanet_counter_handle_list_free (struct counter_handle_list * counters );
79+
80+ /**
81+ * Represents a single latency bucket in a performance histogram.
82+ *
83+ * Each bucket tracks how many packet batches were processed with latency
84+ * greater than or equal to min_latency. The histogram uses a hybrid approach
85+ * with linear buckets for fine-grained resolution at typical latencies and
86+ * exponential buckets for efficient coverage of outliers.
87+ */
88+ struct module_performance_counter_latency_range {
89+ /** Minimum latency in nanoseconds for this bucket */
90+ uint64_t min_latency ;
91+
92+ /** Number of packet batches that fell into this latency bucket */
93+ size_t batches ;
94+ };
95+
96+ /**
97+ * Performance metrics for a specific packet batch size range.
98+ *
99+ * Modules process packets in batches, and this structure contains latency
100+ * statistics for a particular batch size range (e.g., 1 packet, 2-3 packets,
101+ * 4-7 packets, etc.). The latency distribution is captured using a hybrid
102+ * histogram with both linear and exponential buckets.
103+ */
104+ struct module_performance_counter {
105+ /** Mean processing latency in nanoseconds across all batches */
106+ float mean_latency ;
107+
108+ /** Minimum batch size for this counter (e.g., 1, 2, 4, 8, 16, 32) */
109+ uint64_t min_batch_size ;
110+
111+ /** Number of latency histogram buckets */
112+ size_t latency_ranges_count ;
113+
114+ /** Array of latency histogram buckets, sorted by increasing min_latency
115+ */
116+ struct module_performance_counter_latency_range * latency_ranges ;
117+ };
118+
119+ /**
120+ * Collection of all performance counters for a module.
121+ *
122+ * Contains performance metrics for all 6 batch size ranges tracked by the
123+ * module: 1, 2-3, 4-7, 8-15, 16-31, and 32+ packets. Each counter includes
124+ * mean latency and a detailed histogram of latency measurements.
125+ */
126+ struct module_performance_counters {
127+ /** Number of performance counters (typically 6, one per batch size
128+ * range) */
129+ size_t counters_count ;
130+
131+ /** Array of performance counters, ordered by min_batch_size */
132+ struct module_performance_counter * counters ;
133+ };
134+
135+ /**
136+ * Retrieve module performance counters from the dataplane configuration.
137+ *
138+ * This function extracts and aggregates performance metrics for a specific
139+ * module across all worker threads. The metrics include latency histograms
140+ * for different packet batch sizes (1, 2-3, 4-7, 8-15, 16-31, 32+ packets).
141+ *
142+ * The returned structure must be freed using
143+ * yanet_module_performance_counters_free() when no longer needed.
144+ *
145+ * @param counters Output parameter for the performance counters structure
146+ * @param dp_config Pointer to the dataplane configuration
147+ * @param device_name Name of the device
148+ * @param pipeline_name Name of the pipeline
149+ * @param function_name Name of the function
150+ * @param chain_name Name of the chain
151+ * @param module_type Type identifier of the module
152+ * @param module_name Name identifier of the module
153+ * @return 0 on success, negative error code on failure
154+ */
155+ int
156+ yanet_module_performance_counters (
157+ struct module_performance_counters * counters ,
158+ struct dp_config * dp_config ,
159+ const char * device_name ,
160+ const char * pipeline_name ,
161+ const char * function_name ,
162+ const char * chain_name ,
163+ const char * module_type ,
164+ const char * module_name
165+ );
166+
167+ /**
168+ * Free resources allocated for module performance counters.
169+ *
170+ * Releases all memory allocated by yanet_module_performance_counters(),
171+ * including the latency_ranges arrays within each counter.
172+ *
173+ * @param counters Pointer to the performance counters structure to free
174+ */
175+ void
176+ yanet_module_performance_counters_free (
177+ struct module_performance_counters * counters
178+ );
0 commit comments