зеркало из https://github.com/mozilla/gecko-dev.git
Bug 925621 - Let startProfiling take a pid so the content process can be profiled. r=sfink
This commit is contained in:
Родитель
86d60e0305
Коммит
0b9f6fb24f
|
@ -23,6 +23,11 @@
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef XP_WIN
|
||||||
|
# include <process.h>
|
||||||
|
# define getpid _getpid
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "vm/Probes.h"
|
#include "vm/Probes.h"
|
||||||
|
|
||||||
#include "jscntxtinlines.h"
|
#include "jscntxtinlines.h"
|
||||||
|
@ -57,7 +62,7 @@ JS_UnsafeGetLastProfilingError()
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
static bool
|
static bool
|
||||||
StartOSXProfiling(const char *profileName = nullptr)
|
StartOSXProfiling(const char *profileName, pid_t pid)
|
||||||
{
|
{
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
const char* profiler = nullptr;
|
const char* profiler = nullptr;
|
||||||
|
@ -66,7 +71,7 @@ StartOSXProfiling(const char *profileName = nullptr)
|
||||||
profiler = "Shark";
|
profiler = "Shark";
|
||||||
#endif
|
#endif
|
||||||
#ifdef MOZ_INSTRUMENTS
|
#ifdef MOZ_INSTRUMENTS
|
||||||
ok = Instruments::Start();
|
ok = Instruments::Start(pid);
|
||||||
profiler = "Instruments";
|
profiler = "Instruments";
|
||||||
#endif
|
#endif
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
|
@ -81,11 +86,11 @@ StartOSXProfiling(const char *profileName = nullptr)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
JS_PUBLIC_API(bool)
|
JS_PUBLIC_API(bool)
|
||||||
JS_StartProfiling(const char *profileName)
|
JS_StartProfiling(const char *profileName, pid_t pid)
|
||||||
{
|
{
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
ok = StartOSXProfiling(profileName);
|
ok = StartOSXProfiling(profileName, pid);
|
||||||
#endif
|
#endif
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
if (!js_StartPerf())
|
if (!js_StartPerf())
|
||||||
|
@ -226,14 +231,25 @@ StartProfiling(JSContext *cx, unsigned argc, jsval *vp)
|
||||||
{
|
{
|
||||||
CallArgs args = CallArgsFromVp(argc, vp);
|
CallArgs args = CallArgsFromVp(argc, vp);
|
||||||
if (args.length() == 0) {
|
if (args.length() == 0) {
|
||||||
args.rval().setBoolean(JS_StartProfiling(nullptr));
|
args.rval().setBoolean(JS_StartProfiling(nullptr, getpid()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
RequiredStringArg profileName(cx, args, 0, "startProfiling");
|
RequiredStringArg profileName(cx, args, 0, "startProfiling");
|
||||||
if (!profileName)
|
if (!profileName)
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,12 @@
|
||||||
|
|
||||||
#include "jstypes.h"
|
#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
|
* Start any profilers that are available and have been configured on for this
|
||||||
* platform. This is NOT thread safe.
|
* platform. This is NOT thread safe.
|
||||||
|
@ -25,7 +31,7 @@
|
||||||
* Returns true if no profilers fail to start.
|
* Returns true if no profilers fail to start.
|
||||||
*/
|
*/
|
||||||
extern JS_PUBLIC_API(bool)
|
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.
|
* Stop any profilers that were previously started with JS_StartProfiling.
|
||||||
|
|
|
@ -143,7 +143,7 @@ Error(CFErrorRef error)
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Start()
|
Start(pid_t pid)
|
||||||
{
|
{
|
||||||
if (gSession) {
|
if (gSession) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -154,8 +154,7 @@ Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoReleased<CFStringRef> process =
|
AutoReleased<CFStringRef> process =
|
||||||
CFStringCreateWithFormat(kCFAllocatorDefault, nullptr, CFSTR("%d"),
|
CFStringCreateWithFormat(kCFAllocatorDefault, nullptr, CFSTR("%d"), pid);
|
||||||
getpid());
|
|
||||||
if (!process) {
|
if (!process) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,11 @@
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
namespace Instruments {
|
namespace Instruments {
|
||||||
|
|
||||||
bool Start();
|
bool Start(pid_t pid);
|
||||||
void Pause();
|
void Pause();
|
||||||
bool Resume();
|
bool Resume();
|
||||||
void Stop(const char* profileName);
|
void Stop(const char* profileName);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче