Oolite 1.91.0.7644-241112-7f5034b
Loading...
Searching...
No Matches
OOJSEngineTimeManagement.h
Go to the documentation of this file.
1/*
2
3OOJSEngineTimeManagement.h
4
5Functionality related to time limiting and profiling of JavaScript code.
6
7
8Copyright (C) 2010-2013 Jens Ayton
9
10Permission is hereby granted, free of charge, to any person obtaining a copy
11of this software and associated documentation files (the "Software"), to deal
12in the Software without restriction, including without limitation the rights
13to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14copies of the Software, and to permit persons to whom the Software is
15furnished to do so, subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26SOFTWARE.
27
28*/
29
30
32
33
34/* Time Limiter
35
36 The time limiter stops scripts from running an arbitrarily long time.
37
38 The time limiter must be started before calling into JavaScript code.
39 Calls to OOJSStartTimeLimiter() and OOJSStopTimeLimiter() must be balanced,
40 and may be nested.
41 OOJSStartTimeLimiterWithTimeLimit() is like OOJSStartTimeLimiter(), but
42 specifies a custom time limit. This limit is only used if the limiter is
43 actually stopped.
44
45 The time limiter can be paused and resumed for native operations that are
46 known to be slow. OOJSPauseTimeLimiter() and OOJSResumeTimeLimiter() must
47 be balanced and can be nested, but the nest count may be negative - it is
48 valid to call OOJSResumeTimeLimiter() followed by OOJSPauseTimeLimiter().
49*/
50#define OOJSStartTimeLimiter() OOJSStartTimeLimiterWithTimeLimit(0.0)
51
52#ifndef NDEBUG
53#define OOJSStartTimeLimiterWithTimeLimit(limit) OOJSStartTimeLimiterWithTimeLimit_(limit, OOLOG_FILE_NAME, __LINE__)
54#define OOJSStopTimeLimiter() OOJSStopTimeLimiter_(OOLOG_FILE_NAME, __LINE__)
55void OOJSStartTimeLimiterWithTimeLimit_(OOTimeDelta limit, const char *file, unsigned line);
56void OOJSStopTimeLimiter_(const char *file, unsigned line);
57#else
59void OOJSStopTimeLimiter(void);
60#endif
61
62
63#define kOOJSLongTimeLimit (5.0)
64
65
66#if OOJS_PROFILE
68
69/*
70 Profiling support.
71
72 OOJSBeginProfiling(trace), OOJSEndProfiling(), OOJSIsProfiling()
73 Start, stop, and query profiling mode. It is a hard error to start
74 profiling while already profiling.
75
76 If trace is set, all profileable functions will be logged. The actual
77 profile will be of little use in this case because of logging overhead.
78
79 OOJSCopyTimeLimiterNominalStartTime()
80 Copy the nominal start time for the time limiter. This is the actual time
81 with any time extensions (paused periods) added in.
82
83 OOJSResetTimeLimiter()
84 Set the time limiter start time to now.
85
86 OOJSGetTimeLimiterLimit()
87 OOJSSetTimeLimiterLimit()
88 Manipulate the timeout.
89*/
90
91
93
94
95void OOJSBeginProfiling(BOOL trace);
97BOOL OOJSIsProfiling(void);
98
100
101void OOJSResetTimeLimiter(void);
104
105
106/*
107 NOTE: the profiler declarations that need to be visible to functions that
108 are profiled are found in OOJSEngineNativeWrappers.h.
109*/
110
111
112@interface OOTimeProfile: NSObject
113{
114@private
118#ifdef MOZ_TRACE_JSCALLS
119 double _javaScriptTime;
120#endif
121
123
125}
126
127- (double) totalTime;
128- (double) javaScriptTime;
129- (double) nativeTime;
130- (double) extensionTime;
131- (double) nonExtensionTime;
132- (double) profilerOverhead;
133
134- (NSArray *) profileEntries; // Array of OOTimeProfileEntry
135
136@end
137
138
139@interface OOTimeProfileEntry: NSObject
140{
141@private
142 NSString *_function;
143 unsigned long _hitCount;
148#ifdef MOZ_TRACE_JSCALLS
149 JSFunction *_jsFunction;
150#endif
151}
152
153- (NSString *) description;
154
155- (NSString *) function;
156- (NSUInteger) hitCount;
157- (double) totalTimeSum;
158- (double) selfTimeSum;
159- (double) totalTimeAverage;
160- (double) selfTimeAverage;
161- (double) totalTimeMax;
162- (double) selfTimeMax;
163- (BOOL) isJavaScriptFrame;
164
165- (NSComparisonResult) compareByTotalTime:(OOTimeProfileEntry *)other;
166- (NSComparisonResult) compareByTotalTimeReverse:(OOTimeProfileEntry *)other;
167- (NSComparisonResult) compareBySelfTime:(OOTimeProfileEntry *)other;
168- (NSComparisonResult) compareBySelfTimeReverse:(OOTimeProfileEntry *)other;
169
170@end
171
172#endif
173
174
175@class OOJavaScriptEngine;
176
177void OOJSTimeManagementInit(OOJavaScriptEngine *engine, JSRuntime *runtime);
OOTimeProfile * OOJSEndProfiling(void)
#define OOJSStopTimeLimiter()
void OOJSResetTimeLimiter(void)
BOOL OOJSIsProfiling(void)
void OOJSBeginProfiling(BOOL trace)
OOHighResTimeValue OOJSCopyTimeLimiterNominalStartTime(void)
OOTimeDelta OOJSGetTimeLimiterLimit(void)
void OOJSStartTimeLimiterWithTimeLimit_(OOTimeDelta limit, const char *file, unsigned line)
void OOJSTimeManagementInit(OOJavaScriptEngine *engine, JSRuntime *runtime)
void OOJSStopTimeLimiter_(const char *file, unsigned line)
#define OOJSStartTimeLimiterWithTimeLimit(limit)
void OOJSSetTimeLimiterLimit(OOTimeDelta limit)
uint64_t OOHighResTimeValue
double OOTimeDelta
Definition OOTypes.h:224