зеркало из https://github.com/mozilla/pjs.git
bug 382237: make xpctools profiler work, and make it record time spend in the function itself. r=shaver
This commit is contained in:
Родитель
651e03d185
Коммит
51264d2a06
|
@ -147,7 +147,7 @@ xpctools_JSNewScriptHook(JSContext *cx,
|
|||
PR_Lock(self->mLock);
|
||||
|
||||
ProfilerFile* file;
|
||||
if (self->mFileTable.Get(filename, &file))
|
||||
if (!self->mFileTable.Get(filename, &file))
|
||||
{
|
||||
file = new ProfilerFile(filename);
|
||||
if (file)
|
||||
|
@ -212,7 +212,19 @@ xpctools_InterpreterHook(JSContext *cx, JSStackFrame *fp, JSBool before,
|
|||
}
|
||||
else
|
||||
{
|
||||
fun->SetEndTime();
|
||||
PRUint32 delta = fun->SetEndTime();
|
||||
|
||||
JSStackFrame* down = fp->down;
|
||||
if (down) {
|
||||
JSScript* caller = down->script;
|
||||
if (caller) {
|
||||
ProfilerFunction* callfun;
|
||||
if (self->mScriptTable.Get(caller, &callfun))
|
||||
{
|
||||
callfun->AddNotSelfTime(delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -260,6 +272,7 @@ NS_IMETHODIMP nsXPCToolsProfiler::Stop()
|
|||
JS_SetExecuteHook(mRuntime, nsnull, this);
|
||||
JS_SetCallHook(mRuntime, nsnull, this);
|
||||
|
||||
PR_Unlock(mLock);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -295,10 +308,12 @@ xpctools_FunctionNamePrinter(const FunctionID &aKey,
|
|||
(unsigned long) fun->GetTotalSize());
|
||||
if(count != 0)
|
||||
fprintf(out,
|
||||
"{min %lu, max %lu avg %lu}\n",
|
||||
"{min %lu, max %lu, avg %lu, sum %lu, self %lu}\n",
|
||||
(unsigned long) fun->GetQuickTime(),
|
||||
(unsigned long) fun->GetLongTime(),
|
||||
(unsigned long) average);
|
||||
(unsigned long) average,
|
||||
(unsigned long) fun->GetSum(),
|
||||
(unsigned long) fun->GetSelf());
|
||||
else
|
||||
fprintf(out, "\n" );
|
||||
return PL_DHASH_NEXT;
|
||||
|
@ -323,6 +338,8 @@ NS_IMETHODIMP nsXPCToolsProfiler::WriteResults(nsILocalFile *aFile)
|
|||
if(NS_FAILED(aFile->OpenANSIFileDesc("w", &out)) || ! out)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
fprintf(out, "[CompileCount, CallCount] Name {StartLine, EndLine} TotalSize {MinTime, MaxTime, Average, Total, Self}\n\n");
|
||||
|
||||
PR_Lock(mLock);
|
||||
mFileTable.EnumerateRead(xpctools_FilenamePrinter, out);
|
||||
PR_Unlock(mLock);
|
||||
|
|
|
@ -112,15 +112,19 @@ public:
|
|||
return now32;
|
||||
}
|
||||
void SetStartTime() {mStartTime = NowInMilliSecs();}
|
||||
void SetEndTime()
|
||||
PRUint32 SetEndTime()
|
||||
{PRUint32 delta = NowInMilliSecs() - mStartTime;
|
||||
if(delta < mQuickTime)
|
||||
mQuickTime = delta;
|
||||
if (delta > mLongTime)
|
||||
mLongTime = delta;
|
||||
mSum += delta;}
|
||||
mSum += delta;
|
||||
return delta;}
|
||||
PRUint32 GetQuickTime() {return mQuickTime;}
|
||||
PRUint32 GetLongTime() {return mLongTime;}
|
||||
|
||||
void AddNotSelfTime(PRUint32 delta) {mNotSelfSum += delta;}
|
||||
PRUint32 GetSelf() { return mSum - mNotSelfSum;}
|
||||
|
||||
ProfilerFunction(); // not implemented
|
||||
|
||||
|
@ -136,6 +140,7 @@ private:
|
|||
PRUint32 mLongTime; // longest delta in msec
|
||||
PRUint32 mStartTime; // time on enter
|
||||
PRUint32 mSum;
|
||||
PRUint32 mNotSelfSum;
|
||||
};
|
||||
|
||||
struct FunctionID
|
||||
|
|
Загрузка…
Ссылка в новой задаче