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
Родитель 86d60e0305
Коммит 0b9f6fb24f
4 изменённых файлов: 34 добавлений и 11 удалений

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

@ -23,6 +23,11 @@
#endif
#endif
#ifdef XP_WIN
# include <process.h>
# define getpid _getpid
#endif
#include "vm/Probes.h"
#include "jscntxtinlines.h"
@ -57,7 +62,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 +71,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 +86,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 +231,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;
}

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

@ -13,6 +13,12 @@
#include "jstypes.h"
#ifdef XP_WIN
typedef int pid_t;
#else
#include <unistd.h>
#endif
/**
* Start any profilers that are available and have been configured on for this
* platform. This is NOT thread safe.
@ -25,7 +31,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.

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

@ -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;
}

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

@ -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);