Oolite 1.91.0.7645-241119-222d325
Loading...
Searching...
No Matches
OOJSEngineTimeManagement.h File Reference
+ Include dependency graph for OOJSEngineTimeManagement.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  OOTimeProfile
 
class  OOTimeProfileEntry
 

Macros

#define OOJSStartTimeLimiter()
 
#define OOJSStartTimeLimiterWithTimeLimit(limit)
 
#define OOJSStopTimeLimiter()
 
#define kOOJSLongTimeLimit   (5.0)
 

Functions

void OOJSStartTimeLimiterWithTimeLimit_ (OOTimeDelta limit, const char *file, unsigned line)
 
void OOJSStopTimeLimiter_ (const char *file, unsigned line)
 
void OOJSBeginProfiling (BOOL trace)
 
OOTimeProfileOOJSEndProfiling (void)
 
BOOL OOJSIsProfiling (void)
 
OOHighResTimeValue OOJSCopyTimeLimiterNominalStartTime (void)
 
void OOJSResetTimeLimiter (void)
 
OOTimeDelta OOJSGetTimeLimiterLimit (void)
 
void OOJSSetTimeLimiterLimit (OOTimeDelta limit)
 
void OOJSTimeManagementInit (OOJavaScriptEngine *engine, JSRuntime *runtime)
 

Macro Definition Documentation

◆ kOOJSLongTimeLimit

#define kOOJSLongTimeLimit   (5.0)

Definition at line 63 of file OOJSEngineTimeManagement.h.

◆ OOJSStartTimeLimiter

#define OOJSStartTimeLimiter ( )
Value:
#define OOJSStartTimeLimiterWithTimeLimit(limit)

Definition at line 50 of file OOJSEngineTimeManagement.h.

Referenced by JSFunctionPredicate(), and OOStringFromDeciCredits().

◆ OOJSStartTimeLimiterWithTimeLimit

#define OOJSStartTimeLimiterWithTimeLimit ( limit)
Value:
OOJSStartTimeLimiterWithTimeLimit_(limit, OOLOG_FILE_NAME, __LINE__)
void OOJSStartTimeLimiterWithTimeLimit_(OOTimeDelta limit, const char *file, unsigned line)

Definition at line 53 of file OOJSEngineTimeManagement.h.

Referenced by OOJSFrameCallbacksInvoke().

◆ OOJSStopTimeLimiter

#define OOJSStopTimeLimiter ( )
Value:
OOJSStopTimeLimiter_(OOLOG_FILE_NAME, __LINE__)
void OOJSStopTimeLimiter_(const char *file, unsigned line)

Definition at line 54 of file OOJSEngineTimeManagement.h.

Referenced by JSFunctionPredicate(), OOJSFrameCallbacksInvoke(), and OOStringFromDeciCredits().

Function Documentation

◆ OOJSBeginProfiling()

void OOJSBeginProfiling ( BOOL trace)

Definition at line 311 of file OOJSEngineTimeManagement.m.

312{
313 assert(sProfiling == NO);
314 sProfiling = YES;
315 sTracing = trace;
316 sProfileInfo = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks, NSObjectMapValueCallBacks, 100);
317 sProfilerOverhead = 0.0;
321
322 // This should be last for precision.
324
325 if (trace)
326 {
327 OOLog(@"script.javaScript.trace", @"%@", @">>>> Beginning trace.");
328 OOLogIndent();
329 }
330}
static BOOL sTracing
static double sProfilerTotalNativeTime
static OOHighResTimeValue sProfilerStartTime
static double sProfilerOverhead
OOTimeDelta OOJSGetTimeLimiterLimit(void)
static double sProfilerTotalJavaScriptTime
static double sProfilerEntryTimeLimit
static BOOL sProfiling
static NSMapTable * sProfileInfo
#define OOLog(class, format,...)
Definition OOLogging.h:88
void OOLogIndent(void)
Definition OOLogging.m:366
#define OOGetHighResTime

References OOGetHighResTime, OOJSGetTimeLimiterLimit(), OOLog, OOLogIndent(), sProfileInfo, sProfilerEntryTimeLimit, sProfilerOverhead, sProfilerStartTime, sProfilerTotalJavaScriptTime, sProfilerTotalNativeTime, sProfiling, and sTracing.

Referenced by Entity(OODebugInspector)::inspect.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOJSCopyTimeLimiterNominalStartTime()

OOHighResTimeValue OOJSCopyTimeLimiterNominalStartTime ( void )

Definition at line 158 of file OOJSEngineTimeManagement.m.

159{
160 return sLimiterStart;
161}
static OOHighResTimeValue sLimiterStart

References sLimiterStart.

◆ OOJSEndProfiling()

OOTimeProfile * OOJSEndProfiling ( void )

Definition at line 333 of file OOJSEngineTimeManagement.m.

334{
335 // This should be at the top for precision.
337 // Time limiter should be as close to outermost as practical.
339
340 assert(sProfiling && sProfileStack == NULL);
341
342 sProfiling = NO;
343
344 OOTimeProfile *result = [[OOTimeProfile alloc] init];
345
346 [result setTotalTime:OOHighResTimeDeltaInSeconds(sProfilerStartTime, now)];
347 [result setNativeTime:sProfilerTotalNativeTime];
348#ifdef MOZ_TRACE_JSCALLS
349 [result setJavaScriptTime:sProfilerTotalJavaScriptTime];
350#endif
351 [result setProfilerOverhead:sProfilerOverhead];
352
353 double currentTimeLimit = OOJSGetTimeLimiterLimit();
354 [result setExtensionTime:currentTimeLimit - sProfilerEntryTimeLimit];
355
356 [result setProfileEntries:[NSAllMapTableValues(sProfileInfo) sortedArrayUsingSelector:@selector(compareBySelfTimeReverse:)]];
357
358 if (sTracing)
359 {
360 OOLogOutdent();
361 OOLog(@"script.javaScript.trace", @"%@", @"<<<< End of trace.");
362 sTracing = NO;
363 }
364
365 // Clean up.
366 NSFreeMapTable(sProfileInfo);
368
370
372 return result;
373}
void OOJSPauseTimeLimiter(void)
static OOJSProfileStackFrame * sProfileStack
void OOJSResumeTimeLimiter(void)
void OOLogOutdent(void)
Definition OOLogging.m:376
OOTimeDelta OOHighResTimeDeltaInSeconds(OOHighResTimeValue startTime, OOHighResTimeValue endTime)
uint64_t OOHighResTimeValue
#define OODisposeHighResTime(time)

References OODisposeHighResTime, OOGetHighResTime, OOJSGetTimeLimiterLimit(), OOJSPauseTimeLimiter(), OOJSResumeTimeLimiter(), OOLog, OOLogOutdent(), OOTimeProfile::setExtensionTime:, OOTimeProfile::setNativeTime:, OOTimeProfile::setProfileEntries:, OOTimeProfile::setProfilerOverhead:, OOTimeProfile::setTotalTime:, sProfileInfo, sProfilerStartTime, sProfileStack, sProfiling, and sTracing.

Referenced by Entity(OODebugInspector)::inspect.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ OOJSGetTimeLimiterLimit()

OOTimeDelta OOJSGetTimeLimiterLimit ( void )

Definition at line 173 of file OOJSEngineTimeManagement.m.

174{
175 return sLimiterTimeLimit;
176}
static double sLimiterTimeLimit

References sLimiterTimeLimit.

Referenced by Entity(OODebugInspector)::inspect, OOJSBeginProfiling(), and OOJSEndProfiling().

+ Here is the caller graph for this function:

◆ OOJSIsProfiling()

BOOL OOJSIsProfiling ( void )

Definition at line 376 of file OOJSEngineTimeManagement.m.

377{
378 return sProfiling;
379}

References sProfiling.

Referenced by ConsoleGetProfile(), ConsoleProfile(), and ConsoleTrace().

+ Here is the caller graph for this function:

◆ OOJSResetTimeLimiter()

void OOJSResetTimeLimiter ( void )

Definition at line 164 of file OOJSEngineTimeManagement.m.

165{
168
169 sStop = NO;
170}
static BOOL sStop

References OODisposeHighResTime, OOGetHighResTime, sLimiterStart, and sStop.

Referenced by Entity(OODebugInspector)::inspect.

+ Here is the caller graph for this function:

◆ OOJSSetTimeLimiterLimit()

void OOJSSetTimeLimiterLimit ( OOTimeDelta limit)

Definition at line 179 of file OOJSEngineTimeManagement.m.

180{
181 sLimiterTimeLimit = limit;
182}

References sLimiterTimeLimit.

Referenced by Entity(OODebugInspector)::inspect.

+ Here is the caller graph for this function:

◆ OOJSStartTimeLimiterWithTimeLimit_()

void OOJSStartTimeLimiterWithTimeLimit_ ( OOTimeDelta limit,
const char * file,
unsigned line )

Definition at line 82 of file OOJSEngineTimeManagement.m.

86{
87#if OOJS_DEBUG_LIMITER
88 OOLog(@"script.javaScript.timeLimit.debug",@"Limiter starting: %u => %u",sLimiterStartDepth,sLimiterStartDepth+1);
89#endif
90 if (sLimiterStartDepth++ == 0)
91 {
92 if (limit <= 0.0) limit = OOJS_TIME_LIMIT;
93 sLimiterTimeLimit = limit;
95
98 }
99
100#ifndef NDEBUG
101 sLastStartedFile = file;
102 sLastStartedLine = line;
103#endif
104}
#define OOJS_TIME_LIMIT
static const char * sLastStartedFile
static int sLimiterPauseDepth
static unsigned sLimiterStartDepth
static unsigned sLastStartedLine

References OODisposeHighResTime, OOGetHighResTime, OOJS_TIME_LIMIT, OOLog, sLastStartedFile, sLastStartedLine, sLimiterPauseDepth, sLimiterStart, sLimiterStartDepth, and sLimiterTimeLimit.

◆ OOJSStopTimeLimiter_()

void OOJSStopTimeLimiter_ ( const char * file,
unsigned line )

Definition at line 108 of file OOJSEngineTimeManagement.m.

112{
113#ifndef NDEBUG
114 if (sLimiterStartDepth == 0)
115 {
116 OOLog(@"bug.javaScript.limiterDepth", @"Attempt to stop JavaScript time limiter while it is already fully stopped. This is an internal bug, please report it. (Last start: %@:%u, last valid stop: %@:%u, this stop attempt: %@:%u.)", OOLogAbbreviatedFileName(sLastStartedFile), sLastStartedLine, OOLogAbbreviatedFileName(sLastStoppedFile), sLastStoppedLine, OOLogAbbreviatedFileName(file), line);
117 return;
118 }
119
120 sLastStoppedFile = file;
121 sLastStoppedLine = line;
122
123#if OOJS_DEBUG_LIMITER
124 OOLog(@"script.javaScript.timeLimit.debug",@"Limiter ending: %u <= %u",sLimiterStartDepth-1,sLimiterStartDepth);
125#endif
126
127#endif
128
129 if (--sLimiterStartDepth == 0) sLimiterTimeLimit = 0.0;
130}
static unsigned sLastStoppedLine
static const char * sLastStoppedFile
NSString * OOLogAbbreviatedFileName(const char *inName)
Definition OOLogging.m:839

References OOLog, OOLogAbbreviatedFileName(), sLastStartedFile, sLastStartedLine, sLastStoppedFile, sLastStoppedLine, sLimiterStartDepth, and sLimiterTimeLimit.

+ Here is the call graph for this function:

◆ OOJSTimeManagementInit()

void OOJSTimeManagementInit ( OOJavaScriptEngine * engine,
JSRuntime * runtime )

Definition at line 254 of file OOJSEngineTimeManagement.m.

255{
256 [NSThread detachNewThreadSelector:@selector(watchdogTimerThread)
257 toTarget:engine
258 withObject:nil];
259
260 JS_SetContextCallback(runtime, ContextCallback);
261}
static JSBool ContextCallback(JSContext *context, uintN contextOp)
return nil

References ContextCallback().

+ Here is the call graph for this function: