Eric Holk | 480d981 | 2021-01-27 23:41:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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 | #include <sstream> |
| 18 | |
| 19 | #include "android-base/logging.h" |
| 20 | #include "base/macros.h" |
| 21 | #include "metrics.h" |
| 22 | |
| 23 | #pragma clang diagnostic push |
| 24 | #pragma clang diagnostic error "-Wconversion" |
| 25 | |
| 26 | namespace art { |
| 27 | namespace metrics { |
| 28 | |
| 29 | std::string DatumName(DatumId datum) { |
| 30 | switch (datum) { |
| 31 | #define ART_COUNTER(name) \ |
| 32 | case DatumId::k##name: \ |
| 33 | return #name; |
| 34 | ART_COUNTERS(ART_COUNTER) |
| 35 | #undef ART_COUNTER |
| 36 | |
| 37 | #define ART_HISTOGRAM(name, num_buckets, low_value, high_value) \ |
| 38 | case DatumId::k##name: \ |
| 39 | return #name; |
| 40 | ART_HISTOGRAMS(ART_HISTOGRAM) |
| 41 | #undef ART_HISTOGRAM |
| 42 | |
| 43 | default: |
| 44 | LOG(FATAL) << "Unknown datum id: " << static_cast<unsigned>(datum); |
| 45 | UNREACHABLE(); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | ArtMetrics::ArtMetrics() : unused_ {} |
| 50 | #define ART_COUNTER(name) \ |
| 51 | , name##_ {} |
| 52 | ART_COUNTERS(ART_COUNTER) |
| 53 | #undef ART_COUNTER |
| 54 | #define ART_HISTOGRAM(name, num_buckets, low_value, high_value) \ |
| 55 | , name##_ {} |
| 56 | ART_HISTOGRAMS(ART_HISTOGRAM) |
| 57 | #undef ART_HISTOGRAM |
| 58 | { |
| 59 | } |
| 60 | |
| 61 | void ArtMetrics::ReportAllMetrics(MetricsBackend* backend) const { |
| 62 | // Dump counters |
| 63 | #define ART_COUNTER(name) name()->Report(backend); |
| 64 | ART_COUNTERS(ART_COUNTER) |
| 65 | #undef ART_COUNTERS |
| 66 | |
| 67 | // Dump histograms |
| 68 | #define ART_HISTOGRAM(name, num_buckets, low_value, high_value) name()->Report(backend); |
| 69 | ART_HISTOGRAMS(ART_HISTOGRAM) |
| 70 | #undef ART_HISTOGRAM |
| 71 | } |
| 72 | |
| 73 | void ArtMetrics::DumpForSigQuit(std::ostream& os) const { |
| 74 | os << "\n*** ART internal metrics ***\n\n"; |
| 75 | StreamBackend backend{os}; |
| 76 | ReportAllMetrics(&backend); |
| 77 | os << "\n*** Done dumping ART internal metrics ***\n"; |
| 78 | } |
| 79 | |
Eric Holk | 480d981 | 2021-01-27 23:41:45 +0000 | [diff] [blame] | 80 | StreamBackend::StreamBackend(std::ostream& os) : os_{os} {} |
| 81 | |
| 82 | void StreamBackend::BeginSession([[maybe_unused]] const SessionData& session_data) { |
| 83 | // Not needed for now. |
| 84 | } |
| 85 | |
| 86 | void StreamBackend::EndSession() { |
| 87 | // Not needed for now. |
| 88 | } |
| 89 | |
| 90 | void StreamBackend::ReportCounter(DatumId counter_type, uint64_t value) { |
| 91 | os_ << DatumName(counter_type) << ": count = " << value << "\n"; |
| 92 | } |
| 93 | |
| 94 | void StreamBackend::ReportHistogram(DatumId histogram_type, |
| 95 | int64_t minimum_value_, |
| 96 | int64_t maximum_value_, |
| 97 | const std::vector<uint32_t>& buckets) { |
| 98 | os_ << DatumName(histogram_type) << ": range = " << minimum_value_ << "..." << maximum_value_; |
| 99 | if (buckets.size() > 0) { |
| 100 | os_ << ", buckets: "; |
| 101 | bool first = true; |
| 102 | for (const auto& count : buckets) { |
| 103 | if (!first) { |
| 104 | os_ << ","; |
| 105 | } |
| 106 | first = false; |
| 107 | os_ << count; |
| 108 | } |
| 109 | os_ << "\n"; |
| 110 | } else { |
| 111 | os_ << ", no buckets\n"; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | } // namespace metrics |
| 116 | } // namespace art |
| 117 | |
| 118 | #pragma clang diagnostic pop // -Wconversion |