home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples1.exe / Profiler / ProfilerHelper.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  56.9 KB  |  2,364 lines

  1. /****************************************************************************************
  2.  * Copyright (c) 1999 Microsoft Corporation.  All Rights Reserved.
  3.  *
  4.  * File:
  5.  *  ProfilerHelper.cpp
  6.  *
  7.  * Description:
  8.  *    
  9.  *
  10.  *
  11.  ***************************************************************************************/
  12. #include "ProfilerHelper.h"
  13.  
  14.  
  15. /***************************************************************************************
  16.  ********************                                               ********************
  17.  ********************             StackBaseInfo Implementation      ********************
  18.  ********************                                               ********************
  19.  ***************************************************************************************/
  20.  
  21. /***************************************************************************************
  22.  *    Method:
  23.  *
  24.  *
  25.  *    Purpose:
  26.  *
  27.  *
  28.  *    Parameters: 
  29.  *
  30.  *
  31.  *    Return value:
  32.  *
  33.  *
  34.  *    Notes:
  35.  *
  36.  ***************************************************************************************/
  37. /* public */
  38. StackBaseInfo::StackBaseInfo( ULONG id ) : 
  39.     m_id( id )
  40. {} // ctor                 
  41.  
  42.  
  43. /***************************************************************************************
  44.  *    Method:
  45.  *
  46.  *
  47.  *    Purpose:
  48.  *
  49.  *
  50.  *    Parameters: 
  51.  *
  52.  *
  53.  *    Return value:
  54.  *
  55.  *
  56.  *    Notes:
  57.  *
  58.  ***************************************************************************************/
  59. /* public virtual */
  60. StackBaseInfo::~StackBaseInfo()
  61. {} // dtor
  62.  
  63.  
  64. /***************************************************************************************
  65.  *    Method:
  66.  *
  67.  *
  68.  *    Purpose:
  69.  *
  70.  *
  71.  *    Parameters: 
  72.  *
  73.  *
  74.  *    Return value:
  75.  *
  76.  *
  77.  *    Notes:
  78.  *
  79.  ***************************************************************************************/
  80. /* public */
  81. StackBaseInfo *StackBaseInfo::Clone()
  82. {
  83.     return new StackBaseInfo( m_id );
  84.     
  85. } // BaseInfo::Clone
  86.  
  87.  
  88. /***************************************************************************************
  89.  *    Method:
  90.  *
  91.  *
  92.  *    Purpose:
  93.  *
  94.  *
  95.  *    Parameters: 
  96.  *
  97.  *
  98.  *    Return value:
  99.  *
  100.  *
  101.  *    Notes:
  102.  *
  103.  ***************************************************************************************/
  104. /* public */
  105. void StackBaseInfo::Dump()
  106. {
  107.     wprintf( L"\n" );
  108.     wprintf( L"STACKED ID: 0x%08x\n", m_id );
  109.     
  110. } // BaseInfo::Dump
  111.  
  112.  
  113. /***************************************************************************************
  114.  ********************                                               ********************
  115.  ********************             BaseInfo Implementation           ********************
  116.  ********************                                               ********************
  117.  ***************************************************************************************/
  118.  
  119. /***************************************************************************************
  120.  *    Method:
  121.  *
  122.  *
  123.  *    Purpose:
  124.  *
  125.  *
  126.  *    Parameters: 
  127.  *
  128.  *
  129.  *    Return value:
  130.  *
  131.  *
  132.  *    Notes:
  133.  *
  134.  ***************************************************************************************/
  135. /* public */
  136. BaseInfo::BaseInfo( ULONG id ) : 
  137.     m_id( id ),
  138.     m_isValid( TRUE )
  139. {
  140.        wcscpy( m_name, L"UNKNOWN" );     
  141.  
  142. } // ctor                 
  143.  
  144.  
  145. /***************************************************************************************
  146.  *    Method:
  147.  *
  148.  *
  149.  *    Purpose:
  150.  *
  151.  *
  152.  *    Parameters: 
  153.  *
  154.  *
  155.  *    Return value:
  156.  *
  157.  *
  158.  *    Notes:
  159.  *
  160.  ***************************************************************************************/
  161. /* public virtual */
  162. BaseInfo::~BaseInfo()
  163. {} // dtor
  164.  
  165.  
  166. /***************************************************************************************
  167.  *    Method:
  168.  *
  169.  *
  170.  *    Purpose:
  171.  *
  172.  *
  173.  *    Parameters: 
  174.  *
  175.  *
  176.  *    Return value:
  177.  *
  178.  *
  179.  *    Notes:
  180.  *
  181.  ***************************************************************************************/
  182. /* public */
  183. BOOL BaseInfo::Compare( ULONG key )
  184. {
  185.     return (BOOL)(m_id == key);
  186.  
  187. } // BaseInfo::Compare
  188.  
  189.  
  190. /***************************************************************************************
  191.  *    Method:
  192.  *
  193.  *
  194.  *    Purpose:
  195.  *
  196.  *
  197.  *    Parameters: 
  198.  *
  199.  *
  200.  *    Return value:
  201.  *
  202.  *
  203.  *    Notes:
  204.  *
  205.  ***************************************************************************************/
  206. /* public */
  207. void BaseInfo::Dump( )
  208. {
  209.     wprintf( L"\n" );
  210.     wprintf( L"ID: 0x%08x\n", m_id );
  211.     wprintf( L"\n" );
  212.  
  213. } // BaseInfo::Dump
  214.  
  215.  
  216. /***************************************************************************************
  217.  ********************                                               ********************
  218.  ********************           AppDomainInfo Implementation        ********************
  219.  ********************                                               ********************
  220.  ***************************************************************************************/
  221.  
  222. /***************************************************************************************
  223.  *    Method:
  224.  *
  225.  *
  226.  *    Purpose:
  227.  *
  228.  *
  229.  *    Parameters: 
  230.  *
  231.  *
  232.  *    Return value:
  233.  *
  234.  *
  235.  *    Notes:
  236.  *
  237.  ***************************************************************************************/
  238. /* public */
  239. AppDomainInfo::AppDomainInfo( AppDomainID appDomainID ) : 
  240.     BaseInfo( appDomainID ),            
  241.     m_processID( 0 )
  242.  
  243. {} // ctor                 
  244.  
  245.  
  246. /***************************************************************************************
  247.  *    Method:
  248.  *
  249.  *
  250.  *    Purpose:
  251.  *
  252.  *
  253.  *    Parameters: 
  254.  *
  255.  *
  256.  *    Return value:
  257.  *
  258.  *
  259.  *    Notes:
  260.  *
  261.  ***************************************************************************************/
  262. /* public virtual */
  263. AppDomainInfo::~AppDomainInfo()
  264. {} // dtor
  265.         
  266.  
  267. /***************************************************************************************
  268.  *    Method:
  269.  *
  270.  *
  271.  *    Purpose:
  272.  *
  273.  *
  274.  *    Parameters: 
  275.  *
  276.  *
  277.  *    Return value:
  278.  *
  279.  *
  280.  *    Notes:
  281.  *
  282.  ***************************************************************************************/
  283. /* public */
  284. void AppDomainInfo::Dump()
  285. {
  286.     wprintf( L"\n" );
  287.     wprintf( L"APPDOMAIN ID: 0x%08x\n", m_id );
  288.     wprintf( L"\tNAME: %s\n", m_name );
  289.     wprintf( L"\tPROCESS ID: 0x%08x\n", m_processID );
  290.     wprintf( L"\n" );
  291.         
  292. } // AppDomainInfo::Dump
  293.  
  294. /***************************************************************************************
  295.  ********************                                               ********************
  296.  ********************           AssemblyInfo Implementation        ********************
  297.  ********************                                               ********************
  298.  ***************************************************************************************/
  299.  
  300. /***************************************************************************************
  301.  *    Method:
  302.  *
  303.  *
  304.  *    Purpose:
  305.  *
  306.  *
  307.  *    Parameters: 
  308.  *
  309.  *
  310.  *    Return value:
  311.  *
  312.  *
  313.  *    Notes:
  314.  *
  315.  ***************************************************************************************/
  316. /* public */
  317. AssemblyInfo::AssemblyInfo( AssemblyID assemblyID ) : 
  318.     BaseInfo( assemblyID ),            
  319.     m_moduleID( 0 ),
  320.     m_appDomainID( 0 )
  321. {} // ctor                 
  322.  
  323.  
  324. /***************************************************************************************
  325.  *    Method:
  326.  *
  327.  *
  328.  *    Purpose:
  329.  *
  330.  *
  331.  *    Parameters: 
  332.  *
  333.  *
  334.  *    Return value:
  335.  *
  336.  *
  337.  *    Notes:
  338.  *
  339.  ***************************************************************************************/
  340. /* public virtual */
  341. AssemblyInfo::~AssemblyInfo()
  342. {} // dtor
  343.         
  344.  
  345. /***************************************************************************************
  346.  *    Method:
  347.  *
  348.  *
  349.  *    Purpose:
  350.  *
  351.  *
  352.  *    Parameters: 
  353.  *
  354.  *
  355.  *    Return value:
  356.  *
  357.  *
  358.  *    Notes:
  359.  *
  360.  ***************************************************************************************/
  361. /* public */
  362. void AssemblyInfo::Dump()
  363. {
  364.     wprintf( L"\n" );
  365.     wprintf( L"ASSEMBLY ID: 0x%08x\n", m_id );
  366.     wprintf( L"\tNAME: %s\n", m_name );
  367.     wprintf( L"\tMODULE ID: 0x%08x\n", m_moduleID );
  368.     wprintf( L"\tAPPDOMAIN ID: 0x%08x\n", m_appDomainID );
  369.     wprintf( L"\n" );
  370.         
  371. } // AssemblyInfo::Dump
  372.  
  373.  
  374. /***************************************************************************************
  375.  ********************                                               ********************
  376.  ********************           ModuleInfo Implementation           ********************
  377.  ********************                                               ********************
  378.  ***************************************************************************************/
  379.  
  380. /***************************************************************************************
  381.  *    Method:
  382.  *
  383.  *
  384.  *    Purpose:
  385.  *
  386.  *
  387.  *    Parameters: 
  388.  *
  389.  *
  390.  *    Return value:
  391.  *
  392.  *
  393.  *    Notes:
  394.  *
  395.  ***************************************************************************************/
  396. /* public */
  397. ModuleInfo::ModuleInfo( ModuleID moduleID ) : 
  398.     BaseInfo( moduleID ),    
  399.     m_pMDImport( NULL ),
  400.     m_assemblyID( NULL ),        
  401.     m_pBaseLoadAddress( NULL )
  402. {} // ctor                 
  403.  
  404.  
  405. /***************************************************************************************
  406.  *    Method:
  407.  *
  408.  *
  409.  *    Purpose:
  410.  *
  411.  *
  412.  *    Parameters: 
  413.  *
  414.  *
  415.  *    Return value:
  416.  *
  417.  *
  418.  *    Notes:
  419.  *
  420.  ***************************************************************************************/
  421. /* public virtual */
  422. ModuleInfo::~ModuleInfo()
  423. {
  424.     if ( m_pMDImport !=  NULL )
  425.     {
  426.         m_pMDImport->Release();
  427.         m_pMDImport = NULL;
  428.     }
  429.  
  430. } // dtor
  431.         
  432.  
  433. /***************************************************************************************
  434.  *    Method:
  435.  *
  436.  *
  437.  *    Purpose:
  438.  *
  439.  *
  440.  *    Parameters: 
  441.  *
  442.  *
  443.  *    Return value:
  444.  *
  445.  *
  446.  *    Notes:
  447.  *
  448.  ***************************************************************************************/
  449. /* public */
  450. void ModuleInfo::Dump()
  451. {
  452.     wprintf( L"\n" );
  453.     wprintf( L"MODULE ID: 0x%08x\n", m_id );
  454.     wprintf( L"\tNAME: %s\n", m_name );
  455.     wprintf( L"\tASSEMBLY ID: 0x%08x\n", m_assemblyID );
  456.     wprintf( L"\tBASE ADDRESS: 0x%08x\n", m_pBaseLoadAddress );
  457.     wprintf( L"\n" );
  458.  
  459. } // ModuleInfo::Dump
  460.  
  461.  
  462. /***************************************************************************************
  463.  ********************                                               ********************
  464.  ********************            ClassInfo Implementation           ********************
  465.  ********************                                               ********************
  466.  ***************************************************************************************/
  467.  
  468. /***************************************************************************************
  469.  *    Method:
  470.  *
  471.  *
  472.  *    Purpose:
  473.  *
  474.  *
  475.  *    Parameters: 
  476.  *
  477.  *
  478.  *    Return value:
  479.  *
  480.  *
  481.  *    Notes:
  482.  *
  483.  ***************************************************************************************/
  484. /* public */
  485. ClassInfo::ClassInfo( ClassID classID ) : 
  486.     BaseInfo( classID ),
  487.     m_moduleID( 0 ),
  488.     m_token( mdTypeDefNil )
  489. {} // ctor                 
  490.  
  491.  
  492. /***************************************************************************************
  493.  *    Method:
  494.  *
  495.  *
  496.  *    Purpose:
  497.  *
  498.  *
  499.  *    Parameters: 
  500.  *
  501.  *
  502.  *    Return value:
  503.  *
  504.  *
  505.  *    Notes:
  506.  *
  507.  ***************************************************************************************/
  508. /* public virtual */
  509. ClassInfo::~ClassInfo()
  510. {} // dtor
  511.         
  512.  
  513. /***************************************************************************************
  514.  *    Method:
  515.  *
  516.  *
  517.  *    Purpose:
  518.  *
  519.  *
  520.  *    Parameters: 
  521.  *
  522.  *
  523.  *    Return value:
  524.  *
  525.  *
  526.  *    Notes:
  527.  *
  528.  ***************************************************************************************/
  529. /* public */
  530. void ClassInfo::Dump()
  531. {
  532.     wprintf( L"\n" );
  533.     wprintf( L"CLASS ID: 0x%08x\n", m_id );
  534.     wprintf( L"\tNAME: %s\n", m_name );
  535.     wprintf( L"\tTOKEN: 0x%08x\n", m_token );
  536.     wprintf( L"\tMODULE ID: 0x%08x\n", m_moduleID );
  537.     wprintf( L"\n" );
  538.  
  539. } // ClassInfo::Dump
  540.  
  541.  
  542. /***************************************************************************************
  543.  ********************                                               ********************
  544.  ********************            ThreadInfo Implementation          ********************
  545.  ********************                                               ********************
  546.  ***************************************************************************************/
  547.  
  548. /***************************************************************************************
  549.  *    Method:
  550.  *
  551.  *
  552.  *    Purpose:
  553.  *
  554.  *
  555.  *    Parameters: 
  556.  *
  557.  *
  558.  *    Return value:
  559.  *
  560.  *
  561.  *    Notes:
  562.  *
  563.  ***************************************************************************************/
  564. /* public */
  565. ThreadInfo::ThreadInfo( ThreadID threadID ) : 
  566.     BaseInfo( threadID ),        
  567.     m_hThread( NULL ), 
  568.     m_win32ThreadID( 0 ),
  569.     m_status( UNINITIALIZED )
  570. {
  571.        m_pLatestUnwoundFunction = new CStack<StackBaseInfo *>();
  572.     wcscpy( m_name, L"NOT-APPLICABLE" );     
  573.  
  574. } // ctor                 
  575.  
  576.  
  577. /***************************************************************************************
  578.  *    Method:
  579.  *
  580.  *
  581.  *    Purpose:
  582.  *
  583.  *
  584.  *    Parameters: 
  585.  *
  586.  *
  587.  *    Return value:
  588.  *
  589.  *
  590.  *    Notes:
  591.  *
  592.  ***************************************************************************************/
  593. /* public virtual */
  594. ThreadInfo::~ThreadInfo()
  595. {
  596.     if ( m_pLatestUnwoundFunction != NULL )
  597.     {
  598.         delete m_pLatestUnwoundFunction; 
  599.         m_pLatestUnwoundFunction = NULL;
  600.     }
  601.     
  602. } // dtor
  603.         
  604.  
  605. /***************************************************************************************
  606.  *    Method:
  607.  *
  608.  *
  609.  *    Purpose:
  610.  *
  611.  *
  612.  *    Parameters: 
  613.  *
  614.  *
  615.  *    Return value:
  616.  *
  617.  *
  618.  *    Notes:
  619.  *
  620.  ***************************************************************************************/
  621. /* public */
  622. void ThreadInfo::Dump()
  623. {    
  624.     wprintf( L"\n" );
  625.     wprintf( L"THREAD ID: 0x%08x\n", m_id );
  626.     wprintf( L"\tHANDLE: 0x%08x\n", m_hThread );
  627.     wprintf( L"\tWIN32 ID: 0x%08x\n", m_win32ThreadID );
  628.     wprintf( L"\n" );
  629.  
  630. } // ThreadInfo::Dump
  631.  
  632.  
  633. /***************************************************************************************
  634.  ********************                                               ********************
  635.  ********************          FunctionInfo Implementation          ********************
  636.  ********************                                               ********************
  637.  ***************************************************************************************/
  638.  
  639. /***************************************************************************************
  640.  *    Method:
  641.  *
  642.  *
  643.  *    Purpose:
  644.  *
  645.  *
  646.  *    Parameters: 
  647.  *
  648.  *
  649.  *    Return value:
  650.  *
  651.  *
  652.  *    Notes:
  653.  *
  654.  ***************************************************************************************/
  655. /* public */
  656. FunctionInfo::FunctionInfo( FunctionID functionID ) : 
  657.     BaseInfo( functionID ),        
  658.     m_left( 0 ),
  659.     m_tail( 0 ),
  660.     m_enter( 0 ),
  661.     m_unwind( 0 ),
  662.     m_jitStatus( NONE ),
  663.     m_isPitched( FALSE ),
  664.     m_classID( 0 ),
  665.     m_moduleID( 0 ),
  666.       m_codeSize( 0 ),        
  667.     m_token( mdTokenNil ),
  668.     m_pStartAddress( NULL )
  669. {} // ctor                 
  670.  
  671.  
  672. /***************************************************************************************
  673.  *    Method:
  674.  *
  675.  *
  676.  *    Purpose:
  677.  *
  678.  *
  679.  *    Parameters: 
  680.  *
  681.  *
  682.  *    Return value:
  683.  *
  684.  *
  685.  *    Notes:
  686.  *
  687.  ***************************************************************************************/
  688. /* public virtual */
  689. FunctionInfo::~FunctionInfo()
  690. {} // dtor
  691.         
  692.  
  693. /***************************************************************************************
  694.  *    Method:
  695.  *
  696.  *
  697.  *    Purpose:
  698.  *
  699.  *
  700.  *    Parameters: 
  701.  *
  702.  *
  703.  *    Return value:
  704.  *
  705.  *
  706.  *    Notes:
  707.  *
  708.  ***************************************************************************************/
  709. /* public */
  710. void FunctionInfo::Dump()
  711. {
  712.  
  713.     wprintf( L"\n" );
  714.     wprintf( L"FUNCTION ID: 0x%08x\n", m_id );
  715.     wprintf( L"\tNAME: %s\n", m_name );
  716.     wprintf( L"\tTOKEN: 0x%08x\n", m_token );
  717.     wprintf( L"\tCLASS ID: 0x%08x\n", m_classID );
  718.     wprintf( L"\tMODULE ID: 0x%08x\n", m_moduleID );
  719.     wprintf( L"\tCODE SIZE: %d bytes\n", m_codeSize );
  720.     wprintf( L"\tSTART ADDRESS: 0x%08x", m_pStartAddress );
  721.     wprintf( L"\n" );
  722.  
  723.     wprintf( L"\tDumping Enter-Leave event counters\n" );
  724.  
  725.     wprintf( L"\t\tEnter Counter:    %d\n",    m_enter );
  726.     wprintf( L"\t\tLeft Counter:     %d\n",    m_left );
  727.     wprintf( L"\t\tTailCall Counter: %d\n",    m_tail );
  728.     wprintf( L"\t\tUnwind Counter:   %d\n",    m_unwind );
  729.  
  730.     wprintf( L"\n" );
  731.                    
  732. } // FunctionInfo::Dump
  733.  
  734.  
  735. /***************************************************************************************
  736.  ********************                                               ********************
  737.  ********************              PrfInfo Implementation           ********************
  738.  ********************                                               ********************
  739.  ***************************************************************************************/
  740.  
  741. /***************************************************************************************
  742.  *    Method:
  743.  *
  744.  *
  745.  *    Purpose:
  746.  *
  747.  *
  748.  *    Parameters: 
  749.  *
  750.  *
  751.  *    Return value:
  752.  *
  753.  *
  754.  *    Notes:
  755.  *
  756.  ***************************************************************************************/
  757. /* public */
  758. PrfInfo::PrfInfo() :         
  759.     m_pProfilerInfo( NULL )
  760. {
  761.  
  762.     InitializeCriticalSection( &m_criticalSection );
  763.  
  764.     // initialize tables    
  765.     m_pClassTable = new SList<ClassInfo *, ClassID>();
  766.     m_pThreadTable = new SList<ThreadInfo *, ThreadID>();
  767.     m_pModuleTable = new SList<ModuleInfo *, ModuleID>();    
  768.     m_pFunctionTable = new SList<FunctionInfo *, FunctionID>();
  769.     m_pAssemblyTable = new SList<AssemblyInfo *, AssemblyID>();
  770.     m_pAppDomainTable = new SList<AppDomainInfo *, AppDomainID>();
  771.  
  772. } // ctor
  773.  
  774.  
  775. /***************************************************************************************
  776.  *    Method:
  777.  *
  778.  *
  779.  *    Purpose:
  780.  *
  781.  *
  782.  *    Parameters: 
  783.  *
  784.  *
  785.  *    Return value:
  786.  *
  787.  *
  788.  *    Notes:
  789.  *
  790.  ***************************************************************************************/
  791. /* virtual public */
  792. PrfInfo::~PrfInfo()
  793. {
  794.  
  795.     // release the ICorProfilerInfoInterface
  796.     if ( m_pProfilerInfo != NULL )
  797.     {
  798.         m_pProfilerInfo->Release();
  799.         m_pProfilerInfo = NULL;
  800.     }
  801.  
  802.        // clean up tables              
  803.     if ( m_pClassTable != NULL )
  804.            delete m_pClassTable;
  805.     
  806.     if ( m_pThreadTable != NULL )    
  807.         delete m_pThreadTable;
  808.     
  809.     if ( m_pModuleTable != NULL )    
  810.         delete m_pModuleTable;      
  811.               
  812.     if ( m_pFunctionTable != NULL )    
  813.         delete m_pFunctionTable;
  814.         
  815.       if ( m_pAppDomainTable != NULL )
  816.            delete m_pAppDomainTable;
  817.  
  818.        if ( m_pAssemblyTable != NULL )
  819.            delete m_pAssemblyTable;
  820.  
  821.       DeleteCriticalSection( &m_criticalSection );
  822.  
  823. } // dtor                  
  824.  
  825.  
  826. /***************************************************************************************
  827.  *    Method:
  828.  *
  829.  *
  830.  *    Purpose:
  831.  *
  832.  *
  833.  *    Parameters: 
  834.  *
  835.  *
  836.  *    Return value:
  837.  *
  838.  *
  839.  *    Notes:
  840.  *
  841.  ***************************************************************************************/
  842. /* public */
  843. /* throws BaseException */
  844. void PrfInfo::AddAppDomain( AppDomainID appDomainID )
  845. {    
  846.     AppDomainInfo *pAppDomainInfo;
  847.     
  848.     
  849.     pAppDomainInfo = m_pAppDomainTable->Lookup( appDomainID );
  850.     _ASSERT_( pAppDomainInfo == NULL);
  851.  
  852.     pAppDomainInfo = new AppDomainInfo( appDomainID );
  853.     if ( pAppDomainInfo != NULL )
  854.       {
  855.         try
  856.         {
  857.              _GetAppDomainInfoHelper( &pAppDomainInfo );
  858.             m_pAppDomainTable->AddEntry( pAppDomainInfo, appDomainID );    
  859.            }
  860.         catch ( BaseException *exception )
  861.         {
  862.             delete pAppDomainInfo;            
  863.             throw;                           
  864.         }
  865.        }
  866.     else
  867.         _THROW_EXCEPTION( "Allocation for AppDomainInfo Object FAILED" )
  868.         
  869. } // PrfInfo::AddAppDomain
  870.  
  871.  
  872. /***************************************************************************************
  873.  *    Method:
  874.  *
  875.  *
  876.  *    Purpose:
  877.  *
  878.  *
  879.  *    Parameters: 
  880.  *
  881.  *
  882.  *    Return value:
  883.  *
  884.  *
  885.  *    Notes:
  886.  *
  887.  ***************************************************************************************/
  888. /* public */
  889. /* throws BaseException */
  890. void PrfInfo::RemoveAppDomain( AppDomainID appDomainID )
  891. {    
  892.     if ( appDomainID != NULL )
  893.       {
  894.         AppDomainInfo *pAppDomainInfo;
  895.  
  896.         
  897.         pAppDomainInfo = m_pAppDomainTable->Lookup( appDomainID );
  898.         if ( pAppDomainInfo != NULL )
  899.         {
  900.             _ASSERT_( pAppDomainInfo->m_isValid == TRUE );
  901.             pAppDomainInfo->m_isValid = FALSE;
  902.         }
  903.         else
  904.             _THROW_EXCEPTION( "AppDomain was not found in the AppDomain Table" )
  905.     }
  906.     else
  907.         _THROW_EXCEPTION( "AppDomainID is NULL" )
  908.  
  909.  
  910. } // PrfInfo::RemoveAppDomain
  911.  
  912.  
  913. /***************************************************************************************
  914.  *    Method:
  915.  *
  916.  *
  917.  *    Purpose:
  918.  *
  919.  *
  920.  *    Parameters: 
  921.  *
  922.  *
  923.  *    Return value:
  924.  *
  925.  *
  926.  *    Notes:
  927.  *
  928.  ***************************************************************************************/
  929. /* public */
  930. /* throws BaseException */
  931. void PrfInfo::AddAssembly( AssemblyID assemblyID )
  932. {    
  933.     AssemblyInfo *pAssemblyInfo;
  934.     
  935.  
  936.     pAssemblyInfo = m_pAssemblyTable->Lookup( assemblyID );
  937.     _ASSERT_( pAssemblyInfo == NULL);
  938.  
  939.     pAssemblyInfo = new AssemblyInfo( assemblyID );
  940.     if ( pAssemblyInfo != NULL )
  941.       {
  942.         try
  943.         {
  944.             _GetAssemblyInfoHelper( &pAssemblyInfo );
  945.             m_pAssemblyTable->AddEntry( pAssemblyInfo, assemblyID );
  946.           }     
  947.         catch ( BaseException *exception )
  948.         {
  949.             delete pAssemblyInfo;
  950.                throw;            
  951.         }
  952.        }
  953.     else
  954.         _THROW_EXCEPTION( "Allocation for AssemblyInfo Object FAILED" )
  955.         
  956.         
  957. } // PrfInfo::AddAssembly
  958.  
  959.  
  960. /***************************************************************************************
  961.  *    Method:
  962.  *
  963.  *
  964.  *    Purpose:
  965.  *
  966.  *
  967.  *    Parameters: 
  968.  *
  969.  *
  970.  *    Return value:
  971.  *
  972.  *
  973.  *    Notes:
  974.  *
  975.  ***************************************************************************************/
  976. /* public */
  977. /* throws BaseException */
  978. void PrfInfo::RemoveAssembly( AssemblyID assemblyID )
  979. {    
  980.     if ( assemblyID != NULL )
  981.       {
  982.         AssemblyInfo *pAssemblyInfo;
  983.  
  984.         
  985.         pAssemblyInfo = m_pAssemblyTable->Lookup( assemblyID );
  986.         if ( pAssemblyInfo != NULL )
  987.         {
  988.             _ASSERT_( pAssemblyInfo->m_isValid == TRUE );
  989.             pAssemblyInfo->m_isValid = FALSE;
  990.         }
  991.         else
  992.             _THROW_EXCEPTION( "Assembly was not found in the Assembly Table" )
  993.     }
  994.     else
  995.         _THROW_EXCEPTION( "AssemblyID is NULL" )
  996.  
  997.  
  998. } // PrfInfo::RemoveAssembly
  999.  
  1000.  
  1001. /***************************************************************************************
  1002.  *    Method:
  1003.  *
  1004.  *
  1005.  *    Purpose:
  1006.  *
  1007.  *
  1008.  *    Parameters: 
  1009.  *
  1010.  *
  1011.  *    Return value:
  1012.  *
  1013.  *
  1014.  *    Notes:
  1015.  *
  1016.  ***************************************************************************************/
  1017. /* public */
  1018. /* throws BaseException */
  1019. void PrfInfo::AddModule( ModuleID moduleID )
  1020. {    
  1021.     ModuleInfo *pModuleInfo;
  1022.     
  1023.  
  1024.     pModuleInfo = m_pModuleTable->Lookup( moduleID );
  1025.     _ASSERT_( pModuleInfo == NULL);
  1026.  
  1027.     pModuleInfo = new ModuleInfo( moduleID );
  1028.     if ( pModuleInfo != NULL )
  1029.       {
  1030.         try
  1031.         {      
  1032.             _GetModuleInfoHelper( &pModuleInfo );
  1033.             m_pModuleTable->AddEntry( pModuleInfo, moduleID );    
  1034.            }
  1035.         catch ( BaseException *exception )
  1036.         {    
  1037.             delete pModuleInfo;
  1038.             throw;    
  1039.         }
  1040.        }
  1041.     else
  1042.         _THROW_EXCEPTION( "Allocation for ModuleInfo Object FAILED" )
  1043.         
  1044.         
  1045. } // PrfInfo::AddModule
  1046.  
  1047.  
  1048. /***************************************************************************************
  1049.  *    Method:
  1050.  *
  1051.  *
  1052.  *    Purpose:
  1053.  *
  1054.  *
  1055.  *    Parameters: 
  1056.  *
  1057.  *
  1058.  *    Return value:
  1059.  *
  1060.  *
  1061.  *    Notes:
  1062.  *
  1063.  ***************************************************************************************/
  1064. /* public */
  1065. /* throws BaseException */
  1066. void PrfInfo::RemoveModule( ModuleID moduleID )
  1067. {    
  1068.     if ( moduleID != NULL )
  1069.       {
  1070.         ModuleInfo *pModuleInfo;
  1071.  
  1072.         
  1073.         pModuleInfo = m_pModuleTable->Lookup( moduleID );
  1074.         if ( pModuleInfo != NULL )
  1075.         {
  1076.             _ASSERT_( pModuleInfo->m_isValid == TRUE );
  1077.             pModuleInfo->m_isValid = FALSE;
  1078.         }
  1079.         else
  1080.             _THROW_EXCEPTION( "Module was not found in the Module Table" )
  1081.     }
  1082.     else
  1083.         _THROW_EXCEPTION( "ModuleID is NULL" )
  1084.                 
  1085.         
  1086. } // PrfInfo::RemoveModule
  1087.  
  1088.  
  1089. /***************************************************************************************
  1090.  *    Method:
  1091.  *
  1092.  *
  1093.  *    Purpose:
  1094.  *
  1095.  *
  1096.  *    Parameters: 
  1097.  *
  1098.  *
  1099.  *    Return value:
  1100.  *
  1101.  *
  1102.  *    Notes:
  1103.  *
  1104.  ***************************************************************************************/
  1105. /* public */
  1106. void PrfInfo::ReleaseModuleMDInterface( ModuleID moduleID )
  1107. {
  1108.       ModuleInfo *pModuleInfo;
  1109.             
  1110.     
  1111.     // release the MetaData interface for the module here...        
  1112.       pModuleInfo = m_pModuleTable->Lookup( moduleID );
  1113.        if ( (pModuleInfo != NULL) && (pModuleInfo->m_pMDImport != NULL) )
  1114.         pModuleInfo->m_pMDImport->Release();
  1115.           
  1116. } // PrfInfo::ReleaseModuleMDInterface
  1117.  
  1118.  
  1119. /***************************************************************************************
  1120.  *    Method:
  1121.  *
  1122.  *
  1123.  *    Purpose:
  1124.  *
  1125.  *
  1126.  *    Parameters: 
  1127.  *
  1128.  *
  1129.  *    Return value:
  1130.  *
  1131.  *
  1132.  *    Notes:
  1133.  *
  1134.  ***************************************************************************************/
  1135. /* public */
  1136. void PrfInfo::UpdateAssemblyInModule( ModuleID moduleID, AssemblyID assemblyID )
  1137. {
  1138.       ModuleInfo *pModuleInfo;
  1139.             
  1140.     
  1141.     //
  1142.     // Update the Assembly for the module here...        
  1143.       //
  1144.       pModuleInfo = m_pModuleTable->Lookup( moduleID );
  1145.     if ( pModuleInfo != NULL )
  1146.     {
  1147.         _ASSERT_( pModuleInfo->m_isValid == TRUE );
  1148.         if ( assemblyID != PROFILER_PARENT_UNKNOWN )
  1149.             pModuleInfo->m_assemblyID = assemblyID;
  1150.         
  1151.         else
  1152.             _THROW_EXCEPTION( "Assembly ID Not Valid - Unable to Update Profiler Tables" )        
  1153.     }
  1154.     else
  1155.         _THROW_EXCEPTION( "Module Does Not Exist In Profiler Tables" )        
  1156.  
  1157.           
  1158. } // PrfInfo::UpdateAssemblyInModule
  1159.  
  1160.  
  1161. /***************************************************************************************
  1162.  *    Method:
  1163.  *
  1164.  *
  1165.  *    Purpose:
  1166.  *
  1167.  *
  1168.  *    Parameters: 
  1169.  *
  1170.  *
  1171.  *    Return value:
  1172.  *
  1173.  *
  1174.  *    Notes:
  1175.  *
  1176.  ***************************************************************************************/
  1177. /* public */
  1178. /* throws BaseException */
  1179. void PrfInfo::AddClass( ClassID classID )
  1180. {    
  1181.     ClassInfo *pClassInfo;
  1182.     
  1183.  
  1184.     pClassInfo = m_pClassTable->Lookup( classID );
  1185.     _ASSERT_( pClassInfo == NULL);
  1186.  
  1187.     pClassInfo = new ClassInfo( classID );
  1188.     if ( pClassInfo != NULL )
  1189.       {
  1190.         try
  1191.         {
  1192.             _GetClassInfoHelper( &pClassInfo );                                                                                                                                             
  1193.             m_pClassTable->AddEntry( pClassInfo, classID ); 
  1194.         }
  1195.         catch ( BaseException *exception )                     
  1196.         {
  1197.             delete pClassInfo;
  1198.             throw;               
  1199.           }
  1200.        }
  1201.     else
  1202.         _THROW_EXCEPTION( "Allocation for ClassInfo Object FAILED" )
  1203.         
  1204.         
  1205. } // PrfInfo::AddClass
  1206.  
  1207.  
  1208. /***************************************************************************************
  1209.  *    Method:
  1210.  *
  1211.  *
  1212.  *    Purpose:
  1213.  *
  1214.  *
  1215.  *    Parameters: 
  1216.  *
  1217.  *
  1218.  *    Return value:
  1219.  *
  1220.  *
  1221.  *    Notes:
  1222.  *
  1223.  ***************************************************************************************/
  1224. /* public */
  1225. /* throws BaseException */
  1226. void PrfInfo::RemoveClass( ClassID classID )
  1227. {    
  1228.     if ( classID != NULL )
  1229.       {
  1230.         ClassInfo *pClassInfo;
  1231.  
  1232.         
  1233.         pClassInfo = m_pClassTable->Lookup( classID );
  1234.         if ( pClassInfo != NULL )
  1235.         {
  1236.             _ASSERT_( pClassInfo->m_isValid == TRUE );
  1237.             pClassInfo->m_isValid = FALSE;
  1238.         }
  1239.         else
  1240.             _THROW_EXCEPTION( "Class was not found in the Class Table" )
  1241.     }
  1242.     else
  1243.         _THROW_EXCEPTION( "ClassID is NULL" )
  1244.  
  1245.  
  1246. } // PrfInfo::RemoveClass
  1247.  
  1248.  
  1249. /***************************************************************************************
  1250.  *    Method:
  1251.  *
  1252.  *
  1253.  *    Purpose:
  1254.  *
  1255.  *
  1256.  *    Parameters: 
  1257.  *
  1258.  *
  1259.  *    Return value:
  1260.  *
  1261.  *
  1262.  *    Notes:
  1263.  *
  1264.  ***************************************************************************************/
  1265. /* public */
  1266. /* throws BaseException */
  1267. void PrfInfo::AddThread( ThreadID threadID )
  1268. {    
  1269.        ///////////////////////////////////////////////////////////////////////////
  1270.     Synchronize guard( m_criticalSection );
  1271.     ///////////////////////////////////////////////////////////////////////////
  1272.  
  1273.     HRESULT hr;
  1274.     ThreadID myThreadID;
  1275.  
  1276.     hr = m_pProfilerInfo->GetCurrentThreadID( &myThreadID );
  1277.     
  1278.     if ( SUCCEEDED( hr ) )
  1279.     {
  1280.         
  1281.         if ( threadID == myThreadID )
  1282.         {
  1283.             ThreadInfo *pThreadInfo;
  1284.             
  1285.             pThreadInfo = new ThreadInfo( threadID );
  1286.             if ( pThreadInfo != NULL )
  1287.               {
  1288.                 try
  1289.                 {
  1290.                     _GetThreadInfoHelper( &pThreadInfo );
  1291.                     m_pThreadTable->AddEntry( pThreadInfo, threadID );
  1292.                    }
  1293.                 catch ( BaseException *exception )
  1294.                 {
  1295.                     delete pThreadInfo;
  1296.                     throw;                 
  1297.                  }                    
  1298.             }
  1299.             else
  1300.                 _THROW_EXCEPTION( "Allocation for ThreadInfo Object FAILED" )
  1301.         }
  1302.         else
  1303.             _THROW_EXCEPTION( "Thread ID's do not match FAILED" )
  1304.     }
  1305.     else
  1306.         _THROW_EXCEPTION( "ICorProfilerInfo::GetCurrentThreadID() FAILED" )
  1307.                 
  1308. } // PrfInfo::AddThread
  1309.  
  1310.  
  1311. /***************************************************************************************
  1312.  *    Method:
  1313.  *
  1314.  *
  1315.  *    Purpose:
  1316.  *
  1317.  *
  1318.  *    Parameters: 
  1319.  *
  1320.  *
  1321.  *    Return value:
  1322.  *
  1323.  *
  1324.  *    Notes:
  1325.  *
  1326.  ***************************************************************************************/
  1327. /* public */
  1328. /* throws BaseException */
  1329. void PrfInfo::RemoveThread( ThreadID threadID )
  1330. {    
  1331.        ///////////////////////////////////////////////////////////////////////////
  1332.     Synchronize guard( m_criticalSection );
  1333.     ///////////////////////////////////////////////////////////////////////////
  1334.     
  1335.     if ( threadID != NULL )
  1336.       {
  1337.         ThreadInfo *pThreadInfo;
  1338.  
  1339.         
  1340.         pThreadInfo = m_pThreadTable->Lookup( threadID );
  1341.         if ( pThreadInfo != NULL )
  1342.         {
  1343.             _ASSERT_( pThreadInfo->m_isValid == TRUE );
  1344.             pThreadInfo->m_isValid = FALSE;
  1345.         }
  1346.         else
  1347.             _THROW_EXCEPTION( "Thread was not found in the Thread Table" )
  1348.     }
  1349.     else
  1350.         _THROW_EXCEPTION( "ThreadID is NULL" )
  1351.                 
  1352.         
  1353. } // PrfInfo::RemoveThread
  1354.  
  1355.  
  1356. /***************************************************************************************
  1357.  *    Method:
  1358.  *
  1359.  *
  1360.  *    Purpose:
  1361.  *
  1362.  *
  1363.  *    Parameters: 
  1364.  *
  1365.  *
  1366.  *    Return value:
  1367.  *
  1368.  *
  1369.  *    Notes:
  1370.  *
  1371.  ***************************************************************************************/
  1372. /* public */
  1373. /* throws BaseException */
  1374. void PrfInfo::UpdateTransitionState( TransitionState state )
  1375. {
  1376.        ///////////////////////////////////////////////////////////////////////////
  1377.     Synchronize guard( m_criticalSection );
  1378.     ///////////////////////////////////////////////////////////////////////////
  1379.  
  1380.     HRESULT hr;
  1381.     ThreadID threadID;
  1382.  
  1383.  
  1384.     hr = m_pProfilerInfo->GetCurrentThreadID( &threadID );
  1385.     if ( SUCCEEDED(hr) )
  1386.     {
  1387.         ThreadInfo *pThreadInfo = m_pThreadTable->Lookup( threadID );
  1388.  
  1389.  
  1390.         if ( pThreadInfo != NULL )
  1391.         {
  1392.             _ASSERT_( pThreadInfo->m_isValid == TRUE );
  1393.              pThreadInfo->m_status = state;
  1394.         
  1395.         }
  1396.         else                 
  1397.             _THROW_EXCEPTION( "Thread Structure was not found in the thread list" )
  1398.     }
  1399.     else
  1400.         _THROW_EXCEPTION( "ICorProfilerInfo::GetCurrentThreadID() FAILED" )
  1401.  
  1402.     
  1403. } // PrfInfo::UpdateTransitionState
  1404.  
  1405.  
  1406. /***************************************************************************************
  1407.  *    Method:
  1408.  *
  1409.  *
  1410.  *    Purpose:
  1411.  *
  1412.  *
  1413.  *    Parameters: 
  1414.  *
  1415.  *
  1416.  *    Return value:
  1417.  *
  1418.  *
  1419.  *    Notes:
  1420.  *
  1421.  ***************************************************************************************/
  1422. /* public */
  1423. /* throws BaseException */
  1424. void PrfInfo::UpdateOSThreadID( ThreadID managedThreadID, DWORD win32ThreadID )
  1425. {
  1426.        ///////////////////////////////////////////////////////////////////////////
  1427.     Synchronize guard( m_criticalSection );
  1428.     ///////////////////////////////////////////////////////////////////////////
  1429.  
  1430.     if ( managedThreadID != NULL )
  1431.       {
  1432.           ThreadInfo *pThreadInfo;
  1433.  
  1434.         
  1435.         pThreadInfo = m_pThreadTable->Lookup( managedThreadID );
  1436.         if ( pThreadInfo != NULL )
  1437.         {
  1438.             _ASSERT_( pThreadInfo->m_isValid == TRUE );
  1439.             pThreadInfo->m_win32ThreadID = win32ThreadID;
  1440.         }
  1441.         else
  1442.             _THROW_EXCEPTION( "Thread was not found in the Thread Table" )
  1443.     }
  1444.     else
  1445.         _THROW_EXCEPTION( "ThreadID is NULL" )
  1446.           
  1447.           
  1448. } // PrfInfo::UpdateOSThreadID
  1449.  
  1450.  
  1451. /***************************************************************************************
  1452.  *    Method:
  1453.  *
  1454.  *
  1455.  *    Purpose:
  1456.  *
  1457.  *
  1458.  *    Parameters: 
  1459.  *
  1460.  *
  1461.  *    Return value:
  1462.  *
  1463.  *
  1464.  *    Notes:
  1465.  *
  1466.  ***************************************************************************************/
  1467. /* public */
  1468. /* throws BaseException */
  1469. void PrfInfo::UpdateUnwindStack( FunctionID *functionID, StackAction action )
  1470. {
  1471.        ///////////////////////////////////////////////////////////////////////////
  1472.     Synchronize guard( m_criticalSection );
  1473.     ///////////////////////////////////////////////////////////////////////////
  1474.  
  1475.     HRESULT hr;
  1476.     ThreadID threadID;
  1477.  
  1478.  
  1479.     hr = m_pProfilerInfo->GetCurrentThreadID( &threadID );
  1480.     if ( SUCCEEDED(hr) )
  1481.     {
  1482.         ThreadInfo *pThreadInfo = m_pThreadTable->Lookup( threadID );
  1483.  
  1484.  
  1485.         if ( pThreadInfo != NULL )
  1486.         {
  1487.             StackBaseInfo *stackElement = NULL;
  1488.             
  1489.  
  1490.             _ASSERT_( pThreadInfo->m_isValid == TRUE );
  1491.             if ( action == PUSH )
  1492.             {
  1493.                 stackElement = new StackBaseInfo( *functionID );
  1494.                 (pThreadInfo->m_pLatestUnwoundFunction)->Push( stackElement );
  1495.             }
  1496.             else // we can only have POP
  1497.             {
  1498.                 stackElement = new StackBaseInfo( NULL );
  1499.                 stackElement = (pThreadInfo->m_pLatestUnwoundFunction)->Pop();
  1500.                 if ( stackElement != NULL )
  1501.                 {
  1502.                     *functionID = stackElement->m_id;
  1503.                     delete stackElement;
  1504.                 }
  1505.                 else
  1506.                     _THROW_EXCEPTION( "Stack Contains Bad Data" );
  1507.             }
  1508.         }
  1509.         else                 
  1510.             _THROW_EXCEPTION( "Thread Structure was not found in the thread list" )
  1511.     }
  1512.     else
  1513.         _THROW_EXCEPTION( "ICorProfilerInfo::GetCurrentThreadID() FAILED" )
  1514.  
  1515.     
  1516. } // PrfInfo::UpdateUnwindStack
  1517.  
  1518.  
  1519. /***************************************************************************************
  1520.  *    Method:
  1521.  *
  1522.  *
  1523.  *    Purpose:
  1524.  *
  1525.  *
  1526.  *    Parameters: 
  1527.  *
  1528.  *
  1529.  *    Return value:
  1530.  *
  1531.  *
  1532.  *    Notes:
  1533.  *
  1534.  ***************************************************************************************/
  1535. /* public */
  1536. /* throws BaseException */
  1537. void PrfInfo::AddFunction( FunctionID functionID, JitStatus status )
  1538. {    
  1539.     if ( functionID != NULL )
  1540.     {
  1541.         FunctionInfo *pFunctionInfo;
  1542.         
  1543.  
  1544.         pFunctionInfo = m_pFunctionTable->Lookup( functionID );
  1545.         if ( pFunctionInfo == NULL )
  1546.         {
  1547.             pFunctionInfo = new FunctionInfo( functionID );
  1548.             if ( pFunctionInfo != NULL )
  1549.               {
  1550.                 pFunctionInfo->m_jitStatus = status;
  1551.                 try
  1552.                 {
  1553.                     _GetFunctionInfoHelper( &pFunctionInfo );
  1554.                     m_pFunctionTable->AddEntry( pFunctionInfo, functionID );
  1555.                   }
  1556.                 catch ( BaseException *exception )    
  1557.                 {
  1558.                     delete pFunctionInfo;
  1559.                     throw;                    
  1560.                   }
  1561.             }        
  1562.             else
  1563.                 _THROW_EXCEPTION( "Allocation for FunctionInfo Object FAILED" )
  1564.         }
  1565.         else
  1566.         {
  1567.             //
  1568.             // function has been jitted before, this is a re-jit, 
  1569.             // do no overwrite the entry, simply acknowledge  
  1570.             //
  1571.             if ( pFunctionInfo->m_isPitched == FALSE )
  1572.                 _THROW_EXCEPTION( "Function exist in the table while it shouldn't" )
  1573.         }        
  1574.     }
  1575.     else
  1576.         _THROW_EXCEPTION( "FunctionID is NULL" )
  1577.  
  1578.        
  1579. } // PrfInfo::AddFunction
  1580.  
  1581.  
  1582. /***************************************************************************************
  1583.  *    Method:
  1584.  *
  1585.  *
  1586.  *    Purpose:
  1587.  *
  1588.  *
  1589.  *    Parameters: 
  1590.  *
  1591.  *
  1592.  *    Return value:
  1593.  *
  1594.  *
  1595.  *    Notes:
  1596.  *
  1597.  ***************************************************************************************/
  1598. /* public */
  1599. /* throws BaseException */
  1600. void PrfInfo::RemoveFunction( FunctionID functionID )
  1601. {    
  1602.     if ( functionID != NULL )
  1603.     {
  1604.         FunctionInfo *pFunctionInfo;
  1605.         
  1606.  
  1607.         pFunctionInfo = m_pFunctionTable->Lookup( functionID );
  1608.         if ( pFunctionInfo != NULL )
  1609.         {
  1610.             pFunctionInfo->m_isValid = FALSE;
  1611.         }
  1612.         else
  1613.             _THROW_EXCEPTION( "Function was not found in the Function Table" )
  1614.     }
  1615.     else
  1616.         _THROW_EXCEPTION( "FunctionID is NULL" )
  1617.         
  1618.         
  1619. } // PrfInfo::RemoveFunction
  1620.  
  1621.  
  1622. /***************************************************************************************
  1623.  *    Method:
  1624.  *
  1625.  *
  1626.  *    Purpose:
  1627.  *
  1628.  *
  1629.  *    Parameters: 
  1630.  *
  1631.  *
  1632.  *    Return value:
  1633.  *
  1634.  *
  1635.  *    Notes:
  1636.  *
  1637.  ***************************************************************************************/
  1638. /* public */
  1639. /* throws BaseException */
  1640. void PrfInfo::MarkFunctionAsPitched( FunctionID functionID )
  1641. {    
  1642.     if ( functionID != NULL )
  1643.     {
  1644.         FunctionInfo *pFunctionInfo;
  1645.         
  1646.  
  1647.         pFunctionInfo = m_pFunctionTable->Lookup( functionID );
  1648.         if ( pFunctionInfo != NULL )
  1649.         {
  1650.             _ASSERT_( pFunctionInfo->m_isValid == TRUE );
  1651.             pFunctionInfo->m_isPitched = TRUE;
  1652.         }
  1653.         else
  1654.             _THROW_EXCEPTION( "Function was not found in the Function Table" )
  1655.     }
  1656.     else
  1657.         _THROW_EXCEPTION( "FunctionID is NULL" )
  1658.         
  1659.         
  1660. } // PrfInfo::MarkFunctionAsPitched
  1661.  
  1662.  
  1663. /***************************************************************************************
  1664.  *    Method:
  1665.  *
  1666.  *
  1667.  *    Purpose:
  1668.  *
  1669.  *
  1670.  *    Parameters: 
  1671.  *
  1672.  *
  1673.  *    Return value:
  1674.  *
  1675.  *
  1676.  *    Notes:
  1677.  *
  1678.  ***************************************************************************************/
  1679. /* public */
  1680. /* throws BaseException */
  1681. void PrfInfo::UpdateEnterExitCounters( FunctionID functionID, FunctionCounters which )
  1682. {
  1683.        ///////////////////////////////////////////////////////////////////////////
  1684.     Synchronize guard( m_criticalSection );
  1685.     ///////////////////////////////////////////////////////////////////////////
  1686.  
  1687.     FunctionInfo *pFunctionInfo;
  1688.  
  1689.  
  1690.     // Look in the table for a match
  1691.     pFunctionInfo = m_pFunctionTable->Lookup( functionID );
  1692.     if ( pFunctionInfo != NULL )
  1693.     {
  1694.         _ASSERT_( pFunctionInfo->m_isValid == TRUE );
  1695.  
  1696.         switch ( which )
  1697.         {
  1698.             case ENTER:
  1699.                 InterlockedIncrement( &(pFunctionInfo->m_enter) );
  1700.                 break;
  1701.  
  1702.             case LEAVE:
  1703.                 InterlockedIncrement( &(pFunctionInfo->m_left) );
  1704.                 break;
  1705.  
  1706.             case TAIL:
  1707.                 InterlockedIncrement( &(pFunctionInfo->m_tail) );
  1708.                 break;
  1709.  
  1710.             case UNWIND:
  1711.                 InterlockedIncrement( &(pFunctionInfo->m_unwind) );
  1712.                 break;
  1713.  
  1714.             default:
  1715.                 _THROW_EXCEPTION( "PrfInfo::UpdateEnterExitCounters() has invalid parameters " )
  1716.         }
  1717.     }
  1718.     else
  1719.         _THROW_EXCEPTION( "ERROR: Entry was not found in the function table" )
  1720.  
  1721.  
  1722. } // PrfInfo::UpdateEnterExitCounters
  1723.  
  1724.  
  1725. /***************************************************************************************
  1726.  *    Method:
  1727.  *
  1728.  *
  1729.  *    Purpose:
  1730.  *
  1731.  *
  1732.  *    Parameters: 
  1733.  *
  1734.  *
  1735.  *    Return value:
  1736.  *
  1737.  *
  1738.  *    Notes:
  1739.  *
  1740.  ***************************************************************************************/
  1741. /* public */
  1742. void PrfInfo::DumpTables()
  1743. {
  1744.        // dump thread table
  1745.        if ( m_pThreadTable != NULL )
  1746.     {
  1747.         wprintf( L"*** THREAD TABLE ***\n" );
  1748.         m_pThreadTable->Dump();
  1749.         
  1750.         wprintf( L"\n" );
  1751.         wprintf( L"\n" );
  1752.     }
  1753.  
  1754.       // dump AppDomain table
  1755.        if ( m_pAppDomainTable != NULL )
  1756.     {
  1757.         wprintf( L"*** APP_DOMAIN TABLE ***" );
  1758.         m_pAppDomainTable->Dump();
  1759.         
  1760.         wprintf( L"\n" );
  1761.         wprintf( L"\n" );
  1762.     }
  1763.     
  1764.  
  1765.       // dump Assembly table
  1766.        if ( m_pAssemblyTable != NULL )
  1767.     {
  1768.         wprintf( L"*** ASSEMBLY TABLE ***\n" );
  1769.         m_pAssemblyTable->Dump();
  1770.         
  1771.         wprintf( L"\n" );
  1772.         wprintf( L"\n" );
  1773.     }
  1774.  
  1775.        // dump module table
  1776.        if ( m_pModuleTable != NULL )
  1777.     {
  1778.         wprintf( L"*** MODULE TABLE ***\n" );
  1779.         m_pModuleTable->Dump();
  1780.         
  1781.         wprintf( L"\n" );
  1782.         wprintf( L"\n" );
  1783.     }
  1784.     
  1785.     // dump class table
  1786.        if ( m_pClassTable != NULL )
  1787.     {
  1788.         wprintf( L"*** CLASS TABLE ***\n" );
  1789.         m_pClassTable->Dump();
  1790.         
  1791.         wprintf( L"\n" );
  1792.         wprintf( L"\n" );
  1793.     }
  1794.         
  1795.     // dump function table
  1796.        if ( m_pFunctionTable != NULL )
  1797.     {
  1798.         wprintf( L"*** FUNCTION TABLE ***\n" );
  1799.         m_pFunctionTable->Dump();
  1800.         
  1801.         wprintf( L"\n" );
  1802.         wprintf( L"\n" );
  1803.     }      
  1804.     
  1805.  
  1806. } // PrfInfo::DumpTables
  1807.  
  1808.  
  1809. /***************************************************************************************
  1810.  *    Method:
  1811.  *
  1812.  *
  1813.  *    Purpose:
  1814.  *
  1815.  *
  1816.  *    Parameters: 
  1817.  *
  1818.  *
  1819.  *    Return value:
  1820.  *
  1821.  *
  1822.  *    Notes:
  1823.  *
  1824.  ***************************************************************************************/
  1825. void PrfInfo::Failure( char *message )
  1826. {
  1827.     if ( message == NULL )         
  1828.          message = "**** SEVERE FAILURE: TURNING OFF APPLICABLE PROFILING EVENTS ****";  
  1829.     
  1830.     
  1831.     //
  1832.     // Display the error message and turn off the profiler events except the 
  1833.     // IMMUTABLE ones. Turning off the IMMUTABLE events can cause crashes. The only
  1834.     // place that we can safely enable or disable immutable events is the Initialize
  1835.     // callback.
  1836.     //                  
  1837.     TEXT_OUTLN( message );
  1838.     m_pProfilerInfo->SetEventMask(  m_dwEventMask & (DWORD)COR_PRF_MONITOR_IMMUTABLE );    
  1839.                             
  1840. } // PrfInfo::Failure
  1841.  
  1842.  
  1843. /***************************************************************************************
  1844.  *    Method:
  1845.  *
  1846.  *
  1847.  *    Purpose:
  1848.  *
  1849.  *
  1850.  *    Parameters: 
  1851.  *
  1852.  *
  1853.  *    Return value:
  1854.  *
  1855.  *
  1856.  *    Notes:
  1857.  *
  1858.  ***************************************************************************************/
  1859. /* private */
  1860. /* throws BaseException */
  1861. void PrfInfo::_GetThreadInfoHelper( ThreadInfo **ppThreadInfo )
  1862. {
  1863.        if ( m_pProfilerInfo != NULL )
  1864.     {
  1865.         HRESULT hr;
  1866.         
  1867.         
  1868.         //
  1869.         // Assume that the thread starts running managed code
  1870.         // otherwise we would not get notified for its creation
  1871.         //
  1872.         (*ppThreadInfo)->m_status = MANAGED;
  1873.  
  1874.         //
  1875.         // Get the win32 threadID for the specific Runtime thread
  1876.         //
  1877.         hr = m_pProfilerInfo->GetThreadInfo( (*ppThreadInfo)->m_id, 
  1878.                                              &((*ppThreadInfo)->m_win32ThreadID) );
  1879.           if ( SUCCEEDED( hr ) )
  1880.            {
  1881.               //
  1882.               // Get the thread handle
  1883.               //
  1884.               hr = m_pProfilerInfo->GetHandleFromThread( (*ppThreadInfo)->m_id, 
  1885.                                                        &((*ppThreadInfo)->m_hThread) );      
  1886.             if ( FAILED( hr ) )
  1887.                   _THROW_EXCEPTION( "ICorProfilerInfo::GetHandleFromThread() FAILED" )    
  1888.           }
  1889.         else    
  1890.             _THROW_EXCEPTION( "ICorProfilerInfo::GetThreadInfo() FAILED" )
  1891.      }
  1892.     else
  1893.         _THROW_EXCEPTION( "ICorProfilerInfo Interface has NOT been Initialized" )        
  1894.         
  1895.         
  1896. } // PrfInfo::_GetThreadInfoHelper
  1897.  
  1898.  
  1899. /***************************************************************************************
  1900.  *    Method:
  1901.  *
  1902.  *
  1903.  *    Purpose:
  1904.  *
  1905.  *
  1906.  *    Parameters: 
  1907.  *
  1908.  *
  1909.  *    Return value:
  1910.  *
  1911.  *
  1912.  *    Notes:
  1913.  *
  1914.  ***************************************************************************************/
  1915. /* private */
  1916. /* throws BaseException */
  1917. void PrfInfo::_GetAppDomainInfoHelper( AppDomainInfo **ppAppDomainInfo )
  1918. {    
  1919.     if ( m_pProfilerInfo != NULL )
  1920.     {
  1921.         HRESULT hr;
  1922.         ULONG32 dummy;
  1923.         
  1924.  
  1925.         //
  1926.         // Fill in the rest of the AppDomainInfo data structure
  1927.         // Make sure that you are invoking this helper at from a 
  1928.         // "safe" point. Otherwise the GetAppDomainInfo will fail.
  1929.         //
  1930.         hr = m_pProfilerInfo->GetAppDomainInfo( (*ppAppDomainInfo)->m_id,
  1931.                                                    MAX_LENGTH,
  1932.                                                 &dummy,
  1933.                                                 (*ppAppDomainInfo)->m_name,
  1934.                                                 &((*ppAppDomainInfo)->m_processID) );     
  1935.         if ( FAILED( hr ) )
  1936.             _THROW_EXCEPTION( "ICorProfilerInfo::GetAppDomainInfo() FAILED" )
  1937.        }
  1938.     else
  1939.         _THROW_EXCEPTION( "ICorProfilerInfo Interface has NOT been Initialized" )
  1940.                        
  1941.     
  1942. } // PrfInfo::_GetAppDomainInfoHelper
  1943.  
  1944.  
  1945.   /***************************************************************************************
  1946.  *    Method:
  1947.  *
  1948.  *
  1949.  *    Purpose:
  1950.  *
  1951.  *
  1952.  *    Parameters: 
  1953.  *
  1954.  *
  1955.  *    Return value:
  1956.  *
  1957.  *
  1958.  *    Notes:
  1959.  *
  1960.  ***************************************************************************************/
  1961. /* private */
  1962. /* throws BaseException */
  1963. void PrfInfo::_GetAssemblyInfoHelper( AssemblyInfo **ppAssemblyInfo )
  1964. {    
  1965.     if ( m_pProfilerInfo != NULL )
  1966.     {
  1967.         HRESULT hr;
  1968.         ULONG32 dummy;
  1969.         
  1970.  
  1971.         //
  1972.         // Fill in the rest of the AssemblyInfo data structure
  1973.         // Make sure that you are invoking this helper at from a 
  1974.         // "safe" point. Otherwise the GetAssemblyInfo will fail.
  1975.         //
  1976.         hr = m_pProfilerInfo->GetAssemblyInfo( (*ppAssemblyInfo)->m_id,
  1977.                                                   MAX_LENGTH,
  1978.                                                &dummy,
  1979.                                                (*ppAssemblyInfo)->m_name,
  1980.                                                &((*ppAssemblyInfo)->m_appDomainID),
  1981.                                                &((*ppAssemblyInfo)->m_moduleID) );     
  1982.         if ( SUCCEEDED( hr ) )
  1983.         {
  1984.             try
  1985.             {
  1986.                 //
  1987.                 // In certain occasions, the AppDomain name is NULL and we need to
  1988.                 // wait until the assembly gets loaded to get its name
  1989.                 //
  1990.                 _SetAppDomainName( (*ppAssemblyInfo)->m_appDomainID ); 
  1991.             }
  1992.             catch ( BaseException *exception )    
  1993.             {
  1994.                 throw;                    
  1995.             }
  1996.         }
  1997.         else
  1998.             _THROW_EXCEPTION( "ICorProfilerInfo::GetAssemblyInfo() FAILED" )
  1999.        }
  2000.     else
  2001.         _THROW_EXCEPTION( "ICorProfilerInfo Interface has NOT been Initialized" )
  2002.                
  2003.     
  2004. } // PrfInfo::_GetAssemblyInfoHelper
  2005.  
  2006.  
  2007. /***************************************************************************************
  2008.  *    Method:
  2009.  *
  2010.  *
  2011.  *    Purpose:
  2012.  *
  2013.  *
  2014.  *    Parameters: 
  2015.  *
  2016.  *
  2017.  *    Return value:
  2018.  *
  2019.  *
  2020.  *    Notes:
  2021.  *
  2022.  ***************************************************************************************/
  2023. /* private */
  2024. /* throws BaseException */
  2025. void PrfInfo::_GetModuleInfoHelper( ModuleInfo **ppModuleInfo )
  2026. {    
  2027.     if ( m_pProfilerInfo != NULL )
  2028.     {
  2029.         HRESULT hr;
  2030.         ULONG32 dummy;
  2031.         mdModule token;
  2032.  
  2033.         //
  2034.         // Fill in the rest of the ModuleInfo data structure
  2035.         // We are not interested for the module token. It is pretty useless
  2036.         // since all the API's related to modules are using the moduleID.
  2037.         // Besides it alwasy has the same value for every module.
  2038.         //
  2039.         hr = m_pProfilerInfo->GetModuleInfo( (*ppModuleInfo)->m_id,
  2040.                                                 &((*ppModuleInfo)->m_pBaseLoadAddress),
  2041.                                              MAX_LENGTH,
  2042.                                              &dummy,
  2043.                                              (*ppModuleInfo)->m_name,
  2044.                                              &token,
  2045.                                              NULL );
  2046.           if ( SUCCEEDED( hr ) )
  2047.         {
  2048.             //
  2049.             // Store away a MetaDataImport  interface so you can get metadata 
  2050.             // information for the classes and the methods that the 
  2051.             // specific module contains. You need to free the interface
  2052.             // in the end but you do not need to AddRef it. The API
  2053.             // does an AddRef on it before returning.
  2054.             // 
  2055.               hr = m_pProfilerInfo->GetModuleMetaData( (*ppModuleInfo)->m_id, 
  2056.                                                      ofRead,
  2057.                                                      IID_IMetaDataImport, 
  2058.                                                      (IUnknown **)(&((*ppModuleInfo)->m_pMDImport)) );
  2059.             if ( FAILED( hr ) )            
  2060.                 _THROW_EXCEPTION( "ICorProfilerInfo::GetModuleMetaData() FAILED" )
  2061.           } 
  2062.         else
  2063.             _THROW_EXCEPTION( "ICorProfilerInfo::GetModuleInfo() FAILED" )
  2064.        }
  2065.     else
  2066.         _THROW_EXCEPTION( "ICorProfilerInfo Interface has NOT been Initialized" )
  2067.                
  2068.     
  2069. } // PrfInfo::_GetModuleInfoHelper
  2070.  
  2071.  
  2072. /***************************************************************************************
  2073.  *    Method:
  2074.  *
  2075.  *
  2076.  *    Purpose:
  2077.  *
  2078.  *
  2079.  *    Parameters: 
  2080.  *
  2081.  *
  2082.  *    Return value:
  2083.  *
  2084.  *
  2085.  *    Notes:
  2086.  *
  2087.  ***************************************************************************************/
  2088. /* private */
  2089. /* throws BaseException */
  2090. void PrfInfo::_GetClassInfoHelper( ClassInfo **ppClassInfo )
  2091. {
  2092.     if ( m_pProfilerInfo != NULL )
  2093.     {
  2094.         HRESULT hr;
  2095.         
  2096.         
  2097.           //
  2098.           // Fill in the rest of the ClassInfo data structure
  2099.         //
  2100.         hr = m_pProfilerInfo->GetClassIDInfo( (*ppClassInfo)->m_id, 
  2101.                                               &((*ppClassInfo)->m_moduleID),  
  2102.                                               &((*ppClassInfo)->m_token) );                                                                                                                                              
  2103.         if ( SUCCEEDED( hr ) )
  2104.            {                 
  2105.               ModuleInfo *pModuleInfo;
  2106.                 
  2107.             
  2108.             //
  2109.             // To get the name of the class we have to find the module where 
  2110.             // the class belongs to in order to use    the IMetaDataImport 
  2111.             // interface that was casted away to obtain the class name    
  2112.             //
  2113.             pModuleInfo = m_pModuleTable->Lookup( (*ppClassInfo)->m_moduleID );
  2114.             if ( pModuleInfo != NULL )
  2115.             {                                            
  2116.                   //
  2117.                 // Use the MetaData API to get information about the class
  2118.                 //
  2119.                   hr = pModuleInfo->m_pMDImport->GetTypeDefProps( (*ppClassInfo)->m_token, 
  2120.                                                                 (*ppClassInfo)->m_name, 
  2121.                                                                 MAX_LENGTH,
  2122.                                                                 NULL, 
  2123.                                                                 NULL, 
  2124.                                                                 NULL, 
  2125.                                                                 NULL ); 
  2126.                 if ( FAILED( hr ) )
  2127.                        _THROW_EXCEPTION( "IMetaDataImport::GetTypeDefProps() FAILED" ) 
  2128.               }
  2129.             else         
  2130.                 _THROW_EXCEPTION( "Module for Class NOT Found" )          
  2131.         }
  2132.         else    
  2133.             _THROW_EXCEPTION( "ICorProfilerInfo::GetClassIDInfo() FAILED" )
  2134.        }
  2135.     else
  2136.         _THROW_EXCEPTION( "ICorProfilerInfo Interface has NOT been Initialized" )    
  2137.         
  2138.         
  2139. } // PrfInfo::_GetClassInfoHelper
  2140.  
  2141.  
  2142. /***************************************************************************************
  2143.  *    Method:
  2144.  *
  2145.  *
  2146.  *    Purpose:
  2147.  *
  2148.  *
  2149.  *    Parameters: 
  2150.  *
  2151.  *
  2152.  *    Return value:
  2153.  *
  2154.  *
  2155.  *    Notes:
  2156.  *
  2157.  ***************************************************************************************/
  2158. /* private */
  2159. /* throws BaseException */
  2160. void PrfInfo::_GetFunctionInfoHelper( FunctionInfo **ppFunctionInfo )
  2161. {
  2162.     if ( m_pProfilerInfo != NULL )
  2163.     {
  2164.         HRESULT hr;
  2165.         
  2166.         
  2167.         //
  2168.         // Obtain information for a method related to the class and module 
  2169.         // it belongs to
  2170.         //
  2171.         hr = m_pProfilerInfo->GetFunctionInfo( (*ppFunctionInfo)->m_id,
  2172.                                                &((*ppFunctionInfo)->m_classID),
  2173.                                                &((*ppFunctionInfo)->m_moduleID),
  2174.                                                &((*ppFunctionInfo)->m_token) );
  2175.         if ( SUCCEEDED( hr ) )
  2176.         {       
  2177.              //
  2178.             // Obtain information about the method's code size and start address
  2179.             //
  2180.              hr = m_pProfilerInfo->GetCodeInfo( (*ppFunctionInfo)->m_id, 
  2181.                                                   &((*ppFunctionInfo)->m_pStartAddress), 
  2182.                                                &((*ppFunctionInfo)->m_codeSize) );                                                                                                                                                                  
  2183.             if ( SUCCEEDED( hr ) )
  2184.             {
  2185.                 ModuleInfo *pModuleInfo;
  2186.                 
  2187.                 
  2188.                 //
  2189.                 // Find the module the class belongs to in order to use
  2190.                 // the IMetaDataImport interface to obtain the class and
  2191.                 // function name
  2192.                 //
  2193.                 pModuleInfo = m_pModuleTable->Lookup( (*ppFunctionInfo)->m_moduleID );
  2194.                 if ( pModuleInfo != NULL )
  2195.                 {                     
  2196.                     ClassInfo *pClassInfo;
  2197.                     WCHAR className[MAX_LENGTH];                
  2198.                     WCHAR functionName[MAX_LENGTH];
  2199.                     
  2200.                     
  2201.                        //
  2202.                        // Check to se if the function belongs to a class; 
  2203.                     // if not, then it is obviously a global function
  2204.                     //
  2205.                     pClassInfo = m_pClassTable->Lookup( (*ppFunctionInfo)->m_classID );
  2206.                     if ( pClassInfo != NULL )
  2207.                     {                                                 
  2208.                         hr = pModuleInfo->m_pMDImport->GetTypeDefProps( pClassInfo->m_token, 
  2209.                                                                         className, 
  2210.                                                                         MAX_LENGTH,
  2211.                                                                         NULL, 
  2212.                                                                         NULL, 
  2213.                                                                         NULL, 
  2214.                                                                         NULL );
  2215.                         if ( FAILED( hr ) )
  2216.                                _THROW_EXCEPTION( "IMetaDataImport::GetTypeDefProps() FAILED" )
  2217.                       }
  2218.                     else
  2219.                         wcscpy( className, L"<Global>" );
  2220.                         
  2221.     
  2222.                      //
  2223.                      // We have the all the ingredients for calling IMetaDataImport::GetMethodProps()                        
  2224.                        //
  2225.                        hr = pModuleInfo->m_pMDImport->GetMethodProps( (*ppFunctionInfo)->m_token,
  2226.                                                                    NULL,
  2227.                                                                    functionName,
  2228.                                                                    MAX_LENGTH,
  2229.                                                                    0,
  2230.                                                                    0,
  2231.                                                                    NULL,
  2232.                                                                    NULL,
  2233.                                                                    NULL, 
  2234.                                                                    NULL );
  2235.                        if ( SUCCEEDED( hr ) )
  2236.                         swprintf( (*ppFunctionInfo)->m_name, L"%s::%s", className, functionName );
  2237.                     
  2238.                     else
  2239.                            _THROW_EXCEPTION( "IMetaDataImport::GetMethodProps() FAILED" )                                                                             
  2240.                    }
  2241.                 else
  2242.                     _THROW_EXCEPTION( "Module for Function NOT Found" )              
  2243.             }
  2244.                else
  2245.                 _THROW_EXCEPTION( "ICorProfilerInfo::GetCodeInfo() FAILED" )
  2246.            }
  2247.            else
  2248.                _THROW_EXCEPTION( "ICorProfilerInfo::GetFunctionInfo() FAILED" ) 
  2249.        }
  2250.     else
  2251.         _THROW_EXCEPTION( "ICorProfilerInfo Interface has NOT been Initialized" )        
  2252.  
  2253.  
  2254. } // PrfInfo::_GetFunctionInfoHelper
  2255.  
  2256.  
  2257. /***************************************************************************************
  2258.  *    Method:
  2259.  *
  2260.  *
  2261.  *    Purpose:
  2262.  *
  2263.  *
  2264.  *    Parameters: 
  2265.  *
  2266.  *
  2267.  *    Return value:
  2268.  *
  2269.  *
  2270.  *    Notes:
  2271.  *
  2272.  ***************************************************************************************/
  2273. /* private */
  2274. /* throws BaseException */
  2275. void PrfInfo::_SetAppDomainName( AppDomainID appDomainID )
  2276. {    
  2277.     if ( m_pProfilerInfo != NULL )
  2278.     {
  2279.         if (appDomainID != NULL)
  2280.         {
  2281.             //
  2282.             // Update the name of the AppDomain - It has to be non null at this stage
  2283.             //
  2284.             if (m_pAppDomainTable != NULL)
  2285.             {
  2286.                 AppDomainInfo *pAppDomainInfo;
  2287.                 pAppDomainInfo = m_pAppDomainTable->Lookup( appDomainID );
  2288.  
  2289.                 if (pAppDomainInfo != NULL)
  2290.                 {
  2291.                     //
  2292.                     // AppDomainID was found in the internal tables                    
  2293.                     //
  2294.                     if (pAppDomainInfo->m_name[0] == NULL)
  2295.                     {
  2296.                         //
  2297.                         // Appdomain name is not updated
  2298.                         //
  2299.                         HRESULT hr;
  2300.                         ULONG32 dummy;
  2301.                         
  2302.  
  2303.                         //
  2304.                         // Fill in the rest of the AppDomainInfo data structure
  2305.                         //
  2306.                         hr = m_pProfilerInfo->GetAppDomainInfo( pAppDomainInfo->m_id,
  2307.                                                                    MAX_LENGTH,
  2308.                                                                 &dummy,
  2309.                                                                 pAppDomainInfo->m_name,
  2310.                                                                 &(pAppDomainInfo->m_processID) );     
  2311.                         //
  2312.                         // This code performs verification that the GetAppDomainInfo 
  2313.                         // returns the correct values. At this point we should ALWAYS get
  2314.                         // S_OK ! 
  2315.                         //
  2316.                         if ( SUCCEEDED( hr ) )
  2317.                         {
  2318.                             //
  2319.                             // Check if the acquired value for the name is not NULL
  2320.                             //
  2321.                             if ( pAppDomainInfo->m_name[0] == NULL )    
  2322.                                 _THROW_EXCEPTION( "Unexpected AppDomain Name from ICorProfilerInfo::GetAppDomainInfo()" );
  2323.                         }
  2324.                         else
  2325.                             _THROW_EXCEPTION( "ICorProfilerInfo::GetAppDomainInfo() FAILED" )
  2326.  
  2327.                     
  2328.                     }// there is no else here, if the name is not null, then do nothing
  2329.                 
  2330.                 // end     if (pAppDomainInfo->m_appDomainName == NULL)
  2331.                 }
  2332.                 else
  2333.                 {
  2334.                     //
  2335.                     // An AppDomainCreationEvent arrives AFTER the assembly event for the 
  2336.                     // system appdomain. This is possible to happen and the issue is considered
  2337.                     // solved by design. Therefore, we will not fail if the entry in not 
  2338.                     // in the table, we will simply print the out-of-order AppDomain ID.
  2339.                     //
  2340.                     //
  2341.                     // This value can be used in the end to verify if this ID will exists 
  2342.                     // in the AppDomain table. Do the following: 
  2343.                     //             1.    Store away the out-of-order appdomain ID's 
  2344.                     //            2.  Verify in the PrfInfo .dtor that there is an entry for 
  2345.                     //                them in the appdomain list 
  2346.                     //
  2347.                     TEXT_OUTLN( "AppDomain ID NOT FOUND in AppDomain Table" );
  2348.                 }
  2349.             }
  2350.             else
  2351.                 _THROW_EXCEPTION( "AppDomain Table is NULL" )
  2352.         }
  2353.         else
  2354.             _THROW_EXCEPTION( "AppDomainID is NULL - Unable to proceed" )
  2355.     }
  2356.     else
  2357.         _THROW_EXCEPTION( "ICorProfilerInfo Interface has NOT been Initialized" )
  2358.  
  2359.  
  2360. } // PrfInfo::_SetAppDomainName
  2361.  
  2362.  
  2363. // End of File
  2364.