Permalink
Browse files

profiler, feat: support command line option: --prof and --prof-interval.

  • Loading branch information...
xicilion committed Oct 17, 2017
1 parent 21425c9 commit 9f6bad2138ebb4fe79038d31ea4af6f78b3a8ff4
View
@@ -93,6 +93,8 @@ class Isolate : public exlib::linkitem {
return m_in_use != 0;
}
void start_profiler();
public:
int32_t m_id;
exlib::string m_fname;
View
@@ -13,10 +13,13 @@
#include "ifs/global.h"
#include "ifs/process.h"
#include "ifs/coroutine.h"
#include "ifs/profiler.h"
namespace fibjs {
static int32_t s_tls_rt;
extern bool g_prof;
extern int32_t g_prof_interval;
void init_rt()
{
@@ -182,6 +185,17 @@ void Isolate::init()
m_topSandbox->initRoot();
}
void Isolate::start_profiler()
{
if (g_prof) {
char name[32];
obj_ptr<Timer_base> tm;
sprintf(name, "fibjs-%p.log", this);
profiler_base::start(name, -1, g_prof_interval, tm);
m_pendding.dec();
}
}
class CallbackData : public obj_base {
public:
CallbackData(Isolate* isolate, v8::InterruptCallback callback, void* data)
View
@@ -72,6 +72,8 @@ static result_t main_fiber(Isolate* isolate)
{
JSFiber::scope s;
isolate->start_profiler();
if (!isolate->m_fname.empty()) {
v8::Local<v8::Array> argv;
View
@@ -20,6 +20,9 @@ int32_t stack_size = 512;
int32_t stack_size = 256;
#endif
bool g_prof = false;
int32_t g_prof_interval = 1000;
#ifdef DEBUG
#define GUARD_SIZE 32
#else
@@ -35,9 +38,12 @@ static void printHelp()
"Options:\n"
" -h, --help print fibjs command line options\n"
" -v, --version print fibjs version\n"
" --v8-options print v8 command line options\n"
" --prof log statistical profiling information.\n"
" --prof-interval=n interval for --prof samples (in microseconds, default: 1000).\n"
" --prof-process process log file generated by profiler.start\n"
"\n"
" --v8-options print v8 command line options\n"
"\n"
"Documentation can be found at http://fibjs.org/\n");
}
@@ -69,6 +75,14 @@ void options(int32_t& pos, char* argv[])
} else if (!qstrcmp(arg, "--version") || !qstrcmp(arg, "-v")) {
printf("v%s\n", fibjs_version);
_exit(0);
} else if (!qstrcmp(arg, "--prof")) {
g_prof = true;
df++;
} else if (!qstrcmp(arg, "--prof-interval=", 16)) {
g_prof_interval = atoi(arg + 16);
if (g_prof_interval < 50)
g_prof_interval = 50;
df++;
} else if (!qstrcmp(arg, "--v8-options")) {
v8::internal::FlagList::PrintHelp();
_exit(0);
@@ -41,6 +41,8 @@ result_t Worker::_main()
{
JSFiber::scope s;
m_isolate->start_profiler();
m_worker->wrap();
m_event->set();
return m_isolate->m_topSandbox->run_worker(m_isolate->m_fname, m_worker);

0 comments on commit 9f6bad2

Please sign in to comment.