-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMrPerformance.cfc
113 lines (86 loc) · 4.02 KB
/
MrPerformance.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<cfcomponent display="Mr. Performance" hint="I track the performance of cacheable operations.">
<cffunction name="init" access="public" returntype="any" output="false">
<cfargument name="DataMgr" type="any" required="true">
<cfargument name="Observer" type="any" required="true">
<cfargument name="autostart" type="boolean" default="true">
<cfset Variables.instance = Arguments>
<cfset Variables.instance.Timer = CreateObject("component","utils.Timer").init(Arguments.DataMgr,Arguments.Observer)>
<cfset Variables.isTracking = false>
<cfif Arguments.autostart>
<cfset startTracking()>
</cfif>
<cfreturn This>
</cffunction>
<cffunction name="isTracking" access="public" returntype="boolean" output="no" hint="I indicate if Mr Performance is currently tracking.">
<cfreturn Variables.isTracking>
</cffunction>
<cffunction name="logRunCacheable" access="public" returntype="any" output="no" hint="I log information about running of cacheable code.">
<cfargument name="id" type="string" required="true">
<cfargument name="RunTime" type="numeric" required="true">
<cfset var sArgs = {time_ms=Arguments.RunTime,name=Arguments.id}>
<cfset var sComp = 0>
<cfif StructKeyExists(Arguments,"Fun")>
<cfset sArgs["Label"] = Arguments.Fun.Metadata.Name>
</cfif>
<cfif StructKeyExists(Arguments,"Component") AND StructKeyExists(Arguments,"MethodName")>
<cfset sComp = getMetaData(Arguments.Component)>
<cfif StructKeyExists(sComp,"DisplayName")>
<cfset sArgs["Label"] = sComp.DisplayName & ": " & Arguments.MethodName>
<cfelse>
<cfset sArgs["Label"] = sComp.Name & "." & Arguments.MethodName>
</cfif>
</cfif>
<!---<cfset Variables.instance.Timer.hearMrECache(Arguments.id,Arguments.RunTime)>--->
<cfset Variables.instance.Timer.logTime(Arguments.RunTime,Arguments.id,sArgs["Label"])>
</cffunction>
<cffunction name="logRunObservable" access="public" returntype="any" output="no" hint="I log information about running of cacheable code.">
<cfargument name="RunTime" type="numeric" required="true">
<cfargument name="ListenerName" type="string" required="true">
<cfset var sArgs = {time_ms=Arguments.RunTime,name=Arguments.ListenerName}>
<cfset var sComp = 0>
<cfif StructKeyExists(Arguments,"Fun")>
<cfset sArgs["Label"] = Arguments.Fun.Metadata.Name>
</cfif>
<cfif StructKeyExists(Arguments,"Component") AND StructKeyExists(Arguments,"MethodName")>
<cfset sComp = getMetaData(Arguments.Component)>
<cfif StructKeyExists(sComp,"DisplayName")>
<cfset sArgs["Label"] = sComp.DisplayName & ": " & Arguments.MethodName>
<cfelse>
<cfset sArgs["Label"] = sComp.Name & "." & Arguments.MethodName>
</cfif>
</cfif>
<cfif StructKeyExists(Arguments,"Args") AND StructCount(Arguments.Args)>
<cfset sArgs.Data = Arguments.Args>
</cfif>
<!---<cfset Variables.instance.Timer.hearMrECache(Arguments.id,Arguments.RunTime)>--->
<cfset Variables.instance.Timer.logTime(ArgumentCollection=sArgs)>
</cffunction>
<cffunction name="startTracking" access="public" returntype="void" output="no" hint="I register a listener with Observer to listen for services being loaded.">
<cfset Variables.isTracking = true>
<cfset Variables.instance.Observer.registerListener(
Listener = This,
ListenerName = "MrPerformance",
ListenerMethod = "logRunCacheable",
EventName = "MrECache:run"
)>
<cfset Variables.instance.Observer.registerListener(
Listener = This,
ListenerName = "MrPerformanceObserv",
ListenerMethod = "logRunObservable",
EventName = "Observer:announceEvent"
)>
</cffunction>
<cffunction name="stopTracking" access="public" returntype="void" output="no" hint="I register a listener with Observer to listen for services being loaded.">
<cfset Variables.isTracking = false>
<cfset Variables.instance.Observer.unregisterListener(
ListenerName = "MrPerformance",
ListenerMethod = "logRunCacheable",
EventName = "MrECache:run"
)>
<cfset Variables.instance.Observer.unregisterListener(
ListenerName = "MrPerformanceObserv",
ListenerMethod = "logRunObservable",
EventName = "Observer:announceEvent"
)>
</cffunction>
</cfcomponent>