shr_bprof.c (3410B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * File: shr_bprof.c 8 */ 9 #include <sal/types.h> 10 #include <sal/core/time.h> 11 #include <shared/shr_bprof.h> 12 #include <shared/error.h> 13 #include <sal/appl/sal.h> 14 #include <sal/appl/io.h> 15 16 static sal_usecs_t _bprof_stime_main_start; 17 static sal_usecs_t _bprof_stime_main_end; 18 static shr_bprof_stats_entry_t _bprof_stats[SHR_BPROF_STATS_MAX]; 19 20 /* Max name should be of length < SHR_BPROF_STATS_MAX_NAME 21 This should match with shr_bprof_type_e in shr_bprof.h */ 22 static char _bprof_stats_names[SHR_BPROF_STATS_MAX][SHR_BPROF_STATS_MAX_NAME] = { 23 "soc probe", 24 "soc attach", 25 "init soc", 26 "init misc", 27 "init mmu", 28 "init bcm", 29 "commom", 30 "port", 31 "l2", 32 "stg", 33 "vlan", 34 "trunk", 35 "cosq", 36 "mCast", 37 "linkscan", 38 "stat", 39 "stk", 40 "rate", 41 "knet", 42 "field", 43 "mirror", 44 "tx", 45 "rx", 46 "l3", 47 "ipmc", 48 "mpls", 49 "mim", 50 "wlan", 51 "proxy", 52 "subport", 53 "qos", 54 "trill", 55 "niv", 56 "l2gre", 57 "vxlan", 58 "extender", 59 "multicast", 60 "auth", 61 "regex", 62 "time", 63 "oam", 64 "failover", 65 "ces", 66 "ptp", 67 "bfd", 68 "global_meter", 69 "fcoe", 70 "udf", 71 "sat", 72 "range", 73 "switch", 74 "flow", 75 "tsn", 76 #ifdef SW_AUTONEG_SUPPORT 77 "SW_AN", 78 #endif 79 "xflow_macsec", 80 "flowtracker", 81 "gdpll", 82 "ifa", 83 "collector", 84 "telemetry", 85 "int", 86 "sum", 87 "hash" 88 }; 89 90 void shr_bprof_stats_time_init(void) 91 { 92 _bprof_stime_main_start = sal_time_usecs(); 93 94 return; 95 } 96 97 void shr_bprof_stats_time_end(void) 98 { 99 _bprof_stime_main_end = sal_time_usecs(); 100 101 return; 102 } 103 104 sal_usecs_t shr_bprof_stats_time_taken(void) 105 { 106 return (_bprof_stime_main_end - _bprof_stime_main_start); 107 } 108 109 char * shr_bprof_stats_name(int dispname) 110 { 111 return _bprof_stats_names[dispname]; 112 } 113 114 void shr_bprof_stats_timer_start(int op) 115 { 116 sal_usecs_t now; 117 118 now = sal_time_usecs(); 119 _bprof_stats[op].start_stime = now; 120 121 return; 122 } 123 124 void shr_bprof_stats_timer_stop(int op) 125 { 126 sal_usecs_t now; 127 sal_usecs_t delta; 128 129 now = sal_time_usecs(); 130 delta = now - _bprof_stats[op].start_stime; 131 132 if (!_bprof_stats[op].runs) { 133 _bprof_stats[op].total_stime += delta; 134 _bprof_stats[op].runs++; 135 _bprof_stats[op].min_stime = delta; 136 _bprof_stats[op].max_stime = delta; 137 } else { 138 _bprof_stats[op].total_stime += delta; 139 _bprof_stats[op].runs++; 140 141 if (delta < _bprof_stats[op].min_stime) { 142 _bprof_stats[op].min_stime = delta; 143 } else if (delta > _bprof_stats[op].max_stime) { 144 _bprof_stats[op].max_stime = delta; 145 } 146 } 147 148 return; 149 } 150 151 int shr_bprof_stats_get(int idx, shr_bprof_stats_entry_t *bprof_stats) 152 { 153 if ((idx < 0) || (idx >= SHR_BPROF_STATS_MAX)) { 154 return _SHR_E_UNAVAIL; 155 } 156 157 bprof_stats->start_stime = _bprof_stats[idx].start_stime; 158 bprof_stats->total_stime = _bprof_stats[idx].total_stime; 159 bprof_stats->max_stime = _bprof_stats[idx].max_stime; 160 bprof_stats->min_stime = _bprof_stats[idx].min_stime; 161 bprof_stats->runs = _bprof_stats[idx].runs; 162 163 return _SHR_E_NONE; 164 }