1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */ 2*4882a593Smuzhiyun #ifndef __PERF_EVENTS_STATS_ 3*4882a593Smuzhiyun #define __PERF_EVENTS_STATS_ 4*4882a593Smuzhiyun 5*4882a593Smuzhiyun #include <stdio.h> 6*4882a593Smuzhiyun #include <perf/event.h> 7*4882a593Smuzhiyun #include <linux/types.h> 8*4882a593Smuzhiyun #include "auxtrace.h" 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun /* 11*4882a593Smuzhiyun * The kernel collects the number of events it couldn't send in a stretch and 12*4882a593Smuzhiyun * when possible sends this number in a PERF_RECORD_LOST event. The number of 13*4882a593Smuzhiyun * such "chunks" of lost events is stored in .nr_events[PERF_EVENT_LOST] while 14*4882a593Smuzhiyun * total_lost tells exactly how many events the kernel in fact lost, i.e. it is 15*4882a593Smuzhiyun * the sum of all struct perf_record_lost.lost fields reported. 16*4882a593Smuzhiyun * 17*4882a593Smuzhiyun * The kernel discards mixed up samples and sends the number in a 18*4882a593Smuzhiyun * PERF_RECORD_LOST_SAMPLES event. The number of lost-samples events is stored 19*4882a593Smuzhiyun * in .nr_events[PERF_RECORD_LOST_SAMPLES] while total_lost_samples tells 20*4882a593Smuzhiyun * exactly how many samples the kernel in fact dropped, i.e. it is the sum of 21*4882a593Smuzhiyun * all struct perf_record_lost_samples.lost fields reported. 22*4882a593Smuzhiyun * 23*4882a593Smuzhiyun * The total_period is needed because by default auto-freq is used, so 24*4882a593Smuzhiyun * multipling nr_events[PERF_EVENT_SAMPLE] by a frequency isn't possible to get 25*4882a593Smuzhiyun * the total number of low level events, it is necessary to to sum all struct 26*4882a593Smuzhiyun * perf_record_sample.period and stash the result in total_period. 27*4882a593Smuzhiyun */ 28*4882a593Smuzhiyun struct events_stats { 29*4882a593Smuzhiyun u64 total_period; 30*4882a593Smuzhiyun u64 total_non_filtered_period; 31*4882a593Smuzhiyun u64 total_lost; 32*4882a593Smuzhiyun u64 total_lost_samples; 33*4882a593Smuzhiyun u64 total_aux_lost; 34*4882a593Smuzhiyun u64 total_aux_partial; 35*4882a593Smuzhiyun u64 total_invalid_chains; 36*4882a593Smuzhiyun u32 nr_events[PERF_RECORD_HEADER_MAX]; 37*4882a593Smuzhiyun u32 nr_non_filtered_samples; 38*4882a593Smuzhiyun u32 nr_lost_warned; 39*4882a593Smuzhiyun u32 nr_unknown_events; 40*4882a593Smuzhiyun u32 nr_invalid_chains; 41*4882a593Smuzhiyun u32 nr_unknown_id; 42*4882a593Smuzhiyun u32 nr_unprocessable_samples; 43*4882a593Smuzhiyun u32 nr_auxtrace_errors[PERF_AUXTRACE_ERROR_MAX]; 44*4882a593Smuzhiyun u32 nr_proc_map_timeout; 45*4882a593Smuzhiyun }; 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun void events_stats__inc(struct events_stats *stats, u32 type); 48*4882a593Smuzhiyun 49*4882a593Smuzhiyun size_t events_stats__fprintf(struct events_stats *stats, FILE *fp); 50*4882a593Smuzhiyun 51*4882a593Smuzhiyun #endif /* __PERF_EVENTS_STATS_ */ 52