summaryrefslogtreecommitdiff
path: root/PerformancePkg/Dp_App/DpInternal.h
blob: 656223020932418ca2d8b75e700b5db10a8dc319 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/** @file
  * Declarations of objects defined internally to the Dp Application.
  *
  * Declarations of data and functions which are private to the Dp application.
  * This file should never be referenced by anything other than components of the
  * Dp application.  In addition to global data, function declarations for
  * DpUtilities.c, DpTrace.c, and DpProfile.c are included here.
  *
  * Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
  * This program and the accompanying materials
  * are licensed and made available under the terms and conditions of the BSD License
  * which accompanies this distribution.  The full text of the license may be found at
  * http://opensource.org/licenses/bsd-license.php
  *
  * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef _DP_INTELNAL_H_
#define _DP_INTELNAL_H_
//
/// Module-Global Variables
///@{
extern EFI_HII_HANDLE     gHiiHandle;
extern CHAR16             *mPrintTokenBuffer;
extern CHAR16             mGaugeString[DXE_PERFORMANCE_STRING_SIZE];
extern CHAR16             mUnicodeToken[PERF_TOKEN_LENGTH + 1];
extern UINT64             mInterestThreshold;

extern PERF_SUMMARY_DATA  SummaryData;    ///< Create the SummaryData structure and init. to ZERO.

/// Timer Specific Information.
extern TIMER_INFO         TimerInfo;

/// Items for which to gather cumulative statistics.
extern PERF_CUM_DATA      CumData[];

/// Number of items for which we are gathering cumulative statistics.
extern UINT32 const       NumCum;

///@}

/** Calculate an event's duration in timer ticks.
  *
  * Given the count direction and the event's start and end timer values,
  * calculate the duration of the event in timer ticks.
  *
  * @pre  The global TimerInfo structure must have already been initialized
  *       before this function is called.
  *
  * @param[in,out]    Measurement   Pointer to a structure containing data for the current measurement.
  *
  * @return       The 64-bit duration of the event.
**/
UINT64
GetDuration (
  IN OUT MEASUREMENT_RECORD *Measurement
);

/** Determine whether the Measurement record is for an EFI Phase.
  *
  * The Token and Module members of the measurement record are checked.
  * Module must be empty and Token must be one of SEC, PEI, DXE, or BDS.
  *
  * @param[in]  Measurement A pointer to the Measurement record to test.
  *
  * @retval     TRUE        The measurement record is for an EFI Phase.
  * @retval     FALSE       The measurement record is NOT for an EFI Phase.
**/
BOOLEAN
IsPhase(
  IN MEASUREMENT_RECORD *Measurement
);

/** Get the file name portion of the Pdb File Name.
  *
  * The portion of the Pdb File Name between the last backslash and
  * either a following period or the end of the string is converted
  * to Unicode and copied into UnicodeBuffer.  The name is truncated,
  * if necessary, to ensure that UnicodeBuffer is not overrun.
  *
  * @param[in]  PdbFileName     Pdb file name.
  * @param[out] UnicodeBuffer   The resultant Unicode File Name.
  *
**/
VOID
GetShortPdbFileName (
  IN  CHAR8     *PdbFileName,
  OUT CHAR16    *UnicodeBuffer
);

/** Get a human readable name for an image handle.
  *
  * @param[in]    Handle
  *
  * @post   The resulting Unicode name string is stored in the
  *         mGaugeString global array.
  *
**/
VOID
GetNameFromHandle (
  IN EFI_HANDLE Handle
);

/** Calculate the Duration in microseconds.
  *
  * Duration is multiplied by 1000, instead of Frequency being divided by 1000
  * in order to maintain precision.  Since Duration is
  * a 64-bit value, multiplying it by 1000 is unlikely to produce an overflow.
  *
  * @param[in] Duration   The event duration in timer ticks.
  *
  * @return   A 64-bit value which is the Elapsed time in microseconds.
**/
UINT64
DurationInMicroSeconds (
  IN UINT64 Duration
);

/** Formatted Print using a Hii Token to reference the localized format string.
  *
  * @param[in]  Token   A HII token associated with a localized Unicode string.
  *
  * @return             The number of characters converted by UnicodeVSPrint().
  *
**/
UINTN
PrintToken (
  IN UINT16 Token,
  ...
);

/** Get index of Measurement Record's match in the CumData array.
  *
  * @param[in]  Measurement A pointer to a Measurement Record to match against the CumData array.
  *
  * @retval     <0    Token is not in the CumData array.
  * @retval     >=0   Return value is the index into CumData where Token is found.
**/
INTN
GetCumulativeItem(
  IN MEASUREMENT_RECORD *Measurement
);

/** Collect verbose statistics about the logged performance measurements.
  *
  * General Summary information for all Trace measurements is gathered and
  * stored within the SummaryData structure.  This information is both
  * used internally by subsequent reporting functions, and displayed
  * at the end of verbose reports.
  *
  * @pre  The SummaryData and CumData structures must be initialized
  *       prior to calling this function.
  *
  * @post The SummaryData and CumData structures contain statistics for the
  *       current performance logs.
**/
VOID
GatherStatistics(
  VOID
);

/** Gather and print ALL Trace Records.
  *
  * Displays all "interesting" Trace measurements in order.
  * The number of records displayed is controlled by:
  *   - records with a duration less than mInterestThreshold microseconds are not displayed.
  *   - No more than Limit records are displayed.  A Limit of zero will not limit the output.
  *   - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not
  *     displayed.
  *
  * @pre    The mInterestThreshold global variable is set to the shortest duration to be printed.
  *         The mGaugeString and mUnicodeToken global arrays are used for temporary string storage.
  *         They must not be in use by a calling function.
  *
  * @param[in]    Limit       The number of records to print.  Zero is ALL.
  * @param[in]    ExcludeFlag TRUE to exclude individual Cumulative items from display.
  *
**/
VOID
DumpAllTrace(
  IN UINTN             Limit,
  IN BOOLEAN           ExcludeFlag
);

/** Gather and print Raw Trace Records.
  *
  * All Trace measurements with a duration greater than or equal to
  * mInterestThreshold are printed without interpretation.
  *
  * The number of records displayed is controlled by:
  *   - records with a duration less than mInterestThreshold microseconds are not displayed.
  *   - No more than Limit records are displayed.  A Limit of zero will not limit the output.
  *   - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not
  *     displayed.
  *
  * @pre    The mInterestThreshold global variable is set to the shortest duration to be printed.
  *
  * @param[in]    Limit       The number of records to print.  Zero is ALL.
  * @param[in]    ExcludeFlag TRUE to exclude individual Cumulative items from display.
  *
**/
VOID
DumpRawTrace(
  IN UINTN          Limit,
  IN BOOLEAN        ExcludeFlag
);

/** Gather and print Major Phase metrics.
  *
  * @param[in]    Ticker      The timer value for the END of Shell phase
  *
**/
VOID
ProcessPhases(
  IN UINT64 Ticker
);


/** Gather and print Handle data.
  *
  * @param[in]    ExcludeFlag   TRUE if the -x command line flag given.  Elides accumulated trace records.
  *
  * @return       Status from a call to gBS->LocateHandle().
**/
EFI_STATUS
ProcessHandles(
  IN BOOLEAN ExcludeFlag
);


/** Gather and print PEIM data.
  *
  * Only prints complete PEIM records
  *
**/
VOID
ProcessPeims(
  VOID
);

/** Gather and print global data.
  *
  * Strips out incomplete or "Execution Phase" records
  * Only prints records where Handle is NULL
  * Increment TIndex for every record, even skipped ones, so that we have an
  * indication of every measurement record taken.
  *
  *
**/
VOID
ProcessGlobal(
  VOID
);

/** Gather and print cumulative data.
  *
  * Traverse the measurement records and:
  * for each record with a Token listed in the CumData array,
  *   Update the instance count and the total, minimum, and maximum durations.
  * Finally, print the gathered cumulative statistics.
  *
**/
VOID
ProcessCumulative(
  VOID
);

/** Gather and print ALL Profile Records.
  *
  * @param[in]    Limit       The number of records to print.  Zero is ALL.
  * @param[in]    ExcludeFlag TRUE to exclude individual Cumulative items from display
  *
**/
VOID
DumpAllProfile(
  IN UINTN          Limit,
  IN BOOLEAN        ExcludeFlag
);

/** Gather and print Raw Profile Records.
  *
  * @param[in]    Limit       The number of records to print.
  * @param[in]    ExcludeFlag TRUE to exclude individual Cumulative items from display
  *
**/
VOID
DumpRawProfile(
  IN UINTN          Limit,
  IN BOOLEAN        ExcludeFlag
);
#endif