blob: cc2723df99c3bf51bfcde15bc47ff3d99b150e86 [file] [log] [blame]
Calin Juravle48c2b032014-12-09 18:11:36 +00001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_
18#define ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_
19
20#include <sstream>
21#include <string>
22
23#include "atomic.h"
24
25namespace art {
26
27enum MethodCompilationStat {
28 kAttemptCompilation = 0,
29 kCompiledBaseline,
30 kCompiledOptimized,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000031 kInlinedInvoke,
Calin Juravle48c2b032014-12-09 18:11:36 +000032 kNotCompiledUnsupportedIsa,
33 kNotCompiledPathological,
34 kNotCompiledHugeMethod,
35 kNotCompiledLargeMethodNoBranches,
36 kNotCompiledCannotBuildSSA,
37 kNotCompiledNoCodegen,
38 kNotCompiledUnresolvedMethod,
39 kNotCompiledUnresolvedField,
40 kNotCompiledNonSequentialRegPair,
Calin Juravle48c2b032014-12-09 18:11:36 +000041 kNotOptimizedTryCatch,
42 kNotOptimizedDisabled,
43 kNotCompiledCantAccesType,
44 kNotOptimizedRegisterAllocator,
45 kNotCompiledUnhandledInstruction,
46 kLastStat
47};
48
49class OptimizingCompilerStats {
50 public:
51 OptimizingCompilerStats() {}
52
53 void RecordStat(MethodCompilationStat stat) {
54 compile_stats_[stat]++;
55 }
56
57 void Log() const {
58 if (compile_stats_[kAttemptCompilation] == 0) {
59 LOG(INFO) << "Did not compile any method.";
60 } else {
61 size_t unoptimized_percent =
62 compile_stats_[kCompiledBaseline] * 100 / compile_stats_[kAttemptCompilation];
63 size_t optimized_percent =
64 compile_stats_[kCompiledOptimized] * 100 / compile_stats_[kAttemptCompilation];
65 std::ostringstream oss;
66 oss << "Attempted compilation of " << compile_stats_[kAttemptCompilation] << " methods: "
67 << unoptimized_percent << "% (" << compile_stats_[kCompiledBaseline] << ") unoptimized, "
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000068 << optimized_percent << "% (" << compile_stats_[kCompiledOptimized] << ") optimized.";
Calin Juravle48c2b032014-12-09 18:11:36 +000069 for (int i = 0; i < kLastStat; i++) {
70 if (compile_stats_[i] != 0) {
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000071 oss << "\n" << PrintMethodCompilationStat(i) << ": " << compile_stats_[i];
Calin Juravle48c2b032014-12-09 18:11:36 +000072 }
73 }
74 LOG(INFO) << oss.str();
75 }
76 }
77
78 private:
79 std::string PrintMethodCompilationStat(int stat) const {
80 switch (stat) {
81 case kAttemptCompilation : return "kAttemptCompilation";
82 case kCompiledBaseline : return "kCompiledBaseline";
83 case kCompiledOptimized : return "kCompiledOptimized";
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000084 case kInlinedInvoke : return "kInlinedInvoke";
Calin Juravle48c2b032014-12-09 18:11:36 +000085 case kNotCompiledUnsupportedIsa : return "kNotCompiledUnsupportedIsa";
86 case kNotCompiledPathological : return "kNotCompiledPathological";
87 case kNotCompiledHugeMethod : return "kNotCompiledHugeMethod";
88 case kNotCompiledLargeMethodNoBranches : return "kNotCompiledLargeMethodNoBranches";
89 case kNotCompiledCannotBuildSSA : return "kNotCompiledCannotBuildSSA";
90 case kNotCompiledNoCodegen : return "kNotCompiledNoCodegen";
91 case kNotCompiledUnresolvedMethod : return "kNotCompiledUnresolvedMethod";
92 case kNotCompiledUnresolvedField : return "kNotCompiledUnresolvedField";
93 case kNotCompiledNonSequentialRegPair : return "kNotCompiledNonSequentialRegPair";
Calin Juravle48c2b032014-12-09 18:11:36 +000094 case kNotOptimizedDisabled : return "kNotOptimizedDisabled";
95 case kNotOptimizedTryCatch : return "kNotOptimizedTryCatch";
96 case kNotCompiledCantAccesType : return "kNotCompiledCantAccesType";
97 case kNotOptimizedRegisterAllocator : return "kNotOptimizedRegisterAllocator";
98 case kNotCompiledUnhandledInstruction : return "kNotCompiledUnhandledInstruction";
99 default: LOG(FATAL) << "invalid stat";
100 }
101 return "";
102 }
103
104 AtomicInteger compile_stats_[kLastStat];
105
106 DISALLOW_COPY_AND_ASSIGN(OptimizingCompilerStats);
107};
108
109} // namespace art
110
111#endif // ART_COMPILER_OPTIMIZING_OPTIMIZING_COMPILER_STATS_H_