Commit 75037cbd authored by mike@belshe.com's avatar mike@belshe.com

Enable programmatic access to Profile pause/resume

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1185 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent ef8d48ea
......@@ -1970,6 +1970,23 @@ class EXPORT V8 {
*/
static int AdjustAmountOfExternalAllocatedMemory(int change_in_bytes);
/**
* Suspends recording of tick samples in the profiler.
* When the V8 profiling mode is enabled (usually via command line
* switches) this function suspends recording of tick samples.
* Profiling ticks are discarded until ResumeProfiler() is called.
*
* See also the --prof and --prof_auto command line switches to
* enable V8 profiling.
*/
static void PauseProfiler();
/**
* Resumes recording of tick samples in the profiler.
* See also PauseProfiler().
*/
static void ResumeProfiler();
private:
V8();
......
......@@ -2652,6 +2652,18 @@ void V8::SetExternalSymbolCallback(ExternalSymbolCallback callback) {
i::Heap::SetExternalSymbolCallback(callback);
}
void V8::PauseProfiler() {
#ifdef ENABLE_LOGGING_AND_PROFILING
i::Logger::PauseProfiler();
#endif
}
void V8::ResumeProfiler() {
#ifdef ENABLE_LOGGING_AND_PROFILING
i::Logger::ResumeProfiler();
#endif
}
String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj) {
EnsureInitialized("v8::String::Utf8Value::Utf8Value()");
......
......@@ -324,6 +324,8 @@ DEFINE_bool(log_state_changes, false, "Log state changes.")
DEFINE_bool(log_suspect, false, "Log suspect operations.")
DEFINE_bool(prof, false,
"Log statistical profiling information (implies --log-code).")
DEFINE_bool(prof_auto, true,
"Used with --prof, starts profiling automatically")
DEFINE_bool(log_regexp, false, "Log regular expression execution.")
DEFINE_bool(sliding_state_window, false,
"Update sliding state window counters.")
......
......@@ -81,6 +81,9 @@ class Profiler: public Thread {
// Inserts collected profiling data into buffer.
void Insert(TickSample* sample) {
if (paused_)
return;
if (Succ(head_) == tail_) {
overflow_ = true;
} else {
......@@ -102,6 +105,11 @@ class Profiler: public Thread {
void Run();
// Pause and Resume TickSample data collection.
static bool paused() { return paused_; }
static void pause() { paused_ = true; }
static void resume() { paused_ = false; }
private:
// Returns the next index in the cyclic buffer.
int Succ(int index) { return (index + 1) % kBufferSize; }
......@@ -117,8 +125,13 @@ class Profiler: public Thread {
// Tells whether worker thread should continue running.
bool running_;
// Tells whether we are currently recording tick samples.
static bool paused_;
};
bool Profiler::paused_ = false;
//
// Ticker used to provide ticks to the profiler and the sliding state
......@@ -744,6 +757,21 @@ void Logger::TickEvent(TickSample* sample, bool overflow) {
if (overflow) fprintf(logfile_, ",overflow");
fprintf(logfile_, "\n");
}
bool Logger::IsProfilerPaused() {
return profiler_->paused();
}
void Logger::PauseProfiler() {
profiler_->pause();
}
void Logger::ResumeProfiler() {
profiler_->resume();
}
#endif
......@@ -822,6 +850,8 @@ bool Logger::Setup() {
if (FLAG_prof) {
profiler_ = new Profiler();
if (!FLAG_prof_auto)
profiler_->pause();
profiler_->Engage();
}
......
......@@ -203,6 +203,13 @@ class Logger {
static bool is_enabled() { return logfile_ != NULL; }
// Pause/Resume collection of profiling data.
// When data collection is paused, Tick events are discarded until
// data collection is Resumed.
static bool IsProfilerPaused();
static void PauseProfiler();
static void ResumeProfiler();
private:
// Emits the source code of a regexp. Used by regexp events.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment