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,
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
// run the full code generator to get a baseline for the compile-time
// performance of the hydrogen-based compiler.
Timer t(this, &time_taken_to_create_graph_);
bool should_recompile = !info()->shared_info()->has_deoptimization_support();
if (should_recompile || FLAG_hydrogen_stats) {
HPhase phase(HPhase::kFullCodeGen);
@ -324,7 +328,8 @@ OptimizingCompiler::Status OptimizingCompiler::CreateGraph() {
oracle_ = new(info()->zone()) TypeFeedbackOracle(
code, native_context, info()->isolate(), info()->zone());
graph_builder_ = new(info()->zone()) HGraphBuilder(info(), oracle_);
HPhase phase(HPhase::kTotal);
Timer t(this, &time_taken_to_create_graph_);
graph_ = graph_builder_->CreateGraph();
if (info()->isolate()->has_pending_exception()) {
@ -371,15 +376,17 @@ OptimizingCompiler::Status OptimizingCompiler::OptimizeGraph() {
OptimizingCompiler::Status OptimizingCompiler::GenerateAndInstallCode() {
ASSERT(last_status() == SUCCEEDED);
Timer timer(this, &time_taken_to_codegen_);
ASSERT(chunk_ != NULL);
ASSERT(graph_ != NULL);
Handle<Code> optimized_code = chunk_->Codegen();
if (optimized_code.is_null()) {
info()->set_bailout_reason("code generation failed");
return AbortOptimization();
{ // Scope for timer.
Timer timer(this, &time_taken_to_codegen_);
ASSERT(chunk_ != NULL);
ASSERT(graph_ != NULL);
Handle<Code> optimized_code = chunk_->Codegen();
if (optimized_code.is_null()) {
info()->set_bailout_reason("code generation failed");
return AbortOptimization();
}
info()->SetCode(optimized_code);
}
info()->SetCode(optimized_code);
RecordOptimizationStats();
return SetLastStatus(SUCCEEDED);
}

View File

@ -9959,28 +9959,43 @@ void HStatistics::Print() {
double size_percent = static_cast<double>(size) * 100 / total_size_;
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
? (static_cast<double>(sum) / 1000) / source_size_in_kb
: 0;
double normalized_bytes = source_size_in_kb > 0
? total_size_ / source_size_in_kb
: 0;
PrintF("%30s - %7.3f ms %7.3f bytes\n", "Sum",
normalized_time, normalized_bytes);
PrintF("---------------------------------------------------------------\n");
int64_t total = create_graph_ + optimize_graph_ + generate_code_;
PrintF("%30s - %7.3f ms / %4.1f %% \n",
"Create graph",
static_cast<double>(create_graph_) / 1000,
static_cast<double>(create_graph_) * 100 / total);
PrintF("%30s - %7.3f ms / %4.1f %% \n",
"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("%30s - %7.3f ms (%.1f times slower than full code gen)\n",
"Total",
static_cast<double>(total_) / 1000,
static_cast<double>(total_) / full_code_gen_);
static_cast<double>(total) / 1000,
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) {
if (name == HPhase::kFullCodeGen) {
full_code_gen_ += ticks;
} else if (name == HPhase::kTotal) {
total_ += ticks;
} else {
total_size_ += size;
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::kTotal = "Total";
void HPhase::Begin(const char* name,
HGraph* graph,

View File

@ -1378,12 +1378,22 @@ class HStatistics: public Malloced {
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:
HStatistics()
: timing_(5),
names_(5),
sizes_(5),
total_(0),
create_graph_(0),
optimize_graph_(0),
generate_code_(0),
total_size_(0),
full_code_gen_(0),
source_size_(0) { }
@ -1391,7 +1401,9 @@ class HStatistics: public Malloced {
List<int64_t> timing_;
List<const char*> names_;
List<unsigned> sizes_;
int64_t total_;
int64_t create_graph_;
int64_t optimize_graph_;
int64_t generate_code_;
unsigned total_size_;
int64_t full_code_gen_;
double source_size_;
@ -1401,7 +1413,6 @@ class HStatistics: public Malloced {
class HPhase BASE_EMBEDDED {
public:
static const char* const kFullCodeGen;
static const char* const kTotal;
explicit HPhase(const char* name) { Begin(name, NULL, NULL, NULL); }
HPhase(const char* name, HGraph* graph) {