1 /* $Id$ */
2 /*
3 ** Copyright (C) 2014-2021 Cisco and/or its affiliates. All rights reserved.
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License Version 2 as
7 ** published by the Free Software Foundation.  You may not use, modify or
8 ** distribute this program under any other version of the GNU General
9 ** Public License.
10 **
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ** GNU General Public License for more details.
15 **
16 ** You should have received a copy of the GNU General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20 
21 #ifndef _PERF_INDICATORS_H_
22 #define _PERF_INDICATORS_H_
23 
24 #include "profiler.h"
25 
26 /*#define PI_PROCESSOR_UTILIZATION_SUPPORT*/
27 
28 #ifdef PERF_PROFILING
29 #define PI_PACKET_LATENCY_SUPPORT
30 #endif
31 
32 #define PI_PACKET_DROPS_SUPPORT
33 
34 /* Force the collection of packet latency profiler data */
35 #ifdef PI_PACKET_LATENCY_SUPPORT
36 #define PI_PREPROCS (1)
37 #endif
38 
39 enum Perf_Indicator_Type
40 {
41     Perf_Indicator_Type_None = 0,
42     Perf_Indicator_Type_Packet_Latency,
43     Perf_Indicator_Type_Processor_Utilization,
44     Perf_Indicator_Type_DAQ_Drops
45 };
46 
47 struct Perf_Indicator_Descriptor;
48 
49 struct Perf_Indicator_Latency
50 {
51     uint32_t Latency_us;
52 };
53 
54 struct Perf_Indicator_Processor
55 {
56     double Processor_Load;
57 };
58 
59 struct Perf_Indicator_Drops
60 {
61     double Drop_Portion;
62 };
63 
64 struct _Perf_Indicator_Descriptor
65 {
66     enum Perf_Indicator_Type Type;
67     struct _Perf_Indicator_Descriptor *Next;
68     bool Valid;
69     union
70     {
71         struct Perf_Indicator_Latency Latency;
72         struct Perf_Indicator_Processor Processor;
73         struct Perf_Indicator_Drops Drops;
74     } Indicator;
75 };
76 
77 typedef struct _Perf_Indicator_Descriptor
78         Perf_Indicator_Descriptor_t, *Perf_Indicator_Descriptor_p_t;
79 
80 #ifdef PERF_PROFILING
81 int PerfIndicator_RegisterPreprocStat( PreprocStats *Stats,
82                                        enum Perf_Indicator_Type Type );
83 #endif
84 
85 int PerfIndicator_GetIndicators( Perf_Indicator_Descriptor_p_t PI_List );
86 
87 #ifdef PI_PACKET_LATENCY_SUPPORT
88 uint32_t GetPacketLatency(void);
89 #endif
90 
91 #ifdef PI_PACKET_DROPS_SUPPORT
92 double GetPacketDropPortion(void);
93 #endif
94 
PerfIndicator_NewDescriptor(void)95 static inline Perf_Indicator_Descriptor_p_t PerfIndicator_NewDescriptor(void)
96 {
97     /* Caller must check for NULL */
98     return( (Perf_Indicator_Descriptor_p_t)calloc(sizeof(Perf_Indicator_Descriptor_t), sizeof(char)));
99 }
100 
PerfIndicator_FreeDescriptorList(Perf_Indicator_Descriptor_p_t PI_List)101 static inline void PerfIndicator_FreeDescriptorList( Perf_Indicator_Descriptor_p_t PI_List )
102 {
103     if( PI_List->Next != NULL )
104         PerfIndicator_FreeDescriptorList( PI_List->Next );
105     free( PI_List );
106 }
107 
PerfIndicator_CreateAndInsertDescriptor(Perf_Indicator_Descriptor_p_t * PI_List_Ptr,enum Perf_Indicator_Type Type)108 static inline int PerfIndicator_CreateAndInsertDescriptor( Perf_Indicator_Descriptor_p_t *PI_List_Ptr,
109                                                     enum Perf_Indicator_Type Type )
110 {
111     Perf_Indicator_Descriptor_p_t elem;
112 
113     if( (PI_List_Ptr == NULL) || (elem = PerfIndicator_NewDescriptor()) == NULL )
114         return( -1 );
115 
116     elem->Type = Type;
117     elem->Next = *PI_List_Ptr;
118     *(PI_List_Ptr) = elem;
119     return( 0 );
120 }
121 
122 #endif
123