Bug 444023, Add JS functions to stop/start callgrind, r=sayrer

This commit is contained in:
Graydon Hoare 2008-07-08 15:58:08 -07:00
parent d2f545575d
commit 7c4aa69e9d
10 changed files with 115 additions and 3 deletions

View File

@ -103,6 +103,7 @@ MOZ_LEAKY = @MOZ_LEAKY@
MOZ_MEMORY = @MOZ_MEMORY@ MOZ_MEMORY = @MOZ_MEMORY@
MOZ_JPROF = @MOZ_JPROF@ MOZ_JPROF = @MOZ_JPROF@
MOZ_SHARK = @MOZ_SHARK@ MOZ_SHARK = @MOZ_SHARK@
MOZ_CALLGRIND = @MOZ_CALLGRIND@
DEHYDRA_PATH = @DEHYDRA_PATH@ DEHYDRA_PATH = @DEHYDRA_PATH@
MOZ_XPCTOOLS = @MOZ_XPCTOOLS@ MOZ_XPCTOOLS = @MOZ_XPCTOOLS@

View File

@ -6409,6 +6409,17 @@ if test -n "$MOZ_SHARK"; then
AC_DEFINE(MOZ_SHARK) AC_DEFINE(MOZ_SHARK)
fi fi
dnl ========================================================
dnl callgrind
dnl ========================================================
MOZ_ARG_ENABLE_BOOL(callgrind,
[ --enable-callgrind Enable callgrind profiling],
MOZ_CALLGRIND=1,
MOZ_CALLGRIND= )
if test -n "$MOZ_CALLGRIND"; then
AC_DEFINE(MOZ_CALLGRIND)
fi
dnl ======================================================== dnl ========================================================
dnl = Enable static checking using gcc-dehydra dnl = Enable static checking using gcc-dehydra
dnl ======================================================== dnl ========================================================
@ -7801,6 +7812,7 @@ AC_SUBST(MOZ_LOG_REFCNT)
AC_SUBST(MOZ_LEAKY) AC_SUBST(MOZ_LEAKY)
AC_SUBST(MOZ_JPROF) AC_SUBST(MOZ_JPROF)
AC_SUBST(MOZ_SHARK) AC_SUBST(MOZ_SHARK)
AC_SUBST(MOZ_CALLGRIND)
AC_SUBST(MOZ_XPCTOOLS) AC_SUBST(MOZ_XPCTOOLS)
AC_SUBST(MOZ_JSLOADER) AC_SUBST(MOZ_JSLOADER)
AC_SUBST(MOZ_USE_NATIVE_UCONV) AC_SUBST(MOZ_USE_NATIVE_UCONV)

View File

@ -3107,6 +3107,15 @@ static JSFunctionSpec SharkFunctions[] = {
}; };
#endif #endif
#ifdef MOZ_CALLGRIND
static JSFunctionSpec CallgrindFunctions[] = {
{"startCallgrind", js_StartCallgrind, 0, 0, 0},
{"stopCallgrind", js_StopCallgrind, 0, 0, 0},
{"dumpCallgrind", js_DumpCallgrind, 1, 0, 0},
{nsnull, nsnull, 0, 0, 0}
};
#endif
nsresult nsresult
nsJSContext::InitClasses(void *aGlobalObj) nsJSContext::InitClasses(void *aGlobalObj)
{ {
@ -3144,6 +3153,11 @@ nsJSContext::InitClasses(void *aGlobalObj)
::JS_DefineFunctions(mContext, globalObj, SharkFunctions); ::JS_DefineFunctions(mContext, globalObj, SharkFunctions);
#endif #endif
#ifdef MOZ_CALLGRIND
// Attempt to initialize Callgrind functions
::JS_DefineFunctions(mContext, globalObj, CallgrindFunctions);
#endif
JSOptionChangedCallback(js_options_dot_str, this); JSOptionChangedCallback(js_options_dot_str, this);
return rv; return rv;

View File

@ -94,6 +94,9 @@ DEFINES += -DMOZ_SHARK
CFLAGS += -F/System/Library/PrivateFrameworks CFLAGS += -F/System/Library/PrivateFrameworks
LDFLAGS += -F/System/Library/PrivateFrameworks -framework CHUD LDFLAGS += -F/System/Library/PrivateFrameworks -framework CHUD
endif endif
ifdef MOZ_CALLGRIND
DEFINES += -DMOZ_CALLGRIND
endif
ifndef NO_LIBM ifndef NO_LIBM
LDFLAGS += -lm LDFLAGS += -lm

View File

@ -2824,6 +2824,11 @@ static JSFunctionSpec shell_functions[] = {
JS_FS("connectShark", js_ConnectShark, 0,0,0), JS_FS("connectShark", js_ConnectShark, 0,0,0),
JS_FS("disconnectShark", js_DisconnectShark, 0,0,0), JS_FS("disconnectShark", js_DisconnectShark, 0,0,0),
#endif #endif
#ifdef MOZ_CALLGRIND
JS_FS("startCallgrind", js_StartCallgrind, 0,0,0),
JS_FS("stopCallgrind", js_StopCallgrind, 0,0,0),
JS_FS("dumpCallgrind", js_DumpCallgrind, 1,0,0),
#endif
#ifdef DEBUG_ARRAYS #ifdef DEBUG_ARRAYS
JS_FS("arrayInfo", js_ArrayInfo, 1,0,0), JS_FS("arrayInfo", js_ArrayInfo, 1,0,0),
#endif #endif
@ -2901,6 +2906,11 @@ static const char *const shell_help_messages[] = {
" The -k switch does this automatically.", " The -k switch does this automatically.",
"disconnectShark() Disconnect from Shark.", "disconnectShark() Disconnect from Shark.",
#endif #endif
#ifdef MOZ_CALLGRIND
"startCallgrind() Start callgrind instrumentation.\n",
"stopCallgrind() Stop callgrind instumentation.",
"dumpCallgrind() Dump callgrind counters.\n",
#endif
#ifdef DEBUG_ARRAYS #ifdef DEBUG_ARRAYS
"arrayInfo(a1, a2, ...) Report statistics about arrays.", "arrayInfo(a1, a2, ...) Report statistics about arrays.",
#endif #endif

View File

@ -1799,3 +1799,47 @@ js_DisconnectShark(JSContext *cx, JSObject *obj,
} }
#endif /* MOZ_SHARK */ #endif /* MOZ_SHARK */
#ifdef MOZ_CALLGRIND
#include <valgrind/callgrind.h>
JS_FRIEND_API(JSBool)
js_StartCallgrind(JSContext *cx, JSObject *obj,
uintN argc, jsval *argv, jsval *rval)
{
CALLGRIND_START_INSTRUMENTATION;
CALLGRIND_ZERO_STATS;
return JS_TRUE;
}
JS_FRIEND_API(JSBool)
js_StopCallgrind(JSContext *cx, JSObject *obj,
uintN argc, jsval *argv, jsval *rval)
{
CALLGRIND_STOP_INSTRUMENTATION;
return JS_TRUE;
}
JS_FRIEND_API(JSBool)
js_DumpCallgrind(JSContext *cx, JSObject *obj,
uintN argc, jsval *argv, jsval *rval)
{
JSString *str;
char *cstr;
if (argc > 0 && JSVAL_IS_STRING(argv[0])) {
str = JSVAL_TO_STRING(argv[0]);
cstr = js_DeflateString(cx, JSSTRING_CHARS(str), JSSTRING_LENGTH(str));
if (cstr) {
CALLGRIND_DUMP_STATS_AT(cstr);
JS_free(cx, cstr);
return JS_TRUE;
}
}
CALLGRIND_DUMP_STATS;
return JS_TRUE;
}
#endif /* MOZ_CALLGRIND */

View File

@ -459,6 +459,22 @@ js_DisconnectShark(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
#endif /* MOZ_SHARK */ #endif /* MOZ_SHARK */
#ifdef MOZ_CALLGRIND
extern JS_FRIEND_API(JSBool)
js_StopCallgrind(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval);
extern JS_FRIEND_API(JSBool)
js_StartCallgrind(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval);
extern JS_FRIEND_API(JSBool)
js_DumpCallgrind(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval);
#endif /* MOZ_CALLGRIND */
JS_END_EXTERN_C JS_END_EXTERN_C
#endif /* jsdbgapi_h___ */ #endif /* jsdbgapi_h___ */

View File

@ -83,7 +83,7 @@
#include "prmem.h" #include "prmem.h"
#include "plbase64.h" #include "plbase64.h"
#ifdef MOZ_SHARK #if defined(MOZ_SHARK) || defined(MOZ_CALLGRIND)
#include "jsdbgapi.h" #include "jsdbgapi.h"
#endif #endif
@ -281,6 +281,11 @@ static JSFunctionSpec gGlobalFun[] = {
{"stopShark", js_StopShark, 0,0,0}, {"stopShark", js_StopShark, 0,0,0},
{"connectShark", js_ConnectShark, 0,0,0}, {"connectShark", js_ConnectShark, 0,0,0},
{"disconnectShark", js_DisconnectShark,0,0,0}, {"disconnectShark", js_DisconnectShark,0,0,0},
#endif
#ifdef MOZ_CALLGRIND
{"startCallgrind", js_StartCallgrind, 0,0,0},
{"stopCallgrind", js_StopCallgrind, 0,0,0},
{"dumpCallgrind", js_DumpCallgrind, 1,0,0},
#endif #endif
{nsnull,nsnull,0,0,0} {nsnull,nsnull,0,0,0}
}; };

View File

@ -74,7 +74,9 @@ DEFINES += -DMOZ_SHARK
CFLAGS += -F/System/Library/PrivateFrameworks CFLAGS += -F/System/Library/PrivateFrameworks
LDFLAGS += -F/System/Library/PrivateFrameworks -framework CHUD LDFLAGS += -F/System/Library/PrivateFrameworks -framework CHUD
endif endif
ifdef MOZ_CALLGRIND
DEFINES += -DMOZ_CALLGRIND
endif
# #
# Line editing support. If your OS supplies the readline library, define # Line editing support. If your OS supplies the readline library, define
# JS_READLINE to get line editing in the xpcshell. # JS_READLINE to get line editing in the xpcshell.

View File

@ -84,7 +84,7 @@
#include "nsIJSContextStack.h" #include "nsIJSContextStack.h"
#ifdef MOZ_SHARK #if defined(MOZ_SHARK) || defined(MOZ_CALLGRIND)
#include "jsdbgapi.h" #include "jsdbgapi.h"
#endif #endif
@ -438,6 +438,11 @@ static JSFunctionSpec glob_functions[] = {
{"stopShark", js_StopShark, 0,0,0}, {"stopShark", js_StopShark, 0,0,0},
{"connectShark", js_ConnectShark, 0,0,0}, {"connectShark", js_ConnectShark, 0,0,0},
{"disconnectShark", js_DisconnectShark, 0,0,0}, {"disconnectShark", js_DisconnectShark, 0,0,0},
#endif
#ifdef MOZ_CALLGRIND
{"startCallgrind", js_StartCallgrind, 0,0,0},
{"stopCallgrind", js_StopCallgrind, 0,0,0},
{"dumpCallgrind", js_DumpCallgrind, 1,0,0},
#endif #endif
{nsnull,nsnull,0,0,0} {nsnull,nsnull,0,0,0}
}; };