| 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/timer.h" | 8 #include "vm/timer.h" |
| 9 | 9 |
| 10 | 10 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 DEFINE_FLAG(bool, compiler_stats, false, "Compiler stat counters."); | 13 DEFINE_FLAG(bool, compiler_stats, false, "Compiler stat counters."); |
| 14 | 14 |
| 15 // Bytes allocated for generated code. | 15 // Bytes allocated for generated code. |
| 16 intptr_t CompilerStats::code_allocated = 0; | 16 intptr_t CompilerStats::code_allocated = 0; |
| 17 | 17 |
| 18 // Total number of characters in source. | 18 // Total number of characters in source. |
| 19 intptr_t CompilerStats::src_length = 0; | 19 intptr_t CompilerStats::src_length = 0; |
| 20 | 20 |
| 21 // Cumulative runtime of parser. | 21 // Cumulative runtime of parser. |
| 22 Timer CompilerStats::parser_timer(true, "parser timer"); | 22 Timer CompilerStats::parser_timer(true, "parser timer"); |
| 23 | 23 |
| 24 // Cumulative runtime of scanner. | 24 // Cumulative runtime of scanner. |
| 25 Timer CompilerStats::scanner_timer(true, "scanner timer"); | 25 Timer CompilerStats::scanner_timer(true, "scanner timer"); |
| 26 | 26 |
| 27 intptr_t CompilerStats::num_tokens_total = 0; | 27 intptr_t CompilerStats::num_tokens_total = 0; |
| 28 intptr_t CompilerStats::num_literal_tokens_total = 0; |
| 29 intptr_t CompilerStats::num_ident_tokens_total = 0; |
| 28 intptr_t CompilerStats::num_tokens_consumed = 0; | 30 intptr_t CompilerStats::num_tokens_consumed = 0; |
| 29 intptr_t CompilerStats::num_token_checks = 0; | 31 intptr_t CompilerStats::num_token_checks = 0; |
| 30 intptr_t CompilerStats::num_tokens_rewind = 0; | 32 intptr_t CompilerStats::num_tokens_rewind = 0; |
| 31 intptr_t CompilerStats::num_tokens_lookahead = 0; | 33 intptr_t CompilerStats::num_tokens_lookahead = 0; |
| 32 | 34 |
| 33 void CompilerStats::Print() { | 35 void CompilerStats::Print() { |
| 34 if (!FLAG_compiler_stats) { | 36 if (!FLAG_compiler_stats) { |
| 35 return; | 37 return; |
| 36 } | 38 } |
| 37 OS::Print("==== Compiler Stats ====\n"); | 39 OS::Print("==== Compiler Stats ====\n"); |
| 38 OS::Print("Number of tokens: %ld\n", num_tokens_total); | 40 OS::Print("Number of tokens: %ld\n", num_tokens_total); |
| 41 OS::Print(" Literal tokens: %ld\n", num_literal_tokens_total); |
| 42 OS::Print(" Ident tokens: %ld\n", num_ident_tokens_total); |
| 39 OS::Print("Tokens consumed: %ld (%.2f times number of tokens)\n", | 43 OS::Print("Tokens consumed: %ld (%.2f times number of tokens)\n", |
| 40 num_tokens_consumed, | 44 num_tokens_consumed, |
| 41 (1.0 * num_tokens_consumed) / num_tokens_total); | 45 (1.0 * num_tokens_consumed) / num_tokens_total); |
| 42 OS::Print("Tokens checked: %ld (%.2f times tokens consumed)\n", | 46 OS::Print("Tokens checked: %ld (%.2f times tokens consumed)\n", |
| 43 num_token_checks, (1.0 * num_token_checks) / num_tokens_consumed); | 47 num_token_checks, (1.0 * num_token_checks) / num_tokens_consumed); |
| 44 OS::Print("Token rewind: %ld (%ld%% of tokens checked)\n", | 48 OS::Print("Token rewind: %ld (%ld%% of tokens checked)\n", |
| 45 num_tokens_rewind, (100 * num_tokens_rewind) / num_token_checks); | 49 num_tokens_rewind, (100 * num_tokens_rewind) / num_token_checks); |
| 46 OS::Print("Token lookahead: %ld (%ld%% of tokens checked)\n", | 50 OS::Print("Token lookahead: %ld (%ld%% of tokens checked)\n", |
| 47 num_tokens_lookahead, | 51 num_tokens_lookahead, |
| 48 (100 * num_tokens_lookahead) / num_token_checks); | 52 (100 * num_tokens_lookahead) / num_token_checks); |
| 49 OS::Print("Source length: %ld characters\n", src_length); | 53 OS::Print("Source length: %ld characters\n", src_length); |
| 50 intptr_t scan_usecs = scanner_timer.TotalElapsedTime(); | 54 intptr_t scan_usecs = scanner_timer.TotalElapsedTime(); |
| 51 OS::Print("Scanner time: %ld msecs\n", | 55 OS::Print("Scanner time: %ld msecs\n", |
| 52 scan_usecs / 1000); | 56 scan_usecs / 1000); |
| 53 intptr_t parse_usecs = parser_timer.TotalElapsedTime(); | 57 intptr_t parse_usecs = parser_timer.TotalElapsedTime(); |
| 54 OS::Print("Compilation time: %ld msecs\n", | 58 OS::Print("Compilation time: %ld msecs\n", |
| 55 parse_usecs / 1000); | 59 parse_usecs / 1000); |
| 56 OS::Print("Compilation speed: %ld tokens per msec\n", | 60 OS::Print("Compilation speed: %ld tokens per msec\n", |
| 57 1000 * num_tokens_total / parse_usecs); | 61 1000 * num_tokens_total / parse_usecs); |
| 58 OS::Print("Code size: %ld KB\n", | 62 OS::Print("Code size: %ld KB\n", |
| 59 code_allocated / 1024); | 63 code_allocated / 1024); |
| 60 OS::Print("Code density: %ld tokens per KB\n", | 64 OS::Print("Code density: %ld tokens per KB\n", |
| 61 num_tokens_total * 1024 / code_allocated); | 65 num_tokens_total * 1024 / code_allocated); |
| 62 } | 66 } |
| 63 | 67 |
| 64 } // namespace dart | 68 } // namespace dart |
| 65 | |
| OLD | NEW |