Closed Bug 477169 Opened 17 years ago Closed 17 years ago

Add an API to request the time the engine spent executing code for a context

Categories

(Core :: JavaScript Engine, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 477187

People

(Reporter: gal, Assigned: gal)

References

Details

Attachments

(1 file, 3 obsolete files)

No description provided.
Attached patch v1 (obsolete) — — Splinter Review
Blocks: 477179
Attachment #360845 - Attachment is obsolete: true
Blocks: 477187
Attachment #360881 - Flags: review?(brendan)
Comment on attachment 360881 [details] [diff] [review] v2, use unsigned math and clamp to max_ulong >+JS_PUBLIC_API(JSUint64) >+JS_GetElapsedTime(JSContext *cx) >+{ >+ uint64 previous = cx->accumulatedExecutionTime; >+ if (cx->interpLevel) { >+ uint64 diff = PRMJ_Now() - cx->executionStartTime; >+ uint64 accumulated = previous + diff; >+ if (accumulated > previous) >+ return accumulated; >+ return 0xFFFFFFFFFFFFFFFFLL; There is absolutely no reason to clamp: 64 bits holds > 584 megayears' worth of milliseconds. >+ } >+ return previous; >+} >+ >+JS_PUBLIC_API(void) >+JS_ResetElapsedTime(JSContext *cx) >+{ >+ cx->accumulatedExecutionTime = 0; >+} These new APIs fit better in jsdbgapi.{h,cpp}. >diff --git a/js/src/jscntxt.h b/js/src/jscntxt.h >--- a/js/src/jscntxt.h >+++ b/js/src/jscntxt.h >@@ -961,6 +961,17 @@ > uint32 operationLimit : 31; > JSOperationCallback operationCallback; > >+ /* >+ * Timestamp when execution started on this context. >+ */ >+ volatile uint64 executionStartTime; >+ >+ /* >+ * Time elapsed executing JS code using this context (excluding >+ * the current run if code is executing at the moment). >+ */ >+ volatile uint64 accumulatedExecutionTime; >+ > /* Interpreter activation count. */ > uintN interpLevel; If you care only about a thread running JS (no matter on how many contexts -- Gecko uses multiple contexts in the main thread), then the data members should go in JSThread if JS_THREADSAFE, else in JSRuntime. Use JS_CACHE_LOCUS to minimize ifdefs. With this approach, you'll want interpLevel (which is used only in jsscan.cpp, an old and possibly bogus use!) in the cache-locus struct (JSThread or JSRuntime) too. >+ /* >+ * Execution has started on this context, remember the timestamp. >+ */ >+ if (!cx->interpLevel) >+ cx->executionStartTime = PRMJ_Now(); More overhead in js_Interpret, bad on principle (it wasn't the last cookie we ate that made us fat). To avoid this, note that the only js_Interpret calls that could find cx->interpLevel equal to zero would be the calls from js_Execute and js_Invoke. Pushing to the API boundary would give the JS_Evaluate*, JS_Execute*, and JS_Call* APIs. Adding overhead to them is a much better idea. /be
(In reply to comment #3) > (From update of attachment 360881 [details] [diff] [review]) > >+JS_PUBLIC_API(JSUint64) > >+JS_GetElapsedTime(JSContext *cx) > >+{ > >+ uint64 previous = cx->accumulatedExecutionTime; > >+ if (cx->interpLevel) { > >+ uint64 diff = PRMJ_Now() - cx->executionStartTime; > >+ uint64 accumulated = previous + diff; > >+ if (accumulated > previous) > >+ return accumulated; > >+ return 0xFFFFFFFFFFFFFFFFLL; > > There is absolutely no reason to clamp: 64 bits holds > 584 megayears' worth of > milliseconds. Oops, I was thinking of ECMA-262 Date resolution. Still, 584,000+ years is more than enough not to worry about overflow. /be
I think jsapi.cpp is the better place for this. It will be used by the browser and other embeddings for script timeout handling. Thats not really a dbg function I think. I removed the clamping. I still check for diff > 0 in case PRMJ_Now() was called by a different core that is drifting behind us. I think we want to count time elapsed per context. I added executionDepth to track nesting. The cost is now incurred at the API level.
Attachment #360881 - Attachment is obsolete: true
Attachment #360881 - Flags: review?(brendan)
Attachment #360994 - Attachment is obsolete: true
Status: NEW → RESOLVED
Closed: 17 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: