Allow starting/stopping jprof from JS (via JProfStartProfiling() and

JProfStopProfiling() global functions).  Bug 112541, patch by dbaron,
r=bzbarsky, sr=jst
This commit is contained in:
bzbarsky%mit.edu 2004-05-11 02:37:25 +00:00
Родитель 5208e259ab
Коммит ffd72b5d74
1 изменённых файлов: 67 добавлений и 0 удалений

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

@ -1675,6 +1675,68 @@ static JSFunctionSpec TraceMallocFunctions[] = {
#endif /* NS_TRACE_MALLOC */ #endif /* NS_TRACE_MALLOC */
#ifdef MOZ_JPROF
#include <signal.h>
inline PRBool
IsJProfAction(struct sigaction *action)
{
return (action->sa_sigaction &&
action->sa_flags == SA_RESTART | SA_SIGINFO);
}
static JSBool
JProfStartProfiling(JSContext *cx, JSObject *obj,
uintN argc, jsval *argv, jsval *rval)
{
// Figure out whether we're dealing with SIGPROF, SIGALRM, or
// SIGPOLL profiling (SIGALRM for JP_REALTIME, SIGPOLL for
// JP_RTC_HZ)
struct sigaction action;
sigaction(SIGALRM, nsnull, &action);
if (IsJProfAction(&action)) {
printf("Beginning real-time jprof profiling.\n");
raise(SIGALRM);
return JS_TRUE;
}
sigaction(SIGPROF, nsnull, &action);
if (IsJProfAction(&action)) {
printf("Beginning process-time jprof profiling.\n");
raise(SIGPROF);
return JS_TRUE;
}
sigaction(SIGPOLL, nsnull, &action);
if (IsJProfAction(&action)) {
printf("Beginning rtc-based jprof profiling.\n");
raise(SIGPOLL);
return JS_TRUE;
}
printf("Could not start jprof-profiling since JPROF_FLAGS was not set.\n");
return JS_TRUE;
}
static JSBool
JProfStopProfiling(JSContext *cx, JSObject *obj,
uintN argc, jsval *argv, jsval *rval)
{
raise(SIGUSR1);
printf("Stopped jprof profiling.\n");
return JS_TRUE;
}
static JSFunctionSpec JProfFunctions[] = {
{"JProfStartProfiling", JProfStartProfiling, 0, 0, 0},
{"JProfStopProfiling", JProfStopProfiling, 0, 0, 0},
{nsnull, nsnull, 0, 0, 0}
};
#endif /* defined(MOZ_JPROF) */
nsresult nsresult
nsJSContext::InitClasses() nsJSContext::InitClasses()
{ {
@ -1705,6 +1767,11 @@ nsJSContext::InitClasses()
::JS_DefineFunctions(mContext, globalObj, TraceMallocFunctions); ::JS_DefineFunctions(mContext, globalObj, TraceMallocFunctions);
#endif #endif
#ifdef MOZ_JPROF
// Attempt to initialize JProf functions
::JS_DefineFunctions(mContext, globalObj, JProfFunctions);
#endif
return rv; return rv;
} }