Add support to JS profiler for collecting min, max, and average execution

times of functions. Doesn't yet handle rentrancy. Create Makefile.in files
so this stuff will build on *nix. r=jband, a=leaf
This commit is contained in:
syd%netscape.com 2000-07-13 05:19:22 +00:00
Родитель d7f5403698
Коммит dacf41392f
8 изменённых файлов: 235 добавлений и 12 удалений

Просмотреть файл

@ -180,7 +180,7 @@ JSJAVA_CFLAGS = \
include $(topsrcdir)/config/rules.mk
DEFINES += -DEXPORT_JS_API
DEFINES += -DEXPORT_JS_API
INCLUDES += -I$(srcdir)

Просмотреть файл

@ -44,5 +44,10 @@ ifdef ENABLE_TESTS
DIRS += tests shell
endif
ifdef MOZ_XPC_TOOLS_SUPPORT
DIRS += tools
endif
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -89,5 +89,9 @@ EXTRA_DSO_LDOPTS += \
include $(topsrcdir)/config/rules.mk
DEFINES += -DJSFILE -DJS_THREADSAFE
DEFINES += -DJSFILE -DJS_THREADSAFE
ifdef MOZ_XPC_TOOLS_SUPPORT
DEFINES += -DXPC_TOOLS_SUPPORT
endif

Просмотреть файл

@ -0,0 +1,44 @@
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is Mozilla Communicator client code, released
# March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the
# terms of the GNU Public License (the "GPL"), in which case the
# provisions of the GPL are applicable instead of those above.
# If you wish to allow use of your version of this file only
# under the terms of the GPL and not to allow others to use your
# version of this file under the NPL, indicate your decision by
# deleting the provisions above and replace them with the notice
# and other provisions required by the GPL. If you do not delete
# the provisions above, a recipient may use your version of this
# file under either the NPL or the GPL.
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = idl src
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,48 @@
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is Mozilla Communicator client code, released
# March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1999 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the
# terms of the GNU Public License (the "GPL"), in which case the
# provisions of the GPL are applicable instead of those above.
# If you wish to allow use of your version of this file only
# under the terms of the GPL and not to allow others to use your
# version of this file under the NPL, indicate your decision by
# deleting the provisions above and replace them with the notice
# and other provisions required by the GPL. If you do not delete
# the provisions above, a recipient may use your version of this
# file under either the NPL or the GPL.
#
DEPTH = ../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xpctools
XPIDLSRCS = \
nsIXPCToolsCompiler.idl \
nsIXPCToolsProfiler.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,72 @@
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is Mozilla Communicator client code, released
# March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# John Bandhauer <jband@netscape.com>
#
# Alternatively, the contents of this file may be used under the
# terms of the GNU Public License (the "GPL"), in which case the
# provisions of the GPL are applicable instead of those above.
# If you wish to allow use of your version of this file only
# under the terms of the GPL and not to allow others to use your
# version of this file under the NPL, indicate your decision by
# deleting the provisions above and replace them with the notice
# and other provisions required by the GPL. If you do not delete
# the provisions above, a recipient may use your version of this
# file under either the NPL or the GPL.
#
DEPTH = ../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xpctools
LIBRARY_NAME = xpctools
SHORT_LIBNAME = xpctools
CPPSRCS = \
nsXPCToolsCompiler.o \
nsXPCToolsProfiler.o \
nsXPCToolsModule.o \
$(NULL)
include $(topsrcdir)/config/config.mk
IS_COMPONENT = 1
# this is automatically discovered under BeOS
ifneq ($(OS_ARCH),BeOS)
LIBS += \
$(MOZ_JS_LIBS) \
$(MOZ_COMPONENT_LIBS) \
$(NULL)
endif
EXTRA_DSO_LDOPTS += \
$(MOZ_COMPONENT_LIBS) \
$(MOZ_JS_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk
DEFINES += -DJSFILE -DJS_THREADSAFE

Просмотреть файл

@ -111,7 +111,11 @@ ProfilerFunction::ProfilerFunction(const char* name,
mLineExtent(extent),
mFile(file),
mCallCount(0),
mCompileCount(0)
mCompileCount(0),
mQuickTime((PRUint32) -1),
mLongTime(0),
mStartTime(0),
mSum(0)
{
// empty
}
@ -241,7 +245,6 @@ xpctools_InterpreterHook(JSContext *cx, JSStackFrame *fp, JSBool before,
JSBool *ok, void *closure)
{
// ignore returns
NS_ASSERTION(before, "engine should not do this cuz we return nsnull!");
NS_ASSERTION(fp, "bad frame pointer!");
JSScript* script = fp->script;
@ -255,10 +258,20 @@ xpctools_InterpreterHook(JSContext *cx, JSStackFrame *fp, JSBool before,
ProfilerFunction* fun =
(ProfilerFunction*) self->mScriptTable->Get(&scriptkey);
if(fun)
fun->IncrementCallCount();
{
if(before == PR_TRUE)
{
fun->IncrementCallCount();
fun->SetStartTime();
}
else
{
fun->SetEndTime();
}
}
}
}
return nsnull;
return closure;
}
/***************************************************************************/
@ -308,15 +321,29 @@ xpctools_FuncionNamePrinter(nsHashKey *aKey, void *aData, void* closure)
ProfilerFunction* fun = (ProfilerFunction*) aData;
FILE* out = (FILE*) closure;
const char* name = fun->GetName();
PRUint32 average;
PRUint32 count;
count = fun->GetCallCount();
if (count != 0)
average = fun->GetSum() / count;
if(!name)
name = "<top level>";
fprintf(out,
" [%lu,%lu] %s() {%d-%d}\n",
(unsigned long) fun->GetCompileCount(),
(unsigned long) fun->GetCallCount(),
name,
(int) fun->GetBaseLineNumber(),
(int)(fun->GetBaseLineNumber()+fun->GetLineExtent()-1));
" [%lu,%lu] %s() {%d-%d} ",
(unsigned long) fun->GetCompileCount(),
(unsigned long) fun->GetCallCount(),
name,
(int) fun->GetBaseLineNumber(),
(int)(fun->GetBaseLineNumber()+fun->GetLineExtent()-1));
if(count != 0)
fprintf(out,
"{min %lu, max %lu avg %lu}\n",
(unsigned long) fun->GetQuickTime(),
(unsigned long) fun->GetLongTime(),
(unsigned long) average);
else
fprintf(out, "\n" );
return PR_TRUE;
}

Просмотреть файл

@ -52,6 +52,7 @@
#include "jsapi.h"
#include "jshash.h"
#include "jsprf.h"
#include "jslong.h"
#include "jsinterp.h"
#include "jscntxt.h"
#include "jsdbgapi.h"
@ -114,8 +115,26 @@ public:
uintN GetLineExtent() const {return mLineExtent;}
void IncrementCallCount() {++mCallCount;}
PRUint32 GetCallCount() {return mCallCount;}
PRUint32 GetSum() {return mSum;}
void IncrementCompileCount() {++mCompileCount;}
PRUint32 GetCompileCount() {return mCompileCount;}
PRUint32 NowInMilliSecs()
{PRUint64 now64;
PRUint32 now32;
JSLL_DIV(now64,PR_Now(),JSLL_INIT(0,1000));
JSLL_L2UI(now32, now64);
return now32;
}
void SetStartTime() {mStartTime = NowInMilliSecs();}
void SetEndTime()
{PRUint32 delta = NowInMilliSecs() - mStartTime;
if(delta < mQuickTime)
mQuickTime = delta;
if (delta > mLongTime)
mLongTime = delta;
mSum += delta;}
PRUint32 GetQuickTime() {return mQuickTime;}
PRUint32 GetLongTime() {return mLongTime;}
ProfilerFunction(); // not implemented
@ -126,6 +145,10 @@ private:
ProfilerFile* mFile;
PRUint32 mCallCount;
PRUint32 mCompileCount;
PRUint32 mQuickTime; // quickest delta in msec
PRUint32 mLongTime; // longest delta in msec
PRUint32 mStartTime; // time on enter
PRUint32 mSum;
};