source: svn/trunk/newcon3bcm2_21bu/BSEAV/lib/bprofile/btrc.c

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 3.9 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2006-2007, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: btrc.c $
11 * $brcm_Revision: 3 $
12 * $brcm_Date: 1/15/07 10:50a $
13 *
14 * Module Description:
15 *
16 * Perfomance counter module
17 *
18 * Revision History:
19 *
20 * $brcm_Log: /BSEAV/lib/bprofile/btrc.c $
21 *
22 * 3   1/15/07 10:50a vsilyaev
23 * PR 25997: Added 7038 performance counters
24 *
25 * 2   12/8/06 7:21p vsilyaev
26 * PR 25997: Fixed warning
27 *
28 * 1   12/5/06 11:07a vsilyaev
29 * PR 25997: BTRC system level tracing
30 *
31 *
32 *******************************************************************************/
33#include "bstd.h"
34#include "btrc.h"
35#include "bkni.h"
36
37BDBG_MODULE(btrc);
38
39void 
40BTRC_P_DoTrace(unsigned event_, unsigned data)
41{
42        unsigned chn = 0;
43        struct BTRC_P_Stats *stats = &((BTRC_Module *)(event_ & (~0x3)))->stats[chn];
44        BTRC_P_Sample sample;
45        unsigned i;
46        BSTD_UNUSED(data);
47
48        switch((event_)&0x3) {
49        case BTRC_P_Event_COUNT:
50                break;
51        case BTRC_P_Event_START:
52                b_perf_read(&stats->last.perf);
53                break;
54        case BTRC_P_Event_STOP:
55                b_perf_read(&sample.perf);
56                for(i=0;i<BPERF_N_COUNTERS;i++) {
57                        unsigned val;
58
59                        val = bperf_sample_diff(sample.perf.data[i], stats->last.perf.data[i]);
60                        if (stats->count==0) {
61                                stats->max.perf.data[i] =  val;
62                                stats->min.perf.data[i] =  val;
63                                stats->total.perf.data[i] =  val;
64                        } else {
65                                if (val > stats->max.perf.data[i]) {
66                                        stats->max.perf.data[i] =  val;
67                                } else if (val < stats->min.perf.data[i]) {
68                                        stats->min.perf.data[i] =  val;
69                                }
70                                stats->total.perf.data[i] +=  val;
71                        }
72                }
73                stats->count ++;
74                break;
75        }
76        return;
77}
78
79void 
80BTRC_Module_Report(const BTRC_Module *module)
81{
82        const bperf_counter_mode *mode = bperf_get_mode();
83        unsigned chn = 0;
84        const struct BTRC_P_Stats *stats = &module->stats[chn];
85        unsigned i;
86
87        BDBG_ASSERT(module);
88        BDBG_ASSERT(mode);
89        BKNI_Printf("module %s %u samples\n", module->name, stats->count);
90        if (stats->count==0) {
91                return;
92        }
93
94        BKNI_Printf("%8c ", ' ');
95        for(i=0;i<BPERF_N_COUNTERS;i++) {
96                BKNI_Printf("%12s ", mode->counter_names[i]);
97        }
98        BKNI_Printf("\n%8s ", "total");
99        for(i=0;i<BPERF_N_COUNTERS;i++) {
100                BKNI_Printf("%12u ", stats->total.perf.data[i]);
101        }
102        BKNI_Printf("\n%8s ", "average");
103        for(i=0;i<BPERF_N_COUNTERS;i++) {
104                BKNI_Printf("%12u ", stats->total.perf.data[i]/stats->count);
105        }
106        BKNI_Printf("\n%8s ", "max");
107        for(i=0;i<BPERF_N_COUNTERS;i++) {
108                BKNI_Printf("%12u ", stats->max.perf.data[i]);
109        }
110        BKNI_Printf("\n%8s ", "min");
111        for(i=0;i<BPERF_N_COUNTERS;i++) {
112                BKNI_Printf("%12u ", stats->min.perf.data[i]);
113        }
114        BKNI_Printf("\n");
115        return;
116}
117
118
119
120void 
121BTRC_Module_Register(BTRC_Module *module, BTRC_ModuleList *list)
122{
123        BTRC_Module *next;
124
125        /* check if there is a duplicated */
126    for(next= BLST_S_FIRST(list); next ; next = BLST_S_NEXT(next, link)) {
127                if (next==module) {
128                        break;
129                }
130        }
131        if (next==NULL) {
132                /* no module was found add a new one */
133        BLST_S_INSERT_HEAD(list, module, link);
134        }
135        return;
136}
137
138void 
139BTRC_Module_Reset(BTRC_Module *module)
140{
141        unsigned chn = 0;
142        struct BTRC_P_Stats *stats = &module->stats[chn];
143
144        BDBG_ASSERT(module);
145        stats->count = 0;
146        return;
147}
148
149void 
150BTRC_List_Init(BTRC_ModuleList *list)
151{
152        BDBG_ASSERT(list);
153    BLST_S_INIT(list);
154        return;
155}
156
157void 
158BTRC_List_Report(BTRC_ModuleList *list)
159{
160        const BTRC_Module *module;
161
162        /* check if there is a duplicated */
163    for(module=BLST_S_FIRST(list); module ; module = BLST_S_NEXT(module, link)) {
164                BTRC_Module_Report(module);
165        }
166}
167
168
169void 
170BTRC_Module_Enable(BTRC_Module *module, bool enable)
171{
172        BDBG_ASSERT(module);
173        module->b_trc_enable = enable;
174        return;
175}
176
Note: See TracBrowser for help on using the repository browser.