DpInternal.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /** @file
  2. Declarations of objects defined internally to the Dp Application.
  3. Declarations of data and functions which are private to the Dp application.
  4. This file should never be referenced by anything other than components of the
  5. Dp application. In addition to global data, function declarations for
  6. DpUtilities.c, DpTrace.c, and DpProfile.c are included here.
  7. Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
  8. (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>
  9. SPDX-License-Identifier: BSD-2-Clause-Patent
  10. **/
  11. #ifndef _DP_INTELNAL_H_
  12. #define _DP_INTELNAL_H_
  13. #define DP_GAUGE_STRING_LENGTH 36
  14. //
  15. /// Module-Global Variables
  16. ///@{
  17. extern EFI_HII_HANDLE mDpHiiHandle;
  18. extern CHAR16 mGaugeString[DP_GAUGE_STRING_LENGTH + 1];
  19. extern CHAR16 mUnicodeToken[DXE_PERFORMANCE_STRING_SIZE];
  20. extern UINT64 mInterestThreshold;
  21. extern BOOLEAN mShowId;
  22. extern UINT8 *mBootPerformanceTable;
  23. extern UINTN mBootPerformanceTableLength;
  24. extern MEASUREMENT_RECORD *mMeasurementList;
  25. extern UINTN mMeasurementNum;
  26. extern UINT64 mResetEnd;
  27. extern PERF_SUMMARY_DATA SummaryData; ///< Create the SummaryData structure and init. to ZERO.
  28. /// Items for which to gather cumulative statistics.
  29. extern PERF_CUM_DATA CumData[];
  30. /// Number of items for which we are gathering cumulative statistics.
  31. extern UINT32 const NumCum;
  32. ///@}
  33. /**
  34. Calculate an event's duration in timer ticks.
  35. Given the count direction and the event's start and end timer values,
  36. calculate the duration of the event in timer ticks. Information for
  37. the current measurement is pointed to by the parameter.
  38. If the measurement's start time is 1, it indicates that the developer
  39. is indicating that the measurement began at the release of reset.
  40. The start time is adjusted to the timer's starting count before performing
  41. the elapsed time calculation.
  42. The calculated duration, in ticks, is the absolute difference between
  43. the measurement's ending and starting counts.
  44. @param Measurement Pointer to a MEASUREMENT_RECORD structure containing
  45. data for the current measurement.
  46. @return The 64-bit duration of the event.
  47. **/
  48. UINT64
  49. GetDuration (
  50. IN OUT MEASUREMENT_RECORD *Measurement
  51. );
  52. /**
  53. Determine whether the Measurement record is for an EFI Phase.
  54. The Token and Module members of the measurement record are checked.
  55. Module must be empty and Token must be one of SEC, PEI, DXE, BDS, or SHELL.
  56. @param[in] Measurement A pointer to the Measurement record to test.
  57. @retval TRUE The measurement record is for an EFI Phase.
  58. @retval FALSE The measurement record is NOT for an EFI Phase.
  59. **/
  60. BOOLEAN
  61. IsPhase (
  62. IN MEASUREMENT_RECORD *Measurement
  63. );
  64. /**
  65. Determine whether the Measurement record is for core code.
  66. @param[in] Measurement A pointer to the Measurement record to test.
  67. @retval TRUE The measurement record is used for core.
  68. @retval FALSE The measurement record is NOT used for core.
  69. **/
  70. BOOLEAN
  71. IsCorePerf (
  72. IN MEASUREMENT_RECORD *Measurement
  73. );
  74. /**
  75. Get the file name portion of the Pdb File Name.
  76. The portion of the Pdb File Name between the last backslash and
  77. either a following period or the end of the string is converted
  78. to Unicode and copied into UnicodeBuffer. The name is truncated,
  79. if necessary, to ensure that UnicodeBuffer is not overrun.
  80. @param[in] PdbFileName Pdb file name.
  81. @param[out] UnicodeBuffer The resultant Unicode File Name.
  82. **/
  83. VOID
  84. DpGetShortPdbFileName (
  85. IN CHAR8 *PdbFileName,
  86. OUT CHAR16 *UnicodeBuffer
  87. );
  88. /**
  89. Get a human readable name for an image handle.
  90. The following methods will be tried orderly:
  91. 1. Image PDB
  92. 2. ComponentName2 protocol
  93. 3. FFS UI section
  94. 4. Image GUID
  95. 5. Image DevicePath
  96. 6. Unknown Driver Name
  97. @param[in] Handle
  98. @post The resulting Unicode name string is stored in the
  99. mGaugeString global array.
  100. **/
  101. VOID
  102. DpGetNameFromHandle (
  103. IN EFI_HANDLE Handle
  104. );
  105. /**
  106. Calculate the Duration in microseconds.
  107. Duration is multiplied by 1000, instead of Frequency being divided by 1000 or
  108. multiplying the result by 1000, in order to maintain precision. Since Duration is
  109. a 64-bit value, multiplying it by 1000 is unlikely to produce an overflow.
  110. The time is calculated as (Duration * 1000) / Timer_Frequency.
  111. @param[in] Duration The event duration in timer ticks.
  112. @return A 64-bit value which is the Elapsed time in microseconds.
  113. **/
  114. UINT64
  115. DurationInMicroSeconds (
  116. IN UINT64 Duration
  117. );
  118. /**
  119. Get index of Measurement Record's match in the CumData array.
  120. If the Measurement's Token value matches a Token in one of the CumData
  121. records, the index of the matching record is returned. The returned
  122. index is a signed value so that negative values can indicate that
  123. the Measurement didn't match any entry in the CumData array.
  124. @param[in] Measurement A pointer to a Measurement Record to match against the CumData array.
  125. @retval <0 Token is not in the CumData array.
  126. @retval >=0 Return value is the index into CumData where Token is found.
  127. **/
  128. INTN
  129. GetCumulativeItem (
  130. IN MEASUREMENT_RECORD *Measurement
  131. );
  132. /**
  133. Collect verbose statistics about the logged performance measurements.
  134. General Summary information for all Trace measurements is gathered and
  135. stored within the SummaryData structure. This information is both
  136. used internally by subsequent reporting functions, and displayed
  137. at the end of verbose reports.
  138. @pre The SummaryData and CumData structures must be initialized
  139. prior to calling this function.
  140. @post The SummaryData and CumData structures contain statistics for the
  141. current performance logs.
  142. @param[in, out] CustomCumulativeData The pointer to the custom cumulative data.
  143. **/
  144. VOID
  145. GatherStatistics (
  146. IN OUT PERF_CUM_DATA *CustomCumulativeData OPTIONAL
  147. );
  148. /**
  149. Gather and print ALL Trace Records.
  150. Displays all "interesting" Trace measurements in order.<BR>
  151. The number of records displayed is controlled by:
  152. - records with a duration less than mInterestThreshold microseconds are not displayed.
  153. - No more than Limit records are displayed. A Limit of zero will not limit the output.
  154. - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not
  155. displayed.
  156. @pre The mInterestThreshold global variable is set to the shortest duration to be printed.
  157. The mGaugeString and mUnicodeToken global arrays are used for temporary string storage.
  158. They must not be in use by a calling function.
  159. @param[in] Limit The number of records to print. Zero is ALL.
  160. @param[in] ExcludeFlag TRUE to exclude individual Cumulative items from display.
  161. @retval EFI_SUCCESS The operation was successful.
  162. @retval EFI_ABORTED The user aborts the operation.
  163. @return Others from a call to gBS->LocateHandleBuffer().
  164. **/
  165. EFI_STATUS
  166. DumpAllTrace (
  167. IN UINTN Limit,
  168. IN BOOLEAN ExcludeFlag
  169. );
  170. /**
  171. Gather and print Raw Trace Records.
  172. All Trace measurements with a duration greater than or equal to
  173. mInterestThreshold are printed without interpretation.
  174. The number of records displayed is controlled by:
  175. - records with a duration less than mInterestThreshold microseconds are not displayed.
  176. - No more than Limit records are displayed. A Limit of zero will not limit the output.
  177. - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not
  178. displayed.
  179. @pre The mInterestThreshold global variable is set to the shortest duration to be printed.
  180. @param[in] Limit The number of records to print. Zero is ALL.
  181. @param[in] ExcludeFlag TRUE to exclude individual Cumulative items from display.
  182. @retval EFI_SUCCESS The operation was successful.
  183. @retval EFI_ABORTED The user aborts the operation.
  184. **/
  185. EFI_STATUS
  186. DumpRawTrace (
  187. IN UINTN Limit,
  188. IN BOOLEAN ExcludeFlag
  189. );
  190. /**
  191. Gather and print Major Phase metrics.
  192. **/
  193. VOID
  194. ProcessPhases (
  195. VOID
  196. );
  197. /**
  198. Gather and print Handle data.
  199. @param[in] ExcludeFlag TRUE to exclude individual Cumulative items from display.
  200. @retval EFI_SUCCESS The operation was successful.
  201. @retval EFI_ABORTED The user aborts the operation.
  202. @return Others from a call to gBS->LocateHandleBuffer().
  203. **/
  204. EFI_STATUS
  205. ProcessHandles (
  206. IN BOOLEAN ExcludeFlag
  207. );
  208. /**
  209. Gather and print PEIM data.
  210. Only prints complete PEIM records
  211. @retval EFI_SUCCESS The operation was successful.
  212. @retval EFI_ABORTED The user aborts the operation.
  213. **/
  214. EFI_STATUS
  215. ProcessPeims (
  216. VOID
  217. );
  218. /**
  219. Gather and print global data.
  220. Strips out incomplete or "Execution Phase" records
  221. Only prints records where Handle is NULL
  222. Increment TIndex for every record, even skipped ones, so that we have an
  223. indication of every measurement record taken.
  224. @retval EFI_SUCCESS The operation was successful.
  225. @retval EFI_ABORTED The user aborts the operation.
  226. **/
  227. EFI_STATUS
  228. ProcessGlobal (
  229. VOID
  230. );
  231. /**
  232. Gather and print cumulative data.
  233. Traverse the measurement records and:<BR>
  234. For each record with a Token listed in the CumData array:<BR>
  235. - Update the instance count and the total, minimum, and maximum durations.
  236. Finally, print the gathered cumulative statistics.
  237. @param[in] CustomCumulativeData The pointer to the custom cumulative data.
  238. **/
  239. VOID
  240. ProcessCumulative (
  241. IN PERF_CUM_DATA *CustomCumulativeData OPTIONAL
  242. );
  243. #endif