 COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	Copyright (c) Geoworks 1994 -- All Rights Reserved

PROJECT:	
MODULE:		
FILE:		profile.def<2>

AUTHOR:		Ian Porteous, Oct  3, 1994

MACROS:
	Name			Description
	----			-----------

REVISION HISTORY:
	Name	Date		Description
	----	----		-----------
	IP	10/ 3/94   	Initial revision


DESCRIPTION:
	This file contains various exported routines for the profile
	library

		
	$Id: profile.def,v 1.1 97/04/04 14:26:25 newdeal Exp $

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@

SetDef __PROFILE

ProfileEntryBegMask	equ	0x8000


COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		InsertGenericProfileEntry
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SYNOPSIS:	Inserts the code to add a ProfileGenericLogEntry to
		the profiling log.  It takes a ProfileEntryType, and
		whether it is the begginning or end marker for that
		type.  It also takes a Profile mode flag.  The entry
		will only be added to the log if this flag is set at
		the time this code is executed. 

PASS:		entryType	= ProfileEntryType
		startEnd	= beg or end 
		profileMode	= ProfileModeFlag associated with this
				  log entry or bx containing profile
				  mode flags
		dataReg		= register containing word of data

DESTROYED:	none

PSEUDO CODE/STRATEGY:

KNOWN BUGS/SIDE EFFECTS/IDEAS:

REVISION HISTORY:
	Name	Date		Description
	----	----		-----------
	IP	10/20/94	Initial version

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
InsertGenericProfileEntry   macro entryType, startEnd, profileMode, dataReg
if PROFILE_LOG
	pushf
	push	ax, bx, cx
if <dataReg> ne <cx> and <dataReg> ne <CX>
	mov	cx, dataReg
endif	
if <profileMode> ne <bx> and <profileMode> ne <BX>
	mov	bx, mask profileMode
endif	
	mov	ax, entryType
if (startEnd eq 1)
	or	ax, ProfileEntryBegMask
endif
	call	ProfileWriteGenericEntry
	pop	ax, bx, cx
	popf
endif
endm


COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		InsertMessageProfileEntry
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SYNOPSIS:	Inserts the code to add a ProfileMessageLogEntry to
		the profiling log.  It takes a ProfileEntryType, and
		whether it is the begginning or end marker for that
		type.  The entry will only be added to the log if this
		flag is set at the time this code is executed.  

PASS:		entryType 	= ProfileEntryType
		startEnd	= beg or end 
		reg		= message

DESTROYED:	none

PSEUDO CODE/STRATEGY:

KNOWN BUGS/SIDE EFFECTS/IDEAS:

REVISION HISTORY:
	Name	Date		Description
	----	----		-----------
	IP	10/20/94	Initial version

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
InsertMessageProfileEntry   macro entryType, startEnd, reg
if PROFILE_LOG
	pushf	
	push	ax, cx
if <reg> ne <ax> and <reg> ne <AX>
	mov	ax, reg
endif
	mov	cx, entryType
if <startEnd> ne 0
	or	cx, ProfileEntryBegMask
endif
	call	ProfileWriteMessageEntry
	pop	ax, cx
	popf
endif
endm



COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		InsertMessageProfileEntryDSSI
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SYNOPSIS:	Same as InsertMessageProfileEntry, it takes handle of
		the segment pointed to by ds and puts it's handle in bx.
		This is so ^lbx:si can be stored for the object.

PASS:		entryType 	= ProfileEntryType
		startEnd	= beg or end 
		reg		= message

PSEUDO CODE/STRATEGY:

KNOWN BUGS/SIDE EFFECTS/IDEAS:

REVISION HISTORY:
	Name	Date		Description
	----	----		-----------
	IP	11/16/94   	Initial version

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
InsertMessageProfileEntryDSSI	macro entryType, startEnd, reg
if PROFILE_LOG
	push	bx
	mov	bx, ds:0
	InsertMessageProfileEntry entryType, startEnd, reg
	pop	bx
endif
endm



COMMENT @%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
		InsertProcCallEntry
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SYNOPSIS:	This is used to write a generic entry into the log
		from ProcCallModuleRoutine

PASS:		entryType	= ProfileEntryType
		startEnd	= beg or end 
		profileMode	= ProfileModeFlag associated with this
				  log entry
		data		= 

PSEUDO CODE/STRATEGY:

KNOWN BUGS/SIDE EFFECTS/IDEAS:

REVISION HISTORY:
	Name	Date		Description
	----	----		-----------
	IP	11/17/94   	Initial version

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%@
InsertProcCallEntry   macro entryType, startEnd, profileMode, data
if PROFILE_LOG
	pushf	
	push	ax, bx, cx
	mov	ax, entryType
	mov	bx, mask profileMode
ifnb <data>
	mov	cx, data
endif
if (startEnd eq 1)
	or	ax, ProfileEntryBegMask
endif
	call	ProfileWriteProcCallEntry
	pop	ax, bx, cx
	popf
endif
endm


; 
; Describes the type of this entry.  Each ProfileEntryType is
; associated with one of the ProfileXXXXXEntry structures.  
;
; Deciphering names:
;	OCINL 	= ObjCallInstanceNoLock
;	OCCNL 	= ObjCallClassNoLock
;	OCINLES = ObjCallInstanceNoLockES
;	OCSNL	= ObjCallSuperNoLock
;	OCMT	= ObjCallMethodTable
;	MP	= MessageProcess
;
ProfileEntryType	etype	word, 1, 1
	PET_GENERIC	enum	ProfileEntryType ; ProfileGenericEntry
;
;  This group of entry types is used for tracking messages
;
	PET_OBJMESSAGE	enum	ProfileEntryType ; ProfileMessageEntry
	PET_OCINL	enum	ProfileEntryType ; ProfileMessageEntry
	PET_OCINLES	enum	ProfileEntryType ; ProfileMessageEntry
	PET_OCCNL	enum	ProfileEntryType ; ProfileMessageEntry
	PET_OCSNL	enum	ProfileEntryType ; ProfileMessageEntry
	PET_END_CALL	enum	ProfileEntryType ; ProfileMessageEntry
	PET_MSG_DISCARD	enum	ProfileEntryType ; ProfileMessageEntry
	PET_THREAD_SWITCH enum	ProfileEntryType ; ProfileGenericEntry
	PET_OCMT	enum	ProfileEntryType ; ProfileMessageEntry
	PET_MP		enum	ProfileEntryType ; ProfileGenericEntry
	PET_SEND_EVENT	enum	ProfileEntryType ; ProfileGenericEntry
;
; Used to track heap activity
;
	PET_HEAP	enum	ProfileEntryType ; ProfileGenericEntry
;
; Used to track inter-resource calls
;
	PET_PROC_CALL	enum	ProfileEntryType ; ProfileGenericEntry
;
; Used to track local memory management activity
;
	PET_LMEM	enum    ProfileEntryType ; ProfileGenericEntry
;
; ProfileEntryType + 1 bit to indicate whether this is the start of a
; entry, or the end of a timed section.
;
ProfileLogEntryType	record
	PLET_beg:1			; is this the beg or end record for this type
	PLET_type ProfileEntryType:15	; ProfileLogEntryType
ProfileLogEntryType	end

ProfileLogEntry		struct
	PLE_type	ProfileLogEntryType
	PLE_timeStamp	dword
ProfileLogEntry		ends

ProfileGenericEntry 	struct
	PGE_header	ProfileLogEntry
	PGE_address	fptr
	PGE_data	word
	PGE_thread	word
ProfileGenericEntry 	ends

ProfileMessageEntry 	struct
	PME_header	ProfileLogEntry
	PME_message	word
	PME_thread	word
	PME_address	fptr
	PME_class	fptr
	PME_data	optr
ProfileMessageEntry 	ends

; 
; Because reading and writing from xms memory must be word aligned,
; life is easier if the size of profile entries is also word aligned.
;
CheckHack <((((size ProfileGenericEntry)/2)*2) eq (size ProfileGenericEntry))>
CheckHack <((((size ProfileMessageEntry)/2)*2) eq (size ProfileMessageEntry))>

;
; These flags indicate what profile modes are currently turned on
; Only if the mathcing ProfileModeFlags is turned on, will a log
; entry be written
;
ProfileModeFlags	record
	PMF_GENERIC:1
	PMF_MESSAGE:1
	PMF_HEAP:1
	PMF_PROC_CALL:1
	PMF_LMEM:1
	:3
ProfileModeFlags	end

StartKernel

global	ProfileWriteLogEntry:far
global	ProfileReadLogEntry:far
global	ProfileWriteGenericEntry:far

global	ProfileInit:far
global  ProfileExit:far
global 	ProfileReset:far

EndKernel












