OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/compiler_stats.h" | 5 #include "vm/compiler_stats.h" |
6 | 6 |
7 #include "vm/flags.h" | 7 #include "vm/flags.h" |
| 8 #include "vm/object_graph.h" |
8 #include "vm/timer.h" | 9 #include "vm/timer.h" |
9 | 10 |
10 | 11 |
11 namespace dart { | 12 namespace dart { |
12 | 13 |
13 DEFINE_FLAG(bool, compiler_stats, false, "Compiler stat counters."); | 14 DEFINE_FLAG(bool, compiler_stats, false, "Compiler stat counters."); |
14 | 15 |
15 | 16 |
| 17 class TokenStreamVisitor : public ObjectGraph::Visitor { |
| 18 public: |
| 19 explicit TokenStreamVisitor(CompilerStats* compiler_stats) |
| 20 : obj_(Object::Handle()), stats_(compiler_stats) { |
| 21 } |
| 22 |
| 23 virtual Direction VisitObject(ObjectGraph::StackIterator* it) { |
| 24 RawObject* raw_obj = it->Get(); |
| 25 if (raw_obj->IsFreeListElement()) { |
| 26 return kProceed; |
| 27 } |
| 28 obj_ = raw_obj; |
| 29 if (obj_.GetClassId() == TokenStream::kClassId) { |
| 30 TokenStream::Iterator tkit(TokenStream::Cast(obj_), |
| 31 0, |
| 32 TokenStream::Iterator::kNoNewlines); |
| 33 Token::Kind kind = tkit.CurrentTokenKind(); |
| 34 while (kind != Token::kEOS) { |
| 35 ++stats_->num_tokens_total; |
| 36 if (kind == Token::kIDENT) { |
| 37 ++stats_->num_ident_tokens_total; |
| 38 } else if (Token::NeedsLiteralToken(kind)) { |
| 39 ++stats_->num_literal_tokens_total; |
| 40 } |
| 41 tkit.Advance(); |
| 42 kind = tkit.CurrentTokenKind(); |
| 43 } |
| 44 } |
| 45 return kProceed; |
| 46 } |
| 47 |
| 48 private: |
| 49 Object& obj_; |
| 50 CompilerStats* stats_; |
| 51 }; |
| 52 |
| 53 |
16 CompilerStats::CompilerStats(Isolate* isolate) | 54 CompilerStats::CompilerStats(Isolate* isolate) |
17 : isolate_(isolate), | 55 : isolate_(isolate), |
18 parser_timer(true, "parser timer"), | 56 parser_timer(true, "parser timer"), |
19 scanner_timer(true, "scanner timer"), | 57 scanner_timer(true, "scanner timer"), |
20 codegen_timer(true, "codegen timer"), | 58 codegen_timer(true, "codegen timer"), |
21 graphbuilder_timer(true, "flow graph builder timer"), | 59 graphbuilder_timer(true, "flow graph builder timer"), |
22 ssa_timer(true, "flow graph SSA timer"), | 60 ssa_timer(true, "flow graph SSA timer"), |
23 graphinliner_timer(true, "flow graph inliner timer"), | 61 graphinliner_timer(true, "flow graph inliner timer"), |
24 graphinliner_parse_timer(true, "inliner parsing timer"), | 62 graphinliner_parse_timer(true, "inliner parsing timer"), |
25 graphinliner_build_timer(true, "inliner building timer"), | 63 graphinliner_build_timer(true, "inliner building timer"), |
26 graphinliner_ssa_timer(true, "inliner SSA timer"), | 64 graphinliner_ssa_timer(true, "inliner SSA timer"), |
27 graphinliner_opt_timer(true, "inliner optimization timer"), | 65 graphinliner_opt_timer(true, "inliner optimization timer"), |
28 graphinliner_subst_timer(true, "inliner substitution timer"), | 66 graphinliner_subst_timer(true, "inliner substitution timer"), |
29 graphoptimizer_timer(true, "flow graph optimizer timer"), | 67 graphoptimizer_timer(true, "flow graph optimizer timer"), |
30 graphcompiler_timer(true, "flow graph compiler timer"), | 68 graphcompiler_timer(true, "flow graph compiler timer"), |
31 codefinalizer_timer(true, "code finalization timer"), | 69 codefinalizer_timer(true, "code finalization timer"), |
32 num_tokens_total(0), | 70 num_tokens_total(0), |
33 num_literal_tokens_total(0), | 71 num_literal_tokens_total(0), |
34 num_ident_tokens_total(0), | 72 num_ident_tokens_total(0), |
35 num_tokens_consumed(0), | 73 num_tokens_consumed(0), |
36 num_token_checks(0), | 74 num_token_checks(0), |
37 num_tokens_rewind(0), | |
38 num_tokens_lookahead(0), | 75 num_tokens_lookahead(0), |
39 num_classes_compiled(0), | 76 num_classes_compiled(0), |
40 num_functions_compiled(0), | 77 num_functions_compiled(0), |
41 num_implicit_final_getters(0), | 78 num_implicit_final_getters(0), |
42 src_length(0), | 79 src_length(0), |
43 total_code_size(0), | 80 total_code_size(0), |
44 total_instr_size(0), | 81 total_instr_size(0), |
45 pc_desc_size(0), | 82 pc_desc_size(0), |
46 vardesc_size(0) { | 83 vardesc_size(0) { |
47 } | 84 } |
48 | 85 |
49 | 86 |
50 void CompilerStats::Print() { | 87 void CompilerStats::Print() { |
51 if (!FLAG_compiler_stats) { | 88 if (!FLAG_compiler_stats) { |
52 return; | 89 return; |
53 } | 90 } |
| 91 |
| 92 // Traverse the heap and compute number of tokens in all |
| 93 // TokenStream objects. |
| 94 num_tokens_total = 0; |
| 95 num_literal_tokens_total = 0; |
| 96 num_ident_tokens_total = 0; |
| 97 TokenStreamVisitor visitor(this); |
| 98 ObjectGraph graph(isolate_); |
| 99 graph.IterateObjects(&visitor); |
| 100 |
54 OS::Print("==== Compiler Stats for isolate '%s' ====\n", | 101 OS::Print("==== Compiler Stats for isolate '%s' ====\n", |
55 isolate_->debugger_name()); | 102 isolate_->debugger_name()); |
56 OS::Print("Number of tokens: %" Pd64 "\n", num_tokens_total); | 103 OS::Print("Number of tokens: %" Pd64 "\n", num_tokens_total); |
57 OS::Print(" Literal tokens: %" Pd64 "\n", num_literal_tokens_total); | 104 OS::Print(" Literal tokens: %" Pd64 "\n", num_literal_tokens_total); |
58 OS::Print(" Ident tokens: %" Pd64 "\n", num_ident_tokens_total); | 105 OS::Print(" Ident tokens: %" Pd64 "\n", num_ident_tokens_total); |
59 OS::Print("Tokens consumed: %" Pd64 " (%.2f times number of tokens)\n", | 106 OS::Print("Tokens consumed: %" Pd64 " (%.2f times number of tokens)\n", |
60 num_tokens_consumed, | 107 num_tokens_consumed, |
61 (1.0 * num_tokens_consumed) / num_tokens_total); | 108 (1.0 * num_tokens_consumed) / num_tokens_total); |
62 OS::Print("Tokens checked: %" Pd64 " (%.2f times tokens consumed)\n", | 109 OS::Print("Tokens checked: %" Pd64 " (%.2f times tokens consumed)\n", |
63 num_token_checks, (1.0 * num_token_checks) / num_tokens_consumed); | 110 num_token_checks, (1.0 * num_token_checks) / num_tokens_consumed); |
64 OS::Print("Token rewind: %" Pd64 " (%" Pd64 "%% of tokens checked)\n", | |
65 num_tokens_rewind, (100 * num_tokens_rewind) / num_token_checks); | |
66 OS::Print("Token lookahead: %" Pd64 " (%" Pd64 "%% of tokens checked)\n", | 111 OS::Print("Token lookahead: %" Pd64 " (%" Pd64 "%% of tokens checked)\n", |
67 num_tokens_lookahead, | 112 num_tokens_lookahead, |
68 (100 * num_tokens_lookahead) / num_token_checks); | 113 (100 * num_tokens_lookahead) / num_token_checks); |
69 | 114 |
70 OS::Print("Classes parsed: %" Pd64 "\n", num_classes_compiled); | 115 OS::Print("Classes parsed: %" Pd64 "\n", num_classes_compiled); |
71 OS::Print("Functions compiled: %" Pd64 "\n", num_functions_compiled); | 116 OS::Print("Functions compiled: %" Pd64 "\n", num_functions_compiled); |
72 OS::Print(" Impl getters: %" Pd64 "\n", num_implicit_final_getters); | 117 OS::Print(" Impl getters: %" Pd64 "\n", num_implicit_final_getters); |
73 | 118 |
74 OS::Print("Source length: %" Pd64 " characters\n", src_length); | 119 OS::Print("Source length: %" Pd64 " characters\n", src_length); |
75 int64_t scan_usecs = scanner_timer.TotalElapsedTime(); | 120 int64_t scan_usecs = scanner_timer.TotalElapsedTime(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 (num_tokens_total * 1024) / total_instr_size); | 167 (num_tokens_total * 1024) / total_instr_size); |
123 OS::Print("Instr size: %" Pd64 " KB\n", | 168 OS::Print("Instr size: %" Pd64 " KB\n", |
124 total_instr_size / 1024); | 169 total_instr_size / 1024); |
125 OS::Print("Pc Desc size: %" Pd64 " KB\n", pc_desc_size / 1024); | 170 OS::Print("Pc Desc size: %" Pd64 " KB\n", pc_desc_size / 1024); |
126 OS::Print("VarDesc size: %" Pd64 " KB\n", vardesc_size / 1024); | 171 OS::Print("VarDesc size: %" Pd64 " KB\n", vardesc_size / 1024); |
127 | 172 |
128 OS::Print("Code size: %" Pd64 " KB\n", total_code_size / 1024); | 173 OS::Print("Code size: %" Pd64 " KB\n", total_code_size / 1024); |
129 } | 174 } |
130 | 175 |
131 } // namespace dart | 176 } // namespace dart |
OLD | NEW |