home *** CD-ROM | disk | FTP | other *** search
/ Enter 1999 November / ENTER11_1.bin / WARSZTAT / SDKJava32.exe / data1.cab / fg_Samples / Samples / Profiler / jviewprf / jviewprf.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-03-17  |  7.2 KB  |  278 lines

  1. // jviewprf.hpp
  2. //
  3. // Created 01/18/99
  4. //
  5. // (C) Copyright 1995 - 1999 Microsoft Corporation.  All rights reserved.
  6. //
  7.  
  8. #ifndef __JVIEWPRF_HPP__
  9. #define __JVIEWPRF_HPP__
  10.  
  11. #include <jviewprf.h>
  12.  
  13. #include "callprof.hpp"
  14. #include "calltrac.hpp"
  15. #include "sampler.hpp"
  16. #include "allocprf.hpp"
  17. #include "gcprof.hpp"
  18.  
  19.  
  20. //------------------------------------------------------------------------
  21.  
  22.  
  23. extern ULONG g_nMethodsToHook;
  24. extern PSTR *g_rgpszMethodsToHook;
  25. extern ULONG g_nClassesToHook;
  26. extern PSTR *g_rgpszClassesToHook;
  27.  
  28.                                                 // -prof options that map to the flag
  29.                                                 // -----------------------------------
  30. #define OPT_PROF_CALLS          0x00000001      // calltimes, calltrace, or callparams
  31. #define OPT_CALL_TRACE          0x00000002      // calltrace or callparams
  32. #define OPT_CALL_TRACE_PARAMS   0x00000004      // callparams
  33. #define OPT_CALL_TIMES          0x00000008      // calltimes
  34. #define OPT_PROF_ALLOC          0x00000010      // permethodalloc or perclassalloc
  35. #define OPT_ALLOC_PER_CLASS     0x00000020      // perclassalloc
  36. #define OPT_ALLOC_PER_METHOD    0x00000040      // permethodalloc
  37. #define OPT_PROF_GC             0x00000080      // gc or heapdump
  38. #define OPT_DUMP_HEAP           0x00000100      // heapdump
  39. #define OPT_GC_SUMMARY          0x00000200      // gc
  40. #define OPT_SAMPLE              0x00000400      // sample
  41. #define OPT_VERBOSE             0x00000800      // verbose
  42. #define OPT_TABLE               0x00001000      // table
  43.  
  44. #define OPT_NON_EVENT_OPTIONS (OPT_TABLE)
  45.  
  46. // If no options besides OPT_NON_EVENT_OPTIONS are set, these are implicitly set.
  47. #define OPT_DEFAULT_OPTIONS (OPT_PROF_CALLS | OPT_CALL_TIMES)
  48.  
  49. extern DWORD g_ProfOptions;
  50.  
  51. extern ULONG g_SamplingFrequency;
  52.  
  53.  
  54. //------------------------------------------------------------------------
  55.  
  56.  
  57. VOID FatalError (UINT id, ...);
  58. VOID Warning (UINT id, ...);
  59.  
  60. extern ULONG g_OutputWidth;
  61.  
  62. // printf("Hello")
  63. VOID WriteOutput (PCSTR pcsz);
  64.  
  65. // printf(L"Hello")
  66. VOID WriteOutputW (PCWSTR pcwsz);
  67.  
  68. VOID WriteOutputUtf8 (PCSTR pcszUtf8);
  69.  
  70. // printf("%u", 500)
  71. #define WRITE_MAX_SIZE_NORM_FMT 512
  72. VOID WriteOutputFmt (PCSTR fmt, ...);
  73.  
  74. // printf("%s", foo);
  75. // This uses the VM's snprintf, which supports a limited subset of the format characters.
  76. VOID WriteOutputLongFmt (PCSTR fmt, ...);
  77.  
  78. // First arg is field width.
  79. #define WRITE_LEFT_JUSTIFIED    0x00000001
  80. #define WRITE_CENTERED          0x00000002
  81. #define WRITE_RIGHT_JUSTIFIED   0x00000004
  82. #define WRITE_WRAP              0x00000008
  83.  
  84. // First arg is size of fixed space, second arg is percent of remaining to use
  85. // as field width.  With WRITE_WRAP, third arg is percent of remaining already
  86. // used, fourth arg is fixed space already used.
  87. #define WRITE_FIT               0x00000010
  88.  
  89. // The maximum size of at least one of the arguments is unknown.
  90. #define WRITE_BIG               0x00000020
  91.  
  92. // First formatted arg is a utf8 string.
  93. #define WRITE_UTF8              0x00000040
  94.  
  95. VOID WriteOutputEx (DWORD flags, PCSTR fmt, ...);
  96.  
  97.  
  98. //------------------------------------------------------------------------
  99.  
  100.  
  101. enum VMReleases
  102. {
  103.     VM_UNKNOWN,
  104.     VM_IE40,
  105.     VM_SDK30PR1,
  106.     VM_SDK31,
  107.     VM_CURRENT,
  108. };
  109.  
  110.  
  111. //------------------------------------------------------------------------
  112.  
  113.  
  114. struct ThreadRecord
  115. {
  116.     ThreadID vmid;
  117.     DWORD tid;
  118.  
  119.     AllocationProfilerThreadData allocdata;
  120.     CallProfilerThreadData calldata;
  121.     CallTracerThreadData tracedata;
  122. };
  123.  
  124.  
  125. //------------------------------------------------------------------------
  126.  
  127.  
  128. class EventMonitor : public IJavaEventMonitor2,
  129.                      public IObjectAllocationCallback,
  130.                      public IJVIEWProfiler
  131. {
  132. private:
  133.  
  134.     UINT    m_refcount;
  135.  
  136.     IJavaEventMonitorIDInfo *m_monitor_info;
  137.     IJavaEventMonitorIDInfo2 *m_monitor_info2;
  138.     IJavaEventMonitorIDInfo3 *m_monitor_info3;
  139.     IJavaEventMonitorIDInfo4 *m_monitor_info4;
  140.  
  141.     VMReleases m_VMRelease;
  142.  
  143.  
  144.     CallProfiler m_callprof;
  145.  
  146.     CallTracer m_calltracer;
  147.  
  148.     SamplingProfiler m_sampler;
  149.  
  150.     AllocationProfiler m_allocprof;
  151.  
  152.     GCProfiler m_gcprof;
  153.  
  154.  
  155.     BOOL    m_fVMInitialized;
  156.     BOOL    m_fVMTerminated;
  157.  
  158.     VOID OnVMInitialization ();
  159.  
  160.  
  161.     DWORD m_threadtls;
  162.     CRITICAL_SECTION m_ThreadEventCS;
  163.     ThreadRecord **m_rgpthreads;
  164.     ULONG m_nthreads;
  165.     ULONG m_maxthreads;
  166.  
  167.     ThreadRecord *CreateCurrentThreadRecord ();
  168.     ThreadRecord *GetThreadRecord (ThreadID vmid, DWORD tid);
  169.     ThreadRecord *CreateThreadRecord (ThreadID vmid, DWORD tid);
  170.  
  171.     ThreadRecord *GetCurrentThreadRecord ()
  172.     {
  173.         ThreadRecord *pThread = (ThreadRecord*)TlsGetValue(m_threadtls);
  174.         if (pThread)
  175.             return pThread;
  176.         return CreateCurrentThreadRecord();
  177.     }
  178.  
  179.  
  180. public:
  181.  
  182.     EventMonitor ();
  183.     ~EventMonitor ();
  184.  
  185.     VOID ShutdownWorker (BOOL fNormal);
  186.  
  187.  
  188.     IJavaEventMonitorIDInfo *GetVMInfoIfc ()
  189.     {
  190.         return m_monitor_info;
  191.     }
  192.  
  193.     IJavaEventMonitorIDInfo2 *GetVMInfoIfc2 ()
  194.     {
  195.         return m_monitor_info2;
  196.     }
  197.  
  198.     IJavaEventMonitorIDInfo3 *GetVMInfoIfc3 ()
  199.     {
  200.         return m_monitor_info3;
  201.     }
  202.  
  203.  
  204.     BOOL IsVMInitialized ()
  205.     {
  206.         return m_fVMInitialized;
  207.     }
  208.  
  209.     BOOL IsVMTerminating ()
  210.     {
  211.         return m_fVMTerminated;
  212.     }
  213.  
  214.  
  215.     typedef VOID ThreadIterProc (ThreadRecord*, PVOID);
  216.  
  217.     VOID IterateThreads (ThreadIterProc *cb, PVOID token)
  218.     {
  219.         EnterCriticalSection(&m_ThreadEventCS);
  220.         {
  221.             unsigned i;
  222.             unsigned nthreads = m_nthreads;
  223.  
  224.             ThreadRecord **pthreads = m_rgpthreads;
  225.             for (i = 0; i < nthreads; i++)
  226.             {
  227.                 (*cb)(pthreads[i], token);
  228.             }
  229.         }
  230.         LeaveCriticalSection(&m_ThreadEventCS);
  231.     }
  232.  
  233.  
  234.     // IUnknown
  235.  
  236.     STDMETHODIMP QueryInterface(REFIID, void **);
  237.     STDMETHODIMP_(ULONG) AddRef(void);
  238.     STDMETHODIMP_(ULONG) Release(void);
  239.  
  240.     // IJavaEventMonitor
  241.  
  242.     STDMETHODIMP Initialize(LPCSTR pclass_file_name, IJavaEventMonitorIDInfo *pmonitor_info, DWORD java_flags, DWORD *prequested_events);
  243.     STDMETHODIMP NotifyEvent(JVM_EVENT_TYPE event, UniqueID event_id);
  244.     STDMETHODIMP MethodEntry(MethodID method_id, StackID stack_id);
  245.     STDMETHODIMP MethodExit(StackID stack_id);
  246.     STDMETHODIMP ExecuteByteCode(MethodID method_id, BYTE_CODE *pbyte_code, DWORD byte_code_offset);
  247.     STDMETHODIMP ExecuteSourceLine(MethodID method_id, DWORD line_number);
  248.  
  249.     // IJavaEventMonitor2
  250.  
  251.     STDMETHODIMP NotifyEvent2(JVM_EVENT_TYPE2 event2, UniqueID first_event_id, UniqueID second_event_id);
  252.     STDMETHODIMP MethodExit2(MethodID method_id, StackID stack_id);
  253.     STDMETHODIMP GetPossibleEventCategories(DWORD *ppossible_events);
  254.  
  255.     // IObjectAllocationCallback
  256.  
  257.     STDMETHODIMP OnObjectAllocated(ObjectID oid, ClassID type);
  258.  
  259.     // IJVIEWProfiler
  260.  
  261.     STDMETHODIMP JVIEWInitialize (IJVIEWProfilerUtils *putils, DWORD *pflags);
  262.  
  263.     STDMETHODIMP ParseParameters (PCSTR pcszParams);
  264.  
  265.     STDMETHODIMP_(PSTR) GetUsageString ();
  266.  
  267.     STDMETHODIMP_(VOID) Shutdown ()
  268.     {
  269.         ShutdownWorker(TRUE);
  270.     }
  271. };
  272.  
  273.  
  274.  
  275.  
  276. #endif /* __JVIEWPRF_HPP__ */
  277.  
  278.