Commit 048b86d6 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Log event start and event end separately when using --log-timer-events.

R=haraken@chromium.org
BUG=

Review URL: https://chromiumcodereview.appspot.com/12040075

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13529 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 6953861e
......@@ -77,10 +77,13 @@ void* Histogram::CreateHistogram() const {
// Start the timer.
void HistogramTimer::Start() {
if (histogram_.Enabled() || FLAG_log_internal_timer_events) {
if (histogram_.Enabled()) {
stop_time_ = 0;
start_time_ = OS::Ticks();
}
if (FLAG_log_internal_timer_events) {
LOG(Isolate::Current(), TimerEvent(Logger::START, histogram_.name_));
}
}
// Stop the timer and record the results.
......@@ -92,8 +95,7 @@ void HistogramTimer::Stop() {
histogram_.AddSample(milliseconds);
}
if (FLAG_log_internal_timer_events) {
LOG(Isolate::Current(),
TimerEvent(histogram_.name_, start_time_, OS::Ticks()));
LOG(Isolate::Current(), TimerEvent(Logger::END, histogram_.name_));
}
}
......
......@@ -633,46 +633,30 @@ void Logger::SharedLibraryEvent(const wchar_t* library_path,
}
void Logger::TimerEvent(const char* name, int64_t start, int64_t end) {
void Logger::TimerEvent(StartEnd se, const char* name) {
if (!log_->IsEnabled()) return;
ASSERT(FLAG_log_internal_timer_events);
LogMessageBuilder msg(this);
int since_epoch = static_cast<int>(start - epoch_);
int pause_time = static_cast<int>(end - start);
msg.Append("timer-event,\"%s\",%ld,%ld\n", name, since_epoch, pause_time);
int since_epoch = static_cast<int>(OS::Ticks() - epoch_);
const char* format = (se == START) ? "timer-event-start,\"%s\",%ld\n"
: "timer-event-end,\"%s\",%ld\n";
msg.Append(format, name, since_epoch);
msg.WriteToLogFile();
}
void Logger::ExternalSwitch(StateTag old_tag, StateTag new_tag) {
if (old_tag != EXTERNAL && new_tag == EXTERNAL) {
enter_external_ = OS::Ticks();
}
if (old_tag == EXTERNAL && new_tag != EXTERNAL && enter_external_ != 0) {
TimerEvent("V8.External", enter_external_, OS::Ticks());
enter_external_ = 0;
}
}
void Logger::EnterExternal() {
LOGGER->enter_external_ = OS::Ticks();
LOG(ISOLATE, TimerEvent(START, TimerEventScope::v8_external));
}
void Logger::LeaveExternal() {
if (enter_external_ == 0) return;
Logger* logger = LOGGER;
logger->TimerEvent("V8.External", enter_external_, OS::Ticks());
logger->enter_external_ = 0;
LOG(ISOLATE, TimerEvent(END, TimerEventScope::v8_external));
}
int64_t Logger::enter_external_ = 0;
void Logger::TimerEventScope::LogTimerEvent() {
LOG(isolate_, TimerEvent(name_, start_, OS::Ticks()));
void Logger::TimerEventScope::LogTimerEvent(StartEnd se) {
LOG(isolate_, TimerEvent(se, name_));
}
......@@ -683,6 +667,7 @@ const char* Logger::TimerEventScope::v8_recompile_parallel =
const char* Logger::TimerEventScope::v8_compile_full_code =
"V8.CompileFullCode";
const char* Logger::TimerEventScope::v8_execute = "V8.Execute";
const char* Logger::TimerEventScope::v8_external = "V8.External";
void Logger::LogRegExpSource(Handle<JSRegExp> regexp) {
......
......@@ -273,8 +273,9 @@ class Logger {
uintptr_t end);
// ==== Events logged by --log-timer-events. ====
void TimerEvent(const char* name, int64_t start, int64_t end);
void ExternalSwitch(StateTag old_tag, StateTag new_tag);
enum StartEnd { START, END };
void TimerEvent(StartEnd se, const char* name);
static void EnterExternal();
static void LeaveExternal();
......@@ -282,25 +283,25 @@ class Logger {
class TimerEventScope {
public:
TimerEventScope(Isolate* isolate, const char* name)
: isolate_(isolate), name_(name), start_(0) {
if (FLAG_log_internal_timer_events) start_ = OS::Ticks();
: isolate_(isolate), name_(name) {
if (FLAG_log_internal_timer_events) LogTimerEvent(START);
}
~TimerEventScope() {
if (FLAG_log_internal_timer_events) LogTimerEvent();
if (FLAG_log_internal_timer_events) LogTimerEvent(END);
}
void LogTimerEvent();
void LogTimerEvent(StartEnd se);
static const char* v8_recompile_synchronous;
static const char* v8_recompile_parallel;
static const char* v8_compile_full_code;
static const char* v8_execute;
static const char* v8_external;
private:
Isolate* isolate_;
const char* name_;
int64_t start_;
};
// ==== Events logged by --log-regexp ====
......@@ -473,7 +474,6 @@ class Logger {
Address prev_code_;
int64_t epoch_;
static int64_t enter_external_;
friend class CpuProfiler;
};
......
......@@ -67,8 +67,8 @@ VMState::VMState(Isolate* isolate, StateTag tag)
LOG(isolate, UncheckedStringEvent("From", StateToString(previous_tag_)));
}
if (FLAG_log_timer_events) {
LOG(isolate, ExternalSwitch(previous_tag_, tag));
if (FLAG_log_timer_events && previous_tag_ != EXTERNAL && tag == EXTERNAL) {
LOG(isolate_, EnterExternal());
}
isolate_->SetCurrentVMState(tag);
......@@ -84,8 +84,9 @@ VMState::~VMState() {
UncheckedStringEvent("To", StateToString(previous_tag_)));
}
if (FLAG_log_timer_events) {
LOG(isolate_, ExternalSwitch(isolate_->current_vm_state(), previous_tag_));
if (FLAG_log_timer_events &&
previous_tag_ != EXTERNAL && isolate_->current_vm_state() == EXTERNAL) {
LOG(isolate_, LeaveExternal());
}
isolate_->SetCurrentVMState(previous_tag_);
......
......@@ -41,18 +41,25 @@ else
$d8_exec --nocrankshaft --prof --logfile $calibration_log \
--log-timer-events -e "$calibration_script" > /dev/null
t_1=`grep "V8.Execute" $calibration_log | tail -n1 | awk -F, '{print $4}'`
n_1=`grep "timer-event" $calibration_log | wc -l`
t_1_start=`grep "timer-event-start,\"V8.Execute\"" $calibration_log \
| tail -n1 | awk -F, '{print $3}'`
t_1_end=`grep "timer-event-end,\"V8.Execute\"" $calibration_log \
| tail -n1 | awk -F, '{print $3}'`
n_1=`grep "timer-event\|tick" $calibration_log | wc -l`
$d8_exec --nocrankshaft --prof --logfile $calibration_log \
--log-internal-timer-events -e "$calibration_script" > /dev/null
t_2=`grep "V8.Execute" $calibration_log | tail -n1 | awk -F, '{print $4}'`
n_2=`grep "timer-event" $calibration_log | wc -l`
t_2_start=`grep "timer-event-start,\"V8.Execute\"" $calibration_log \
| tail -n1 | awk -F, '{print $3}'`
t_2_end=`grep "timer-event-end,\"V8.Execute\"" $calibration_log \
| tail -n1 | awk -F, '{print $3}'`
n_2=`grep "timer-event\|tick" $calibration_log | wc -l`
rm $calibration_log
# Overhead in picoseconds.
distortion=`echo "1000*($t_1 - $t_2)/($n_1 - $n_2)" | bc`
distortion=`echo "1000*(($t_1_end - $t_1_start) - ($t_2_end - $t_2_start)) \
/ ($n_1 - $n_2)" | bc`
fi
if [ -n "$PLOT_RANGE" ]; then
......
This diff is collapsed.
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