Home | History | Annotate | Download | only in Dp_App
      1 /** @file
      2   Declarations of objects defined internally to the Dp Application.
      3 
      4   Declarations of data and functions which are private to the Dp application.
      5   This file should never be referenced by anything other than components of the
      6   Dp application.  In addition to global data, function declarations for
      7   DpUtilities.c, DpTrace.c, and DpProfile.c are included here.
      8 
      9   Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
     10   (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>
     11   This program and the accompanying materials
     12   are licensed and made available under the terms and conditions of the BSD License
     13   which accompanies this distribution.  The full text of the license may be found at
     14   http://opensource.org/licenses/bsd-license.php
     15 
     16   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     17   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     18 **/
     19 #ifndef _DP_INTELNAL_H_
     20 #define _DP_INTELNAL_H_
     21 
     22 #define DP_GAUGE_STRING_LENGTH   36
     23 
     24 //
     25 /// Module-Global Variables
     26 ///@{
     27 extern EFI_HII_HANDLE     gHiiHandle;
     28 extern CHAR16             *mPrintTokenBuffer;
     29 extern CHAR16             mGaugeString[DP_GAUGE_STRING_LENGTH + 1];
     30 extern CHAR16             mUnicodeToken[DXE_PERFORMANCE_STRING_SIZE];
     31 extern UINT64             mInterestThreshold;
     32 extern BOOLEAN            mShowId;
     33 
     34 extern PERF_SUMMARY_DATA  SummaryData;    ///< Create the SummaryData structure and init. to ZERO.
     35 
     36 /// Timer Specific Information.
     37 extern TIMER_INFO         TimerInfo;
     38 
     39 /// Items for which to gather cumulative statistics.
     40 extern PERF_CUM_DATA      CumData[];
     41 
     42 /// Number of items for which we are gathering cumulative statistics.
     43 extern UINT32 const       NumCum;
     44 
     45 ///@}
     46 
     47 /**
     48   Calculate an event's duration in timer ticks.
     49 
     50   Given the count direction and the event's start and end timer values,
     51   calculate the duration of the event in timer ticks.  Information for
     52   the current measurement is pointed to by the parameter.
     53 
     54   If the measurement's start time is 1, it indicates that the developer
     55   is indicating that the measurement began at the release of reset.
     56   The start time is adjusted to the timer's starting count before performing
     57   the elapsed time calculation.
     58 
     59   The calculated duration, in ticks, is the absolute difference between
     60   the measurement's ending and starting counts.
     61 
     62   @param Measurement   Pointer to a MEASUREMENT_RECORD structure containing
     63                        data for the current measurement.
     64 
     65   @return              The 64-bit duration of the event.
     66 **/
     67 UINT64
     68 GetDuration (
     69   IN OUT MEASUREMENT_RECORD *Measurement
     70   );
     71 
     72 /**
     73   Determine whether the Measurement record is for an EFI Phase.
     74 
     75   The Token and Module members of the measurement record are checked.
     76   Module must be empty and Token must be one of SEC, PEI, DXE, BDS, or SHELL.
     77 
     78   @param[in]  Measurement A pointer to the Measurement record to test.
     79 
     80   @retval     TRUE        The measurement record is for an EFI Phase.
     81   @retval     FALSE       The measurement record is NOT for an EFI Phase.
     82 **/
     83 BOOLEAN
     84 IsPhase(
     85   IN MEASUREMENT_RECORD *Measurement
     86   );
     87 
     88 /**
     89   Get the file name portion of the Pdb File Name.
     90 
     91   The portion of the Pdb File Name between the last backslash and
     92   either a following period or the end of the string is converted
     93   to Unicode and copied into UnicodeBuffer.  The name is truncated,
     94   if necessary, to ensure that UnicodeBuffer is not overrun.
     95 
     96   @param[in]  PdbFileName     Pdb file name.
     97   @param[out] UnicodeBuffer   The resultant Unicode File Name.
     98 
     99 **/
    100 VOID
    101 GetShortPdbFileName (
    102   IN  CHAR8     *PdbFileName,
    103   OUT CHAR16    *UnicodeBuffer
    104   );
    105 
    106 /**
    107   Get a human readable name for an image handle.
    108   The following methods will be tried orderly:
    109     1. Image PDB
    110     2. ComponentName2 protocol
    111     3. FFS UI section
    112     4. Image GUID
    113     5. Image DevicePath
    114     6. Unknown Driver Name
    115 
    116   @param[in]    Handle
    117 
    118   @post   The resulting Unicode name string is stored in the
    119           mGaugeString global array.
    120 
    121 **/
    122 VOID
    123 GetNameFromHandle (
    124   IN EFI_HANDLE Handle
    125   );
    126 
    127 /**
    128   Calculate the Duration in microseconds.
    129 
    130   Duration is multiplied by 1000, instead of Frequency being divided by 1000 or
    131   multiplying the result by 1000, in order to maintain precision.  Since Duration is
    132   a 64-bit value, multiplying it by 1000 is unlikely to produce an overflow.
    133 
    134   The time is calculated as (Duration * 1000) / Timer_Frequency.
    135 
    136   @param[in]  Duration   The event duration in timer ticks.
    137 
    138   @return     A 64-bit value which is the Elapsed time in microseconds.
    139 **/
    140 UINT64
    141 DurationInMicroSeconds (
    142   IN UINT64 Duration
    143   );
    144 
    145 /**
    146   Formatted Print using a Hii Token to reference the localized format string.
    147 
    148   @param[in]  Token   A HII token associated with a localized Unicode string.
    149   @param[in]  ...     The variable argument list.
    150 
    151   @return             The number of characters converted by UnicodeVSPrint().
    152 
    153 **/
    154 UINTN
    155 EFIAPI
    156 PrintToken (
    157   IN UINT16 Token,
    158   ...
    159   );
    160 
    161 /**
    162   Get index of Measurement Record's match in the CumData array.
    163 
    164   If the Measurement's Token value matches a Token in one of the CumData
    165   records, the index of the matching record is returned.  The returned
    166   index is a signed value so that negative values can indicate that
    167   the Measurement didn't match any entry in the CumData array.
    168 
    169   @param[in]  Measurement A pointer to a Measurement Record to match against the CumData array.
    170 
    171   @retval     <0    Token is not in the CumData array.
    172   @retval     >=0   Return value is the index into CumData where Token is found.
    173 **/
    174 INTN
    175 GetCumulativeItem(
    176   IN MEASUREMENT_RECORD *Measurement
    177   );
    178 
    179 /**
    180   Collect verbose statistics about the logged performance measurements.
    181 
    182   General Summary information for all Trace measurements is gathered and
    183   stored within the SummaryData structure.  This information is both
    184   used internally by subsequent reporting functions, and displayed
    185   at the end of verbose reports.
    186 
    187   @pre  The SummaryData and CumData structures must be initialized
    188         prior to calling this function.
    189 
    190   @post The SummaryData and CumData structures contain statistics for the
    191         current performance logs.
    192 
    193   @param[in, out] CustomCumulativeData  The pointer to the custom cumulative data.
    194 
    195 **/
    196 VOID
    197 GatherStatistics(
    198   IN OUT PERF_CUM_DATA              *CustomCumulativeData OPTIONAL
    199   );
    200 
    201 /**
    202   Gather and print ALL Trace Records.
    203 
    204   Displays all "interesting" Trace measurements in order.<BR>
    205   The number of records displayed is controlled by:
    206      - records with a duration less than mInterestThreshold microseconds are not displayed.
    207      - No more than Limit records are displayed.  A Limit of zero will not limit the output.
    208      - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not
    209        displayed.
    210 
    211   @pre    The mInterestThreshold global variable is set to the shortest duration to be printed.
    212            The mGaugeString and mUnicodeToken global arrays are used for temporary string storage.
    213            They must not be in use by a calling function.
    214 
    215   @param[in]    Limit       The number of records to print.  Zero is ALL.
    216   @param[in]    ExcludeFlag TRUE to exclude individual Cumulative items from display.
    217 
    218   @retval EFI_SUCCESS           The operation was successful.
    219   @retval EFI_ABORTED           The user aborts the operation.
    220   @return Others                from a call to gBS->LocateHandleBuffer().
    221 **/
    222 EFI_STATUS
    223 DumpAllTrace(
    224   IN UINTN             Limit,
    225   IN BOOLEAN           ExcludeFlag
    226   );
    227 
    228 /**
    229   Gather and print Raw Trace Records.
    230 
    231   All Trace measurements with a duration greater than or equal to
    232   mInterestThreshold are printed without interpretation.
    233 
    234   The number of records displayed is controlled by:
    235      - records with a duration less than mInterestThreshold microseconds are not displayed.
    236      - No more than Limit records are displayed.  A Limit of zero will not limit the output.
    237      - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not
    238        displayed.
    239 
    240   @pre    The mInterestThreshold global variable is set to the shortest duration to be printed.
    241 
    242   @param[in]    Limit       The number of records to print.  Zero is ALL.
    243   @param[in]    ExcludeFlag TRUE to exclude individual Cumulative items from display.
    244 
    245   @retval EFI_SUCCESS           The operation was successful.
    246   @retval EFI_ABORTED           The user aborts the operation.
    247 **/
    248 EFI_STATUS
    249 DumpRawTrace(
    250   IN UINTN          Limit,
    251   IN BOOLEAN        ExcludeFlag
    252   );
    253 
    254 /**
    255   Gather and print Major Phase metrics.
    256 
    257   @param[in]    Ticker      The timer value for the END of Shell phase
    258 
    259 **/
    260 VOID
    261 ProcessPhases(
    262   IN UINT64 Ticker
    263   );
    264 
    265 
    266 /**
    267   Gather and print Handle data.
    268 
    269   @param[in]    ExcludeFlag   TRUE to exclude individual Cumulative items from display.
    270 
    271   @retval EFI_SUCCESS             The operation was successful.
    272   @retval EFI_ABORTED             The user aborts the operation.
    273   @return Others                  from a call to gBS->LocateHandleBuffer().
    274 **/
    275 EFI_STATUS
    276 ProcessHandles(
    277   IN BOOLEAN ExcludeFlag
    278   );
    279 
    280 
    281 /**
    282   Gather and print PEIM data.
    283 
    284   Only prints complete PEIM records
    285 
    286   @retval EFI_SUCCESS           The operation was successful.
    287   @retval EFI_ABORTED           The user aborts the operation.
    288 **/
    289 EFI_STATUS
    290 ProcessPeims(
    291   VOID
    292   );
    293 
    294 /**
    295   Gather and print global data.
    296 
    297   Strips out incomplete or "Execution Phase" records
    298   Only prints records where Handle is NULL
    299   Increment TIndex for every record, even skipped ones, so that we have an
    300   indication of every measurement record taken.
    301 
    302   @retval EFI_SUCCESS           The operation was successful.
    303   @retval EFI_ABORTED           The user aborts the operation.
    304 **/
    305 EFI_STATUS
    306 ProcessGlobal(
    307   VOID
    308   );
    309 
    310 /**
    311   Gather and print cumulative data.
    312 
    313   Traverse the measurement records and:<BR>
    314   For each record with a Token listed in the CumData array:<BR>
    315      - Update the instance count and the total, minimum, and maximum durations.
    316   Finally, print the gathered cumulative statistics.
    317 
    318   @param[in]    CustomCumulativeData  The pointer to the custom cumulative data.
    319 
    320 **/
    321 VOID
    322 ProcessCumulative(
    323   IN PERF_CUM_DATA                  *CustomCumulativeData OPTIONAL
    324   );
    325 
    326 /**
    327   Gather and print ALL Profiling Records.
    328 
    329   Displays all "interesting" Profile measurements in order.
    330   The number of records displayed is controlled by:
    331      - records with a duration less than mInterestThreshold microseconds are not displayed.
    332      - No more than Limit records are displayed.  A Limit of zero will not limit the output.
    333      - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not
    334        displayed.
    335 
    336   @pre    The mInterestThreshold global variable is set to the shortest duration to be printed.
    337            The mGaugeString and mUnicodeToken global arrays are used for temporary string storage.
    338            They must not be in use by a calling function.
    339 
    340   @param[in]    Limit         The number of records to print.  Zero is ALL.
    341   @param[in]    ExcludeFlag   TRUE to exclude individual Cumulative items from display.
    342 
    343 **/
    344 VOID
    345 DumpAllProfile(
    346   IN UINTN          Limit,
    347   IN BOOLEAN        ExcludeFlag
    348   );
    349 
    350 /**
    351   Gather and print Raw Profile Records.
    352 
    353   All Profile measurements with a duration greater than or equal to
    354   mInterestThreshold are printed without interpretation.
    355 
    356   The number of records displayed is controlled by:
    357      - records with a duration less than mInterestThreshold microseconds are not displayed.
    358      - No more than Limit records are displayed.  A Limit of zero will not limit the output.
    359      - If the ExcludeFlag is TRUE, records matching entries in the CumData array are not
    360        displayed.
    361 
    362   @pre    The mInterestThreshold global variable is set to the shortest duration to be printed.
    363 
    364   @param[in]    Limit         The number of records to print.  Zero is ALL.
    365   @param[in]    ExcludeFlag   TRUE to exclude individual Cumulative items from display.
    366 
    367 **/
    368 VOID
    369 DumpRawProfile(
    370   IN UINTN          Limit,
    371   IN BOOLEAN        ExcludeFlag
    372   );
    373 
    374 /**
    375   Wrap original FreePool to check NULL pointer first.
    376 
    377   @param[in]    Buffer      The pointer to the buffer to free.
    378 
    379 **/
    380 VOID
    381 SafeFreePool (
    382   IN VOID   *Buffer
    383   );
    384 
    385 #endif
    386