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 .MitigationDurationPath = "/sys/devices/virtual/pmic/mitigation/irq_dur_cnt",
48 .BrownoutReasonProp = "vendor.brownout_reason",
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 .ThermalStatsPaths = {
64 "/sys/devices/platform/100a0000.BIG/trip_counter",
65 "/sys/devices/platform/100a0000.MID/trip_counter",
66 "/sys/devices/platform/100a0000.LITTLE/trip_counter",
67 "/sys/devices/platform/100b0000.G3D/trip_counter",
68 "/sys/devices/platform/100b0000.TPU/trip_counter",
69 "/sys/devices/platform/100b0000.AUR/trip_counter",
70 },
71 .ResumeLatencyMetricsPath = "/sys/kernel/metrics/resume_latency/resume_latency_metrics",
72 .LongIRQMetricsPath = "/sys/kernel/metrics/irq/long_irq_metrics",
73 .StormIRQMetricsPath = "/sys/kernel/metrics/irq/storm_irq_metrics",
74 .IRQStatsResetPath = "/sys/kernel/metrics/irq/stats_reset",
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 .DisplayStatsPaths = {
88 "/sys/devices/platform/exynos-drm/primary-panel/error_count_te",
89 "/sys/devices/platform/exynos-drm/primary-panel/error_count_unknown",
90 "/sys/devices/platform/exynos-drm/secondary-panel/error_count_te",
91 "/sys/devices/platform/exynos-drm/secondary-panel/error_count_unknown",
92 },
93 .PDMStatePath = "/sys/devices/platform/audiometrics/pdm_state",
94 .WavesPath = "/sys/devices/platform/audiometrics/waves",
95 .AdaptedInfoCountPath = "/sys/devices/platform/audiometrics/adapted_info_active_count",
96 .AdaptedInfoDurationPath = "/sys/devices/platform/audiometrics/adapted_info_active_duration",
97 .CCARatePath = "/sys/devices/platform/audiometrics/cca_count_read_once",
98 .PcmLatencyPath = "/sys/devices/platform/audiometrics/pcm_latency",
99 .PcmCountPath = "/sys/devices/platform/audiometrics/pcm_count",
100 .TotalCallCountPath = "/sys/devices/platform/audiometrics/call_count",
101 .OffloadEffectsIdPath = "/sys/devices/platform/audiometrics/offload_effects_id",
102 .OffloadEffectsDurationPath = "/sys/devices/platform/audiometrics/offload_effects_duration",
103 .BluetoothAudioUsagePath = "/sys/devices/platform/audiometrics/bt_usage",
104 .GMSRPath = {
105 "/sys/class/power_supply/maxfg/gmsr",
106 "/sys/class/power_supply/maxfg_base/gmsr",
107 },
108 .FGModelLoadingPath = {
109 "/sys/class/power_supply/maxfg/m5_model_state",
110 "/sys/class/power_supply/maxfg_base/m5_model_state"
111 },
112 .FGLogBufferPath = {
113 "/dev/logbuffer_maxfg_monitor",
114 "/dev/logbuffer_max77779fg_monitor",
115 "/dev/logbuffer_maxfg_base_monitor",
116 "/dev/logbuffer_maxfg_secondary_monitor"
117 },
118 .DisplayPortStatsPaths = {
119 "/sys/devices/platform/exynos-drm/displayport/drm-displayport-stats/link_negotiation_failures",
120 "/sys/devices/platform/exynos-drm/displayport/drm-displayport-stats/edid_read_failures",
121 "/sys/devices/platform/exynos-drm/displayport/drm-displayport-stats/dpcd_read_failures",
122 "/sys/devices/platform/exynos-drm/displayport/drm-displayport-stats/edid_invalid_failures",
123 "/sys/devices/platform/exynos-drm/displayport/drm-displayport-stats/sink_count_invalid_failures",
124 "/sys/devices/platform/exynos-drm/displayport/drm-displayport-stats/link_unstable_failures",
125 },
126 .HDCPStatsPaths = {
127 "/sys/devices/platform/hdcp/hdcp2_success_count",
128 "/sys/devices/platform/hdcp/hdcp2_fallback_count",
129 "/sys/devices/platform/hdcp/hdcp2_fail_count",
130 "/sys/devices/platform/hdcp/hdcp1_success_count",
131 "/sys/devices/platform/hdcp/hdcp1_fail_count",
132 "/sys/devices/platform/hdcp/hdcp0_count",
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 = ""
141 };
142
main()143 int main() {
144 LOG(INFO) << "starting PixelStats";
145
146 UeventListener ueventListener(ueventPaths);
147 std::thread listenThread(&UeventListener::ListenForever, &ueventListener);
148 listenThread.detach();
149
150 SysfsCollector collector(sysfs_paths);
151 collector.collect(); // This blocks forever.
152
153 return 0;
154 }
155