Created
September 9, 2012 14:11
-
-
Save edwardbeckett/3684571 to your computer and use it in GitHub Desktop.
Stupid Tracer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- | |
User: Edward | |
Date: 9/7/12 | |
Time: 3:01 PM | |
@TODO: Finish this silly example ... | |
---> | |
<cfcomponent output="false"> | |
<cfscript> | |
variables.instance = {}; | |
</cfscript> | |
<cffunction name="init" access="public" returntype="StupidTracer" hint="I return an Instance of a Stupid Tracer." output="false" > | |
<cfreturn this /> | |
</cffunction> | |
<cffunction name="Start" access="public" returntype="any" output="false" hint="I'm the incrementer ..." > | |
<cfargument name="TraceTo" required="true" type="string" /> | |
<cfset variables.instance.TraceTo = JavaCast('int',arguments.TraceTo)> | |
<cfset TraceThis(run = 1) /> | |
<cfreturn this /> | |
</cffunction> | |
<cffunction name="getStartTime" access="public" output="true" returntype="string" hint="I Get the Start Time"> | |
<cfreturn variables.instance.TraceLog.Time.Start['Timer'] /> | |
</cffunction> | |
<cffunction name="getStopTime" access="public" output="true" returntype="string" hint="I get stopped time."> | |
<cfreturn variables.instance.TraceLog.Time.Finish['Timer']> | |
</cffunction> | |
<cffunction name="getTraceLogDiff" access="public" output="true" returntype="any" hint="I get the TraceLog"> | |
<cfreturn variables.instance.TraceLog.Time.Diff['Run Time']> | |
</cffunction> | |
<cffunction name="TraceThis" access="public" returntype="any" output="false" hint="I'm the tracer"> | |
<cfargument name="run" required="true" type="boolean" /> | |
<cfset variables.instance.run = arguments.run> | |
<cfscript> | |
if(variables.instance.run is 1) { | |
variables.instance.TraceLog = {}; | |
variables.instance.TraceLog.Itterations = { | |
'Itterations' = variables.instance.TraceTo | |
}; | |
variables.instance.TraceLog.Time = { | |
'Time' = '' | |
}; | |
variables.instance.TraceLog.Time.Start = { | |
'Start' = timeFormat(now(),'h:mm:s:L'), | |
'Timer' = getTickCount() | |
}; | |
variables.instance.tempDir = getDirectoryFromPath(getCurrentTemplatePath()) & 'tmp/'; | |
variables.instance.date_stamp_filname = ReReplace(timeFormat(now(),'l'),':','_','all'); | |
variables.instance.TraceLogFile = 'StupidTracer' & '_' & variables.instance.date_stamp_filname & '.log'; | |
local = {}; | |
local.tempDir = variables.instance.tempDir; | |
local.logFile = variables.instance.TraceLogFile; | |
try { | |
FileWrite(#local.tempDir# & #local.logFile#, 'TraceLog for :' & #variables.instance.TraceLogFile# & chr(13)); | |
} | |
catch (any error){ | |
WriteOutput('Warning: ' & error.message); | |
} | |
finally { | |
writeOutput(local.logFile & " was created @ " & timeFormat(now(),'h:mm:s:L') & '<br />'); | |
} | |
for(i =1; i < variables.instance.TraceTo; i ++ ) { | |
structUpdate(variables.instance.TraceLog.Itterations,'Itterations', [i]); | |
structUpdate(variables.instance.TraceLog.Time,'Time', timeFormat(now(),'h:mm:s:L')); | |
// We should have a updated records now ... | |
saveContent variable='TraceLogFile' { | |
WriteOutPut('Itteration ' & '#i#' & ' Ran @ ' & variables.instance.TraceLog.Time['Time'] & chr(13)); | |
} | |
WriteOutPut('Itteration ' & '#i#' & ' Ran @ ' & variables.instance.TraceLog.Time['Time'] & '<br />'); | |
// Now let's update the logfile ... | |
local.logFileData = FileOpen(local.tempDir & local.logFile,'append'); | |
FileWrite(local.logFileData,'#TraceLogFile#'); | |
FileClose(local.logFileData); | |
} | |
variables.instance.TraceLog.Time.Finish = { | |
'Finish' = timeFormat(now(),'h:mm:s:L'), | |
'Timer' = getTickCount() | |
}; | |
local.start = variables.instance.TraceLog.Time.Start['Start']; | |
local.finish = variables.instance.TraceLog.Time.Finish['Finish']; | |
local.diff = variables.instance.TraceLog.Time.Finish['Timer'] - variables.instance.TraceLog.Time.Start['Timer']; | |
variables.instance.TraceLog.Time.Diff = { | |
'Run Time' = local.diff | |
}; | |
}; | |
</cfscript> | |
<cfreturn this /> | |
</cffunction> | |
</cfcomponent> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment