Commit 12ffd366 authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[log] Add sampling interval flag for --prof

Note that this changes the sampling interval from milliseconds to
microseconds -- this shouldn't cause issues except for tools that use
'profiler,"begin",<interval>' somehow.

Change-Id: I20222de91f7820e26eb3fc505a4752b0bc7e1642
Reviewed-on: https://chromium-review.googlesource.com/451658
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43726}
parent 36a22fe7
......@@ -1138,6 +1138,18 @@ DEFINE_BOOL(log_handles, false, "Log global handle events.")
DEFINE_BOOL(log_suspect, false, "Log suspect operations.")
DEFINE_BOOL(prof, false,
"Log statistical profiling information (implies --log-code).")
#if defined(ANDROID)
// Phones and tablets have processors that are much slower than desktop
// and laptop computers for which current heuristics are tuned.
#define DEFAULT_PROF_SAMPLING_INTERVAL 5000
#else
#define DEFAULT_PROF_SAMPLING_INTERVAL 1000
#endif
DEFINE_INT(prof_sampling_interval, DEFAULT_PROF_SAMPLING_INTERVAL,
"Interval for --prof samples (in microseconds).")
#undef DEFAULT_PROF_SAMPLING_INTERVAL
DEFINE_BOOL(prof_cpp, false, "Like --prof, but ignore generated code.")
DEFINE_IMPLICATION(prof, prof_cpp)
DEFINE_BOOL(prof_browser_mode, true,
......
......@@ -524,21 +524,22 @@ class SamplingThread : public base::Thread {
public:
static const int kSamplingThreadStackSize = 64 * KB;
SamplingThread(sampler::Sampler* sampler, int interval)
: base::Thread(base::Thread::Options("SamplingThread",
kSamplingThreadStackSize)),
SamplingThread(sampler::Sampler* sampler, int interval_microseconds)
: base::Thread(
base::Thread::Options("SamplingThread", kSamplingThreadStackSize)),
sampler_(sampler),
interval_(interval) {}
interval_microseconds_(interval_microseconds) {}
void Run() override {
while (sampler_->IsProfiling()) {
sampler_->DoSample();
base::OS::Sleep(base::TimeDelta::FromMilliseconds(interval_));
base::OS::Sleep(
base::TimeDelta::FromMicroseconds(interval_microseconds_));
}
}
private:
sampler::Sampler* sampler_;
const int interval_;
const int interval_microseconds_;
};
......@@ -616,10 +617,10 @@ class Profiler: public base::Thread {
//
class Ticker: public sampler::Sampler {
public:
Ticker(Isolate* isolate, int interval)
Ticker(Isolate* isolate, int interval_microseconds)
: sampler::Sampler(reinterpret_cast<v8::Isolate*>(isolate)),
profiler_(nullptr),
sampling_thread_(new SamplingThread(this, interval)) {}
sampling_thread_(new SamplingThread(this, interval_microseconds)) {}
~Ticker() {
if (IsActive()) Stop();
......@@ -760,7 +761,7 @@ void Logger::removeCodeEventListener(CodeEventListener* listener) {
void Logger::ProfilerBeginEvent() {
if (!log_->IsEnabled()) return;
Log::MessageBuilder msg(log_);
msg.Append("profiler,\"begin\",%d", kSamplingIntervalMs);
msg.Append("profiler,\"begin\",%d", FLAG_prof_sampling_interval);
msg.WriteToLogFile();
}
......@@ -1754,7 +1755,7 @@ bool Logger::SetUp(Isolate* isolate) {
addCodeEventListener(ll_logger_);
}
ticker_ = new Ticker(isolate, kSamplingIntervalMs);
ticker_ = new Ticker(isolate, FLAG_prof_sampling_interval);
if (Log::InitLogAtStart()) {
is_logging_ = true;
......
......@@ -58,6 +58,10 @@ namespace internal {
// --prof
// Collect statistical profiling information (ticks), default is off. The
// tick profiler requires code events, so --prof implies --log-code.
//
// --prof-sampling-interval <microseconds>
// The interval between --prof samples, default is 1000 microseconds (5000 on
// Android).
// Forward declarations.
class CodeEventListener;
......@@ -254,15 +258,6 @@ class Logger : public CodeEventListener {
INLINE(static CodeEventListener::LogEventsAndTags ToNativeByScript(
CodeEventListener::LogEventsAndTags, Script*));
// Profiler's sampling interval (in milliseconds).
#if defined(ANDROID)
// Phones and tablets have processors that are much slower than desktop
// and laptop computers for which current heuristics are tuned.
static const int kSamplingIntervalMs = 5;
#else
static const int kSamplingIntervalMs = 1;
#endif
// Callback from Log, stops profiling in case of insufficient resources.
void LogFailure();
......
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