1 /*
2 * Copyright (C) 2018 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 #define LOG_TAG "pixelstats"
18
19 #include <android-base/logging.h>
20 #include <pixelstats/SysfsCollector.h>
21 #include <pixelstats/UeventListener.h>
22
23 #include <thread>
24
25 #include <pixelstats/SysfsCollector.h>
26 #include <pixelstats/UeventListener.h>
27
28 using android::hardware::google::pixel::SysfsCollector;
29 using android::hardware::google::pixel::UeventListener;
30
31 #define UFSHC_PATH(filename) "/dev/sys/block/bootdevice/" #filename
32 #define UFS_ERR_PATH(err_type) UFSHC_PATH(err_stats/) #err_type
33 const struct SysfsCollector::SysfsPaths sysfs_paths = {
34 .SlowioReadCntPath = UFSHC_PATH(slowio_read_cnt),
35 .SlowioWriteCntPath = UFSHC_PATH(slowio_write_cnt),
36 .SlowioUnmapCntPath = UFSHC_PATH(slowio_unmap_cnt),
37 .SlowioSyncCntPath = UFSHC_PATH(slowio_sync_cnt),
38 .CycleCountBinsPath = "/sys/class/power_supply/battery/cycle_counts",
39 .UFSLifetimeA = UFSHC_PATH(health_descriptor/life_time_estimation_a),
40 .UFSLifetimeB = UFSHC_PATH(health_descriptor/life_time_estimation_b),
41 .UFSLifetimeC = UFSHC_PATH(health_descriptor/life_time_estimation_c),
42 .F2fsStatsPath = "/sys/fs/f2fs/",
43 .ImpedancePath = "/sys/devices/platform/audiometrics/speaker_impedance",
44 .CodecPath = "/sys/devices/platform/audiometrics/codec_state",
45 .EEPROMPath = "/dev/battery_history",
46 .MitigationPath = "/sys/devices/virtual/pmic/mitigation",
47 .BrownoutReasonProp = "vendor.brownout_reason",
48 .BrownoutCsvPath = "/data/vendor/mitigation/lastmeal.csv",
49 .BrownoutLogPath = "/data/vendor/mitigation/lastmeal.txt",
50 .SpeakerTemperaturePath = "/sys/devices/platform/audiometrics/speaker_temp",
51 .SpeakerExcursionPath = "/sys/devices/platform/audiometrics/speaker_excursion",
52 .SpeakerHeartBeatPath = "/sys/devices/platform/audiometrics/speaker_heartbeat",
53 .UFSErrStatsPath = {
54 UFS_ERR_PATH(pa_err_count),
55 UFS_ERR_PATH(dl_err_count),
56 UFS_ERR_PATH(nl_err_count),
57 UFS_ERR_PATH(tl_err_count),
58 UFS_ERR_PATH(dme_err_count),
59 UFS_ERR_PATH(fatal_err_count),
60 UFS_ERR_PATH(auto_hibern8_err_count)
61 },
62 .AmsRatePath = "/sys/devices/platform/audiometrics/ams_rate_read_once",
63 .ResumeLatencyMetricsPath = "/sys/kernel/metrics/resume_latency/resume_latency_metrics",
64 .LongIRQMetricsPath = "/sys/kernel/metrics/irq/long_irq_metrics",
65 .StormIRQMetricsPath = "/sys/kernel/metrics/irq/storm_irq_metrics",
66 .IRQStatsResetPath = "/sys/kernel/metrics/irq/stats_reset",
67 .ThermalStatsPaths = {
68 "/sys/devices/platform/100a0000.BIG/trip_counter",
69 "/sys/devices/platform/100a0000.MID/trip_counter",
70 "/sys/devices/platform/100a0000.LITTLE/trip_counter",
71 "/sys/devices/platform/100b0000.G3D/trip_counter",
72 "/sys/devices/platform/100b0000.TPU/trip_counter",
73 "/sys/devices/platform/100b0000.AUR/trip_counter",
74 },
75 .TempResidencyAndResetPaths = {
76 {
77 "/sys/kernel/metrics/thermal/tr_by_group/tmu/stats",
78 "/sys/kernel/metrics/thermal/tr_by_group/tmu/stats_reset"
79 },
80 {
81 "/sys/kernel/metrics/thermal/tr_by_group/spmic/stats",
82 "/sys/kernel/metrics/thermal/tr_by_group/spmic/stats_reset"
83 }
84 },
85 .ModemPcieLinkStatsPath = "/sys/devices/platform/12100000.pcie/link_stats",
86 .WifiPcieLinkStatsPath = "/sys/devices/platform/13120000.pcie/link_stats",
87 .GMSRPath = {
88 "/sys/class/power_supply/max77779fg/gmsr",
89 "/sys/class/power_supply/maxfg_base/gmsr",
90 },
91 .FGModelLoadingPath = {
92 "/sys/class/power_supply/max77779fg/model_state",
93 "/sys/class/power_supply/maxfg_base/model_state"
94 },
95 .FGLogBufferPath = {
96 "/dev/logbuffer_maxfg_monitor",
97 "/dev/logbuffer_max77779fg_monitor",
98 "/dev/logbuffer_maxfg_base_monitor",
99 "/dev/logbuffer_maxfg_secondary_monitor"
100 },
101 .PDMStatePath = "/sys/devices/platform/audiometrics/pdm_state",
102 .WavesPath = "/sys/devices/platform/audiometrics/waves",
103 .AdaptedInfoCountPath = "/sys/devices/platform/audiometrics/adapted_info_active_count",
104 .AdaptedInfoDurationPath = "/sys/devices/platform/audiometrics/adapted_info_active_duration",
105 .CCARatePath = "/sys/devices/platform/audiometrics/cca_count_read_once",
106 .PcmLatencyPath = "/sys/devices/platform/audiometrics/pcm_latency",
107 .PcmCountPath = "/sys/devices/platform/audiometrics/pcm_count",
108 .TotalCallCountPath = "/sys/devices/platform/audiometrics/call_count",
109 .OffloadEffectsIdPath = "/sys/devices/platform/audiometrics/offload_effects_id",
110 .OffloadEffectsDurationPath = "/sys/devices/platform/audiometrics/offload_effects_duration",
111 .BluetoothAudioUsagePath = "/sys/devices/platform/audiometrics/bt_usage",
112 .DisplayPortStatsPaths = {
113 "/sys/devices/platform/exynos-drm/displayport/drm-displayport-stats/link_negotiation_failures",
114 "/sys/devices/platform/exynos-drm/displayport/drm-displayport-stats/edid_read_failures",
115 "/sys/devices/platform/exynos-drm/displayport/drm-displayport-stats/dpcd_read_failures",
116 "/sys/devices/platform/exynos-drm/displayport/drm-displayport-stats/edid_invalid_failures",
117 "/sys/devices/platform/exynos-drm/displayport/drm-displayport-stats/sink_count_invalid_failures",
118 "/sys/devices/platform/exynos-drm/displayport/drm-displayport-stats/link_unstable_failures",
119 },
120 .HDCPStatsPaths = {
121 "/sys/devices/platform/hdcp/hdcp2_success_count",
122 "/sys/devices/platform/hdcp/hdcp2_fallback_count",
123 "/sys/devices/platform/hdcp/hdcp2_fail_count",
124 "/sys/devices/platform/hdcp/hdcp1_success_count",
125 "/sys/devices/platform/hdcp/hdcp1_fail_count",
126 "/sys/devices/platform/hdcp/hdcp0_count",
127 },
128 .DisplayStatsPaths = {
129 "/sys/devices/platform/exynos-drm/primary-panel/error_count_te",
130 "/sys/devices/platform/exynos-drm/primary-panel/error_count_unknown",
131 "/sys/devices/platform/exynos-drm/secondary-panel/error_count_te",
132 "/sys/devices/platform/exynos-drm/secondary-panel/error_count_unknown",
133 },
134 .SpeakerVersionPath = "/sys/devices/platform/audiometrics/speaker_version"
135 };
136
137 const struct UeventListener::UeventPaths ueventPaths = {
138 .AudioUevent = "/devices/virtual/amcs/amcs",
139 .TypeCPartnerUevent = "PRODUCT_TYPE=",
140 .FwUpdatePath = "/sys/devices/platform/maxim,max77779fwu/update_stats",
141 .FGAbnlPath = {
142 "/dev/logbuffer_max77779fg_monitor",
143 "/dev/logbuffer_maxfg_base_monitor",
144 }
145 };
146
main()147 int main() {
148 LOG(INFO) << "starting PixelStats";
149
150 UeventListener ueventListener(ueventPaths);
151 std::thread listenThread(&UeventListener::ListenForever, &ueventListener);
152 listenThread.detach();
153
154 SysfsCollector collector(sysfs_paths);
155 collector.collect(); // This blocks forever.
156
157 return 0;
158 }
159