Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Profile an Application

Keywords: 	  profiler  application profiling

;-------------------------------------------------------------------------
; Application Profiling SetUp
;

DataPoints = 3
DataPointNames = "Sub1,Sub2,Sub3"
ProfileDataFile = "C:\Profile.csv"
gosub InitProfiler

;-------------------------------------------------------------------------
; Program to be Profiled Begins Here
;

gosub Sub1
gosub WriteProfileData   ;don't forget this before you exit
exit

:Sub1
	DataPoint = 1
	gosub ProfileOn

	for i = 1 to 3
		TimeDelay(0.1)

		DataPoint = 1
		gosub ProfileOff
		gosub Sub2
		DataPoint = 1
		gosub ProfileOn

		TimeDelay(0.1)
	next

	DataPoint = 1
	gosub ProfileOff
return

:Sub2
	DataPoint = 2
	gosub ProfileOn

	TimeDelay(0.2)

	DataPoint = 2
	gosub ProfileOff
	gosub Sub3
	DataPoint = 2
	gosub ProfileOn

	TimeDelay(0.2)

	DataPoint = 2
	gosub ProfileOff
return

:Sub3
	DataPoint = 3
	gosub ProfileOn

	TimeDelay(0.6)

	DataPoint = 3
	gosub ProfileOff
return

;-------------------------------------------------------------------------
; Application Profiling Support Routines
;

:InitProfiler
	DataPointT = ""
	DataPointE = ""
	for i = 1 to DataPoints
		if i == 1
			DataPointT = StrCat(0)
			DataPointE = StrCat(0)
		else
			DataPointT = StrCat(DataPointT, ",", 0)
			DataPointE = StrCat(DataPointE, ",", 0)
		endif
	next
return

:ProfileOn
	tics = GetTickCount()
	DataPointT = ItemRemove(DataPoint, DataPointT, ",")
	DataPointT = ItemInsert(tics, DataPoint - 1, DataPointT, ",")
return

:ProfileOff
	tics = GetTickCount()
	et = ItemExtract(DataPoint, DataPointE, ",")
	t2 = ItemExtract(DataPoint, DataPointT, ",")
	et = tics - t2 + et
	DataPointE = ItemRemove(DataPoint, DataPointE, ",")
	DataPointE = ItemInsert(et, DataPoint - 1, DataPointE, ",")
return

:WriteProfileData
	hprof = FileOpen(ProfileDataFile, "WRITE")
	FileWrite(hprof, DataPointNames)
	FileWrite(hprof, DataPointE)
	FileClose(hprof)
	Message("Profile", "Profile data written to%@CRLF%%@CRLF%%ProfileDataFile%")
return


Article ID:   W14957