home *** CD-ROM | disk | FTP | other *** search
- // jviewprf.hpp
- //
- // Created 01/18/99
- //
- // (C) Copyright 1995 - 1999 Microsoft Corporation. All rights reserved.
- //
-
- #ifndef __JVIEWPRF_HPP__
- #define __JVIEWPRF_HPP__
-
- #include <jviewprf.h>
-
- #include "callprof.hpp"
- #include "calltrac.hpp"
- #include "sampler.hpp"
- #include "allocprf.hpp"
- #include "gcprof.hpp"
-
-
- //------------------------------------------------------------------------
- // Options from the command line
-
-
- extern ULONG g_nMethodsToHook;
- extern PSTR *g_rgpszMethodsToHook;
- extern ULONG g_nClassesToHook;
- extern PSTR *g_rgpszClassesToHook;
-
- // -prof options that map to the flag
- // -----------------------------------
- #define OPT_PROF_CALLS 0x00000001 // calltimes, calltrace, or callparams
- #define OPT_CALL_TRACE 0x00000002 // calltrace or callparams
- #define OPT_CALL_TRACE_PARAMS 0x00000004 // callparams
- #define OPT_CALL_TIMES 0x00000008 // calltimes
- #define OPT_PROF_ALLOC 0x00000010 // permethodalloc or perclassalloc
- #define OPT_ALLOC_PER_CLASS 0x00000020 // perclassalloc
- #define OPT_ALLOC_PER_METHOD 0x00000040 // permethodalloc
- #define OPT_PROF_GC 0x00000080 // gc or heapdump
- #define OPT_DUMP_HEAP 0x00000100 // heapdump
- #define OPT_GC_SUMMARY 0x00000200 // gc
- #define OPT_SAMPLE 0x00000400 // sample
- #define OPT_VERBOSE 0x00000800 // verbose
- #define OPT_TABLE 0x00001000 // table
-
- #define OPT_NON_EVENT_OPTIONS (OPT_TABLE)
-
- // If no options besides OPT_NON_EVENT_OPTIONS are set, these are implicitly set.
- #define OPT_DEFAULT_OPTIONS (OPT_PROF_CALLS | OPT_CALL_TIMES)
-
- extern DWORD g_ProfOptions;
-
- extern ULONG g_SamplingFrequency;
-
-
- //------------------------------------------------------------------------
- // Output stuff
-
-
- extern IJVIEWProfilerUtils *g_pJVIEW;
- extern ULONG g_OutputWidth;
-
- VOID DisplayMessage (JVIEWDisplayClass type, UINT id, va_list va);
-
- VOID FatalError (UINT id, ...);
- VOID Warning (UINT id, ...);
-
- // All of the WriteOutput variants use the VM's snprintf, which supports a
- // limited subset of the format characters.
-
- // printf("Hello")
- VOID WriteOutput (PCSTR pcsz);
- VOID WriteOutput (PCSTR pcsz, int len);
-
- // printf(L"Hello")
- VOID WriteOutputW (PCWSTR pcwsz);
-
- VOID WriteOutputUtf8 (PCSTR pcszUtf8);
-
- // printf("%u", 500)
- #define WRITE_MAX_SIZE_NORM_FMT 2048
- VOID WriteOutputFmt (PCSTR fmt, ...);
-
-
- // Justification
- #define WRITE_LEFT_JUSTIFIED 0x00000001
- #define WRITE_CENTERED 0x00000002
- #define WRITE_RIGHT_JUSTIFIED 0x00000004
-
- // If longer than field width, align next column on next line
- #define WRITE_WRAP 0x00000008
-
- // Field width is a percentage of the total output device width.
- #define WRITE_FIT 0x00000010
-
- // Convert string from UTF-8 format
- #define WRITE_UTF8 0x00000020
-
- // Write a ' ' at the end
- #define WRITE_SPACE 0x00000040
-
- // Write a '\n' at the end
- #define WRITE_NEWLINE 0x00000080
-
- struct WriteOutputExArgs
- {
- // Valid with WRITE_LEFT_JUSTIFIED, WRITE_CENTERED, WRITE_RIGHT_JUSTIFIED,
- // WRITE_WRAP, or WRITE_FIT. With WRITE_FIT, this is the amount of the
- // output device width already used or reserved for other fields.
- ULONG Width;
-
- // Valid with WRITE_FIT.
- ULONG PctFreeSpaceToUse;
-
- // Valid with WRITE_FIT, WRITE_WRAP, and ctFreeSpaceToUse < 100.
- ULONG PctFreeSpaceUsed;
- ULONG FixedSpaceUsed;
-
- };
-
- VOID WriteOutputEx (DWORD flags, WriteOutputExArgs *pArgs, PCSTR pcsz);
- VOID WriteOutputFmtEx (DWORD flags, WriteOutputExArgs *pArgs, PCSTR fmt, ...);
-
- VOID WriteOutputFloat (DWORD flags, double value);
- VOID WriteOutputFixedFloat (DWORD flags, double value, int precision);
- VOID WriteOutputFitString (DWORD flags, ULONG FixedWidth, ULONG PctFreeSpaceToUse, PCSTR pcsz);
- VOID WriteOutputColumnULONG (DWORD flags, ULONG ColumnWidth, ULONG value);
- VOID WriteOutputColumnUINT64 (DWORD flags, ULONG ColumnWidth, unsigned __int64 value);
- VOID WriteOutputColumnString (DWORD flags, ULONG ColumnWidth, PCSTR pcsz);
- VOID WriteOutputColumnFmt (DWORD flags, ULONG ColumnWidth, PCSTR fmt, ...);
-
- VOID WriteCurrentTime (PCSTR prefix, PCSTR suffix);
-
-
- //------------------------------------------------------------------------
- // VM version
-
-
- enum VMReleases
- {
- VM_UNKNOWN,
- VM_IE40,
- VM_SDK30PR1,
- VM_SDK31,
- VM_CURRENT,
- };
-
-
- //------------------------------------------------------------------------
-
-
- struct ThreadRecord
- {
- ThreadID vmid;
- DWORD tid;
-
- AllocationProfilerThreadData allocdata;
- CallProfilerThreadData calldata;
- CallTracerThreadData tracedata;
- };
-
-
- //------------------------------------------------------------------------
-
-
- class EventMonitor : public IJavaEventMonitor2,
- public IObjectAllocationCallback,
- public IJVIEWProfiler
- {
- private:
-
- UINT m_refcount;
-
- IJavaEventMonitorIDInfo *m_monitor_info;
- IJavaEventMonitorIDInfo2 *m_monitor_info2;
- IJavaEventMonitorIDInfo3 *m_monitor_info3;
- IJavaEventMonitorIDInfo4 *m_monitor_info4;
-
- VMReleases m_VMRelease;
-
-
- CallProfiler m_callprof;
-
- CallTracer m_calltracer;
-
- SamplingProfiler m_sampler;
-
- AllocationProfiler m_allocprof;
-
- GCProfiler m_gcprof;
-
-
- BOOL m_fVMInitialized;
- BOOL m_fVMTerminated;
-
- VOID OnVMInitialization ();
-
-
- DWORD m_threadtls;
- CRITICAL_SECTION m_ThreadEventCS;
- ThreadRecord **m_rgpthreads;
- ULONG m_nthreads;
- ULONG m_maxthreads;
-
- ThreadRecord *CreateCurrentThreadRecord ();
- ThreadRecord *GetThreadRecord (ThreadID vmid, DWORD tid);
- ThreadRecord *CreateThreadRecord (ThreadID vmid, DWORD tid);
-
- ThreadRecord *GetCurrentThreadRecord ()
- {
- ThreadRecord *pThread = (ThreadRecord*)TlsGetValue(m_threadtls);
- if (pThread)
- return pThread;
- return CreateCurrentThreadRecord();
- }
-
-
- public:
-
- EventMonitor ();
- ~EventMonitor ();
-
- VOID ShutdownWorker (BOOL fNormal);
-
-
- IJavaEventMonitorIDInfo *GetVMInfoIfc ()
- {
- return m_monitor_info;
- }
-
- IJavaEventMonitorIDInfo2 *GetVMInfoIfc2 ()
- {
- return m_monitor_info2;
- }
-
- IJavaEventMonitorIDInfo3 *GetVMInfoIfc3 ()
- {
- return m_monitor_info3;
- }
-
-
- BOOL IsVMInitialized ()
- {
- return m_fVMInitialized;
- }
-
- BOOL IsVMTerminating ()
- {
- return m_fVMTerminated;
- }
-
-
- typedef VOID ThreadIterProc (ThreadRecord*, PVOID);
-
- VOID IterateThreads (ThreadIterProc *cb, PVOID token)
- {
- EnterCriticalSection(&m_ThreadEventCS);
- {
- unsigned i;
- unsigned nthreads = m_nthreads;
-
- ThreadRecord **pthreads = m_rgpthreads;
- for (i = 0; i < nthreads; i++)
- {
- (*cb)(pthreads[i], token);
- }
- }
- LeaveCriticalSection(&m_ThreadEventCS);
- }
-
-
- // IUnknown
-
- STDMETHODIMP QueryInterface(REFIID, void **);
- STDMETHODIMP_(ULONG) AddRef(void);
- STDMETHODIMP_(ULONG) Release(void);
-
- // IJavaEventMonitor
-
- STDMETHODIMP Initialize(LPCSTR pclass_file_name, IJavaEventMonitorIDInfo *pmonitor_info, DWORD java_flags, DWORD *prequested_events);
- STDMETHODIMP NotifyEvent(JVM_EVENT_TYPE event, UniqueID event_id);
- STDMETHODIMP MethodEntry(MethodID method_id, StackID stack_id);
- STDMETHODIMP MethodExit(StackID stack_id);
- STDMETHODIMP ExecuteByteCode(MethodID method_id, BYTE_CODE *pbyte_code, DWORD byte_code_offset);
- STDMETHODIMP ExecuteSourceLine(MethodID method_id, DWORD line_number);
-
- // IJavaEventMonitor2
-
- STDMETHODIMP NotifyEvent2(JVM_EVENT_TYPE2 event2, UniqueID first_event_id, UniqueID second_event_id);
- STDMETHODIMP MethodExit2(MethodID method_id, StackID stack_id);
- STDMETHODIMP GetPossibleEventCategories(DWORD *ppossible_events);
-
- // IObjectAllocationCallback
-
- STDMETHODIMP OnObjectAllocated(ObjectID oid, ClassID type);
-
- // IJVIEWProfiler
-
- STDMETHODIMP JVIEWInitialize (IJVIEWProfilerUtils *putils);
-
- STDMETHODIMP ParseParameters (PCSTR pcszParams);
-
- STDMETHODIMP_(VOID) Shutdown ()
- {
- ShutdownWorker(TRUE);
- }
- };
-
- extern EventMonitor *g_EventMonitor;
-
-
- #endif /* __JVIEWPRF_HPP__ */
-
-