DpInternal.h 9.8 KB

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