Fix --hydrogen-stats.

Timing happens in a scope.  Since crankshaft has been chopped up into three methods, this approach is wrong.

BUG=

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12998 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
yangguo@chromium.org 2012-11-19 14:20:57 +00:00
parent f9bc4d3bf2
commit 2b5e6bae60
3 changed files with 59 additions and 28 deletions

View File

@ -194,6 +194,11 @@ void OptimizingCompiler::RecordOptimizationStats() {
code_size, code_size,
compilation_time); compilation_time);
} }
if (FLAG_hydrogen_stats) {
HStatistics::Instance()->IncrementSubtotals(time_taken_to_create_graph_,
time_taken_to_optimize_,
time_taken_to_codegen_);
}
} }
@ -284,7 +289,6 @@ OptimizingCompiler::Status OptimizingCompiler::CreateGraph() {
// doesn't have deoptimization support. Alternatively, we may decide to // doesn't have deoptimization support. Alternatively, we may decide to
// run the full code generator to get a baseline for the compile-time // run the full code generator to get a baseline for the compile-time
// performance of the hydrogen-based compiler. // performance of the hydrogen-based compiler.
Timer t(this, &time_taken_to_create_graph_);
bool should_recompile = !info()->shared_info()->has_deoptimization_support(); bool should_recompile = !info()->shared_info()->has_deoptimization_support();
if (should_recompile || FLAG_hydrogen_stats) { if (should_recompile || FLAG_hydrogen_stats) {
HPhase phase(HPhase::kFullCodeGen); HPhase phase(HPhase::kFullCodeGen);
@ -324,7 +328,8 @@ OptimizingCompiler::Status OptimizingCompiler::CreateGraph() {
oracle_ = new(info()->zone()) TypeFeedbackOracle( oracle_ = new(info()->zone()) TypeFeedbackOracle(
code, native_context, info()->isolate(), info()->zone()); code, native_context, info()->isolate(), info()->zone());
graph_builder_ = new(info()->zone()) HGraphBuilder(info(), oracle_); graph_builder_ = new(info()->zone()) HGraphBuilder(info(), oracle_);
HPhase phase(HPhase::kTotal);
Timer t(this, &time_taken_to_create_graph_);
graph_ = graph_builder_->CreateGraph(); graph_ = graph_builder_->CreateGraph();
if (info()->isolate()->has_pending_exception()) { if (info()->isolate()->has_pending_exception()) {
@ -371,15 +376,17 @@ OptimizingCompiler::Status OptimizingCompiler::OptimizeGraph() {
OptimizingCompiler::Status OptimizingCompiler::GenerateAndInstallCode() { OptimizingCompiler::Status OptimizingCompiler::GenerateAndInstallCode() {
ASSERT(last_status() == SUCCEEDED); ASSERT(last_status() == SUCCEEDED);
Timer timer(this, &time_taken_to_codegen_); { // Scope for timer.
ASSERT(chunk_ != NULL); Timer timer(this, &time_taken_to_codegen_);
ASSERT(graph_ != NULL); ASSERT(chunk_ != NULL);
Handle<Code> optimized_code = chunk_->Codegen(); ASSERT(graph_ != NULL);
if (optimized_code.is_null()) { Handle<Code> optimized_code = chunk_->Codegen();
info()->set_bailout_reason("code generation failed"); if (optimized_code.is_null()) {
return AbortOptimization(); info()->set_bailout_reason("code generation failed");
return AbortOptimization();
}
info()->SetCode(optimized_code);
} }
info()->SetCode(optimized_code);
RecordOptimizationStats(); RecordOptimizationStats();
return SetLastStatus(SUCCEEDED); return SetLastStatus(SUCCEEDED);
} }

View File

@ -9959,28 +9959,43 @@ void HStatistics::Print() {
double size_percent = static_cast<double>(size) * 100 / total_size_; double size_percent = static_cast<double>(size) * 100 / total_size_;
PrintF(" %8u bytes / %4.1f %%\n", size, size_percent); PrintF(" %8u bytes / %4.1f %%\n", size, size_percent);
} }
double source_size_in_kb = static_cast<double>(source_size_) / 1024;
double normalized_time = source_size_in_kb > 0 PrintF("---------------------------------------------------------------\n");
? (static_cast<double>(sum) / 1000) / source_size_in_kb int64_t total = create_graph_ + optimize_graph_ + generate_code_;
: 0; PrintF("%30s - %7.3f ms / %4.1f %% \n",
double normalized_bytes = source_size_in_kb > 0 "Create graph",
? total_size_ / source_size_in_kb static_cast<double>(create_graph_) / 1000,
: 0; static_cast<double>(create_graph_) * 100 / total);
PrintF("%30s - %7.3f ms %7.3f bytes\n", "Sum", PrintF("%30s - %7.3f ms / %4.1f %% \n",
normalized_time, normalized_bytes); "Optimize graph",
static_cast<double>(optimize_graph_) / 1000,
static_cast<double>(optimize_graph_) * 100 / total);
PrintF("%30s - %7.3f ms / %4.1f %% \n",
"Generate and install code",
static_cast<double>(generate_code_) / 1000,
static_cast<double>(generate_code_) * 100 / total);
PrintF("---------------------------------------------------------------\n"); PrintF("---------------------------------------------------------------\n");
PrintF("%30s - %7.3f ms (%.1f times slower than full code gen)\n", PrintF("%30s - %7.3f ms (%.1f times slower than full code gen)\n",
"Total", "Total",
static_cast<double>(total_) / 1000, static_cast<double>(total) / 1000,
static_cast<double>(total_) / full_code_gen_); static_cast<double>(total) / full_code_gen_);
double source_size_in_kb = static_cast<double>(source_size_) / 1024;
double normalized_time = source_size_in_kb > 0
? (static_cast<double>(total) / 1000) / source_size_in_kb
: 0;
double normalized_size_in_kb = source_size_in_kb > 0
? total_size_ / 1024 / source_size_in_kb
: 0;
PrintF("%30s - %7.3f ms %7.3f kB allocated\n",
"Average per kB source",
normalized_time, normalized_size_in_kb);
} }
void HStatistics::SaveTiming(const char* name, int64_t ticks, unsigned size) { void HStatistics::SaveTiming(const char* name, int64_t ticks, unsigned size) {
if (name == HPhase::kFullCodeGen) { if (name == HPhase::kFullCodeGen) {
full_code_gen_ += ticks; full_code_gen_ += ticks;
} else if (name == HPhase::kTotal) {
total_ += ticks;
} else { } else {
total_size_ += size; total_size_ += size;
for (int i = 0; i < names_.length(); ++i) { for (int i = 0; i < names_.length(); ++i) {
@ -9998,8 +10013,6 @@ void HStatistics::SaveTiming(const char* name, int64_t ticks, unsigned size) {
const char* const HPhase::kFullCodeGen = "Full code generator"; const char* const HPhase::kFullCodeGen = "Full code generator";
const char* const HPhase::kTotal = "Total";
void HPhase::Begin(const char* name, void HPhase::Begin(const char* name,
HGraph* graph, HGraph* graph,

View File

@ -1378,12 +1378,22 @@ class HStatistics: public Malloced {
return instance.get(); return instance.get();
} }
void IncrementSubtotals(int64_t create_graph,
int64_t optimize_graph,
int64_t generate_code) {
create_graph_ += create_graph;
optimize_graph_ += optimize_graph;
generate_code_ += generate_code;
}
private: private:
HStatistics() HStatistics()
: timing_(5), : timing_(5),
names_(5), names_(5),
sizes_(5), sizes_(5),
total_(0), create_graph_(0),
optimize_graph_(0),
generate_code_(0),
total_size_(0), total_size_(0),
full_code_gen_(0), full_code_gen_(0),
source_size_(0) { } source_size_(0) { }
@ -1391,7 +1401,9 @@ class HStatistics: public Malloced {
List<int64_t> timing_; List<int64_t> timing_;
List<const char*> names_; List<const char*> names_;
List<unsigned> sizes_; List<unsigned> sizes_;
int64_t total_; int64_t create_graph_;
int64_t optimize_graph_;
int64_t generate_code_;
unsigned total_size_; unsigned total_size_;
int64_t full_code_gen_; int64_t full_code_gen_;
double source_size_; double source_size_;
@ -1401,7 +1413,6 @@ class HStatistics: public Malloced {
class HPhase BASE_EMBEDDED { class HPhase BASE_EMBEDDED {
public: public:
static const char* const kFullCodeGen; static const char* const kFullCodeGen;
static const char* const kTotal;
explicit HPhase(const char* name) { Begin(name, NULL, NULL, NULL); } explicit HPhase(const char* name) { Begin(name, NULL, NULL, NULL); }
HPhase(const char* name, HGraph* graph) { HPhase(const char* name, HGraph* graph) {