WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

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
File Created: 2001:11:08:12:41:08
Last Updated: 2001:11:08:12:41:08