Bug 925621 - Let startProfiling take a pid so the content process can be profiled. r=sfink

This commit is contained in:
Drew Willcoxon 2013-10-24 17:27:36 -07:00
parent 89cecf118f
commit 3f15de1f7b
4 changed files with 23 additions and 11 deletions

View File

@ -57,7 +57,7 @@ JS_UnsafeGetLastProfilingError()
#ifdef __APPLE__
static bool
StartOSXProfiling(const char *profileName = nullptr)
StartOSXProfiling(const char *profileName, pid_t pid)
{
bool ok = true;
const char* profiler = nullptr;
@ -66,7 +66,7 @@ StartOSXProfiling(const char *profileName = nullptr)
profiler = "Shark";
#endif
#ifdef MOZ_INSTRUMENTS
ok = Instruments::Start();
ok = Instruments::Start(pid);
profiler = "Instruments";
#endif
if (!ok) {
@ -81,11 +81,11 @@ StartOSXProfiling(const char *profileName = nullptr)
#endif
JS_PUBLIC_API(bool)
JS_StartProfiling(const char *profileName)
JS_StartProfiling(const char *profileName, pid_t pid)
{
bool ok = true;
#ifdef __APPLE__
ok = StartOSXProfiling(profileName);
ok = StartOSXProfiling(profileName, pid);
#endif
#ifdef __linux__
if (!js_StartPerf())
@ -226,14 +226,25 @@ StartProfiling(JSContext *cx, unsigned argc, jsval *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
if (args.length() == 0) {
args.rval().setBoolean(JS_StartProfiling(nullptr));
args.rval().setBoolean(JS_StartProfiling(nullptr, getpid()));
return true;
}
RequiredStringArg profileName(cx, args, 0, "startProfiling");
if (!profileName)
return false;
args.rval().setBoolean(JS_StartProfiling(profileName.mBytes));
if (args.length() == 1) {
args.rval().setBoolean(JS_StartProfiling(profileName.mBytes, getpid()));
return true;
}
if (!args[1].isInt32()) {
JS_ReportError(cx, "startProfiling: invalid arguments (int expected)");
return false;
}
pid_t pid = static_cast<pid_t>(args[1].toInt32());
args.rval().setBoolean(JS_StartProfiling(profileName.mBytes, pid));
return true;
}

View File

@ -25,7 +25,7 @@
* Returns true if no profilers fail to start.
*/
extern JS_PUBLIC_API(bool)
JS_StartProfiling(const char *profileName);
JS_StartProfiling(const char *profileName, pid_t pid);
/**
* Stop any profilers that were previously started with JS_StartProfiling.

View File

@ -143,7 +143,7 @@ Error(CFErrorRef error)
}
bool
Start()
Start(pid_t pid)
{
if (gSession) {
return false;
@ -154,8 +154,7 @@ Start()
}
AutoReleased<CFStringRef> process =
CFStringCreateWithFormat(kCFAllocatorDefault, nullptr, CFSTR("%d"),
getpid());
CFStringCreateWithFormat(kCFAllocatorDefault, nullptr, CFSTR("%d"), pid);
if (!process) {
return false;
}

View File

@ -7,9 +7,11 @@
#ifdef __APPLE__
#include <unistd.h>
namespace Instruments {
bool Start();
bool Start(pid_t pid);
void Pause();
bool Resume();
void Stop(const char* profileName);