home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / Profiler / jviewprf / jviewprf.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-04  |  8.5 KB  |  313 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. // Options from the command line
  22.  
  23.  
  24. extern ULONG g_nMethodsToHook;
  25. extern PSTR *g_rgpszMethodsToHook;
  26. extern ULONG g_nClassesToHook;
  27. extern PSTR *g_rgpszClassesToHook;
  28.  
  29.                                                 // -prof options that map to the flag
  30.                                                 // -----------------------------------
  31. #define OPT_PROF_CALLS          0x00000001      // calltimes, calltrace, or callparams
  32. #define OPT_CALL_TRACE          0x00000002      // calltrace or callparams
  33. #define OPT_CALL_TRACE_PARAMS   0x00000004      // callparams
  34. #define OPT_CALL_TIMES          0x00000008      // calltimes
  35. #define OPT_PROF_ALLOC          0x00000010      // permethodalloc or perclassalloc
  36. #define OPT_ALLOC_PER_CLASS     0x00000020      // perclassalloc
  37. #define OPT_ALLOC_PER_METHOD    0x00000040      // permethodalloc
  38. #define OPT_PROF_GC             0x00000080      // gc or heapdump
  39. #define OPT_DUMP_HEAP           0x00000100      // heapdump
  40. #define OPT_GC_SUMMARY          0x00000200      // gc
  41. #define OPT_SAMPLE              0x00000400      // sample
  42. #define OPT_VERBOSE             0x00000800      // verbose
  43. #define OPT_TABLE               0x00001000      // table
  44.  
  45. #define OPT_NON_EVENT_OPTIONS (OPT_TABLE)
  46.  
  47. // If no options besides OPT_NON_EVENT_OPTIONS are set, these are implicitly set.
  48. #define OPT_DEFAULT_OPTIONS (OPT_PROF_CALLS | OPT_CALL_TIMES)
  49.  
  50. extern DWORD g_ProfOptions;
  51.  
  52. extern ULONG g_SamplingFrequency;
  53.  
  54.  
  55. //------------------------------------------------------------------------
  56. // Output stuff
  57.  
  58.  
  59. extern IJVIEWProfilerUtils *g_pJVIEW;
  60. extern ULONG g_OutputWidth;
  61.  
  62. VOID DisplayMessage (JVIEWDisplayClass type, UINT id, va_list va);
  63.  
  64. VOID FatalError (UINT id, ...);
  65. VOID Warning (UINT id, ...);
  66.  
  67. // All of the WriteOutput variants use the VM's snprintf, which supports a
  68. // limited subset of the format characters.
  69.  
  70. // printf("Hello")
  71. VOID WriteOutput (PCSTR pcsz);
  72. VOID WriteOutput (PCSTR pcsz, int len);
  73.  
  74. // printf(L"Hello")
  75. VOID WriteOutputW (PCWSTR pcwsz);
  76.  
  77. VOID WriteOutputUtf8 (PCSTR pcszUtf8);
  78.  
  79. // printf("%u", 500)
  80. #define WRITE_MAX_SIZE_NORM_FMT 2048
  81. VOID WriteOutputFmt (PCSTR fmt, ...);
  82.  
  83.  
  84. // Justification
  85. #define WRITE_LEFT_JUSTIFIED    0x00000001
  86. #define WRITE_CENTERED          0x00000002
  87. #define WRITE_RIGHT_JUSTIFIED   0x00000004
  88.  
  89. // If longer than field width, align next column on next line
  90. #define WRITE_WRAP              0x00000008
  91.  
  92. // Field width is a percentage of the total output device width.
  93. #define WRITE_FIT               0x00000010
  94.  
  95. // Convert string from UTF-8 format
  96. #define WRITE_UTF8              0x00000020
  97.  
  98. // Write a ' ' at the end
  99. #define WRITE_SPACE             0x00000040
  100.  
  101. // Write a '\n' at the end
  102. #define WRITE_NEWLINE           0x00000080
  103.  
  104. struct WriteOutputExArgs
  105. {
  106.     // Valid with WRITE_LEFT_JUSTIFIED, WRITE_CENTERED, WRITE_RIGHT_JUSTIFIED,
  107.     // WRITE_WRAP, or WRITE_FIT.  With WRITE_FIT, this is the amount of the
  108.     // output device width already used or reserved for other fields.
  109.     ULONG Width;
  110.  
  111.     // Valid with WRITE_FIT.
  112.     ULONG PctFreeSpaceToUse;
  113.  
  114.     // Valid with WRITE_FIT, WRITE_WRAP, and ctFreeSpaceToUse < 100.
  115.     ULONG PctFreeSpaceUsed;
  116.     ULONG FixedSpaceUsed;
  117.     
  118. };
  119.  
  120. VOID WriteOutputEx (DWORD flags, WriteOutputExArgs *pArgs, PCSTR pcsz);
  121. VOID WriteOutputFmtEx (DWORD flags, WriteOutputExArgs *pArgs, PCSTR fmt, ...);
  122.  
  123. VOID WriteOutputFloat (DWORD flags, double value);
  124. VOID WriteOutputFixedFloat (DWORD flags, double value, int precision);
  125. VOID WriteOutputFitString (DWORD flags, ULONG FixedWidth, ULONG PctFreeSpaceToUse, PCSTR pcsz);
  126. VOID WriteOutputColumnULONG (DWORD flags, ULONG ColumnWidth, ULONG value);
  127. VOID WriteOutputColumnUINT64 (DWORD flags, ULONG ColumnWidth, unsigned __int64 value);
  128. VOID WriteOutputColumnString (DWORD flags, ULONG ColumnWidth, PCSTR pcsz);
  129. VOID WriteOutputColumnFmt (DWORD flags, ULONG ColumnWidth, PCSTR fmt, ...);
  130.  
  131. VOID WriteCurrentTime (PCSTR prefix, PCSTR suffix);
  132.  
  133.  
  134. //------------------------------------------------------------------------
  135. // VM version
  136.  
  137.  
  138. enum VMReleases
  139. {
  140.     VM_UNKNOWN,
  141.     VM_IE40,
  142.     VM_SDK30PR1,
  143.     VM_SDK31,
  144.     VM_CURRENT,
  145. };
  146.  
  147.  
  148. //------------------------------------------------------------------------
  149.  
  150.  
  151. struct ThreadRecord
  152. {
  153.     ThreadID vmid;
  154.     DWORD tid;
  155.  
  156.     AllocationProfilerThreadData allocdata;
  157.     CallProfilerThreadData calldata;
  158.     CallTracerThreadData tracedata;
  159. };
  160.  
  161.  
  162. //------------------------------------------------------------------------
  163.  
  164.  
  165. class EventMonitor : public IJavaEventMonitor2,
  166.                      public IObjectAllocationCallback,
  167.                      public IJVIEWProfiler
  168. {
  169. private:
  170.  
  171.     UINT    m_refcount;
  172.  
  173.     IJavaEventMonitorIDInfo *m_monitor_info;
  174.     IJavaEventMonitorIDInfo2 *m_monitor_info2;
  175.     IJavaEventMonitorIDInfo3 *m_monitor_info3;
  176.     IJavaEventMonitorIDInfo4 *m_monitor_info4;
  177.  
  178.     VMReleases m_VMRelease;
  179.  
  180.  
  181.     CallProfiler m_callprof;
  182.  
  183.     CallTracer m_calltracer;
  184.  
  185.     SamplingProfiler m_sampler;
  186.  
  187.     AllocationProfiler m_allocprof;
  188.  
  189.     GCProfiler m_gcprof;
  190.  
  191.  
  192.     BOOL    m_fVMInitialized;
  193.     BOOL    m_fVMTerminated;
  194.  
  195.     VOID OnVMInitialization ();
  196.  
  197.  
  198.     DWORD m_threadtls;
  199.     CRITICAL_SECTION m_ThreadEventCS;
  200.     ThreadRecord **m_rgpthreads;
  201.     ULONG m_nthreads;
  202.     ULONG m_maxthreads;
  203.  
  204.     ThreadRecord *CreateCurrentThreadRecord ();
  205.     ThreadRecord *GetThreadRecord (ThreadID vmid, DWORD tid);
  206.     ThreadRecord *CreateThreadRecord (ThreadID vmid, DWORD tid);
  207.  
  208.     ThreadRecord *GetCurrentThreadRecord ()
  209.     {
  210.         ThreadRecord *pThread = (ThreadRecord*)TlsGetValue(m_threadtls);
  211.         if (pThread)
  212.             return pThread;
  213.         return CreateCurrentThreadRecord();
  214.     }
  215.  
  216.  
  217. public:
  218.  
  219.     EventMonitor ();
  220.     ~EventMonitor ();
  221.  
  222.     VOID ShutdownWorker (BOOL fNormal);
  223.  
  224.  
  225.     IJavaEventMonitorIDInfo *GetVMInfoIfc ()
  226.     {
  227.         return m_monitor_info;
  228.     }
  229.  
  230.     IJavaEventMonitorIDInfo2 *GetVMInfoIfc2 ()
  231.     {
  232.         return m_monitor_info2;
  233.     }
  234.  
  235.     IJavaEventMonitorIDInfo3 *GetVMInfoIfc3 ()
  236.     {
  237.         return m_monitor_info3;
  238.     }
  239.  
  240.  
  241.     BOOL IsVMInitialized ()
  242.     {
  243.         return m_fVMInitialized;
  244.     }
  245.  
  246.     BOOL IsVMTerminating ()
  247.     {
  248.         return m_fVMTerminated;
  249.     }
  250.  
  251.  
  252.     typedef VOID ThreadIterProc (ThreadRecord*, PVOID);
  253.  
  254.     VOID IterateThreads (ThreadIterProc *cb, PVOID token)
  255.     {
  256.         EnterCriticalSection(&m_ThreadEventCS);
  257.         {
  258.             unsigned i;
  259.             unsigned nthreads = m_nthreads;
  260.  
  261.             ThreadRecord **pthreads = m_rgpthreads;
  262.             for (i = 0; i < nthreads; i++)
  263.             {
  264.                 (*cb)(pthreads[i], token);
  265.             }
  266.         }
  267.         LeaveCriticalSection(&m_ThreadEventCS);
  268.     }
  269.  
  270.  
  271.     // IUnknown
  272.  
  273.     STDMETHODIMP QueryInterface(REFIID, void **);
  274.     STDMETHODIMP_(ULONG) AddRef(void);
  275.     STDMETHODIMP_(ULONG) Release(void);
  276.  
  277.     // IJavaEventMonitor
  278.  
  279.     STDMETHODIMP Initialize(LPCSTR pclass_file_name, IJavaEventMonitorIDInfo *pmonitor_info, DWORD java_flags, DWORD *prequested_events);
  280.     STDMETHODIMP NotifyEvent(JVM_EVENT_TYPE event, UniqueID event_id);
  281.     STDMETHODIMP MethodEntry(MethodID method_id, StackID stack_id);
  282.     STDMETHODIMP MethodExit(StackID stack_id);
  283.     STDMETHODIMP ExecuteByteCode(MethodID method_id, BYTE_CODE *pbyte_code, DWORD byte_code_offset);
  284.     STDMETHODIMP ExecuteSourceLine(MethodID method_id, DWORD line_number);
  285.  
  286.     // IJavaEventMonitor2
  287.  
  288.     STDMETHODIMP NotifyEvent2(JVM_EVENT_TYPE2 event2, UniqueID first_event_id, UniqueID second_event_id);
  289.     STDMETHODIMP MethodExit2(MethodID method_id, StackID stack_id);
  290.     STDMETHODIMP GetPossibleEventCategories(DWORD *ppossible_events);
  291.  
  292.     // IObjectAllocationCallback
  293.  
  294.     STDMETHODIMP OnObjectAllocated(ObjectID oid, ClassID type);
  295.  
  296.     // IJVIEWProfiler
  297.  
  298.     STDMETHODIMP JVIEWInitialize (IJVIEWProfilerUtils *putils);
  299.  
  300.     STDMETHODIMP ParseParameters (PCSTR pcszParams);
  301.  
  302.     STDMETHODIMP_(VOID) Shutdown ()
  303.     {
  304.         ShutdownWorker(TRUE);
  305.     }
  306. };
  307.  
  308. extern EventMonitor *g_EventMonitor;
  309.  
  310.  
  311. #endif /* __JVIEWPRF_HPP__ */
  312.  
  313.