1
2 /*
3 * Copyright (C) Texas Instruments - http://www.ti.com/
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 *
11 * This library 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 GNU
14 * Lesser General Public License for more details.
15 *
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21 #define __PERF_C__
22
23 #include "perf_config.h"
24 #include "perf.h"
25
26 /* used internal function declarations */
27 PERF_LOG_Private *
28 __PERF_LOG_create(PERF_Private *perf, PERF_Config *config,
29 PERF_MODULETYPE eModule);
30
31 void
32 __PERF_LOG_done(PERF_Private *perf);
33
34 /* get custom implementation */
35 #ifdef __PERF_CUSTOMIZABLE__
36 #include "perf_custom.c"
37 #endif
38
39 /*=============================================================================
40 INSTRUMENTATION INTERFACE
41 =============================================================================*/
42
43 static
44 void
__common_Done(PERF_OBJHANDLE * phObject)45 __common_Done(PERF_OBJHANDLE *phObject)
46 {
47 PERF_OBJHANDLE hObject = *phObject;
48 PERF_Private *me = get_Private(hObject);
49
50 /* we may not have allocated the private structure */
51 if (me)
52 {
53 #ifdef __PERF_CUSTOMIZABLE__
54 __PERF_CUSTOM_done(me);
55 #else
56 if (me->uMode & PERF_Mode_Log)
57 { /* close log */
58 __PERF_LOG_done(me);
59 }
60 #endif
61
62 /* delete private structure */
63 free (me);
64 (*phObject)->pComponentPrivate = NULL;
65 }
66
67 /* delete PERF opject */
68 free (*phObject);
69
70 /* invalidate handle */
71 *phObject = NULL;
72 }
73
74 PERF_OBJHANDLE
__PERF_common_Create(PERF_Config * config,unsigned long ulID,PERF_MODULETYPE eModule)75 __PERF_common_Create(PERF_Config *config,
76 unsigned long ulID,
77 PERF_MODULETYPE eModule)
78 {
79 PERF_OBJHANDLE hPERF = NULL;
80 PERF_Private *me = NULL;
81
82 if ((config->mask & eModule & ~PERF_ModuleMask) &&
83 (config->mask & (1 << (eModule & PERF_ModuleMask))))
84 {
85 /* allocate object */
86 hPERF = (PERF_OBJHANDLE) malloc(sizeof(PERF_OBJTYPE));
87
88 /* set up methods */
89 if (hPERF != NULL)
90 {
91 hPERF->pApplicationPrivate = NULL;
92 hPERF->Done = __common_Done;
93 hPERF->pComponentPrivate =
94 me = (PERF_Private *) malloc(sizeof(PERF_Private));
95
96 if (me)
97 {
98 /* no flags are selected, and capture creation time */
99 me->uMode = PERF_Mode_None;
100 me->ulID = ulID;
101 me->pLog = NULL;
102 PID_GET(me->ulPID);
103
104 /* save original time stamp */
105 TIME_GET(me->time);
106 TIME_COPY(me->tempTime, me->time);
107
108 /* create LOG private structures a log file is specified */
109 if (config->trace_file)
110 {
111 __PERF_LOG_create(me, config, eModule);
112 }
113
114 #ifdef __PERF_CUSTOMIZABLE__
115 __PERF_CUSTOM_create(hPERF, config, eModule);
116 #endif
117 }
118
119 /* if we could not create any logging object (no flag is enabled) */
120 if (!me || me->uMode == PERF_Mode_None)
121 { /* free up object */
122 __common_Done(&hPERF);
123 }
124 }
125 }
126
127 return(hPERF);
128 }
129
130 PERF_OBJHANDLE
PERF_Create(unsigned long ulID,PERF_MODULETYPE eModule)131 PERF_Create(unsigned long ulID, PERF_MODULETYPE eModule)
132 {
133 PERF_OBJTYPE *hPERF = NULL; /* PERF object */
134 char tag[5] = { PERF_FOUR_CHARS(ulID), 0 };
135 int i;
136
137 /* replace spaces in ID with _ */
138 for (i=0; i<4; i++) if (tag[i] == ' ') tag[i] = '_';
139 ulID = PERF_FOURS(tag);
140
141 /* read config file */
142 PERF_Config config;
143 PERF_Config_Init(&config);
144 PERF_Config_Read(&config, tag);
145
146 /* remove replay file if any */
147 if (config.replay_file)
148 {
149 free(config.replay_file);
150 config.replay_file = NULL;
151 }
152
153 /* create for capturing */
154 hPERF = __PERF_common_Create(&config, ulID, eModule);
155
156 PERF_Config_Release(&config);
157 return(hPERF);
158 }
159
160