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 };
102 
103 const struct UeventListener::UeventPaths ueventPaths = {
104         .AudioUevent = "/devices/virtual/amcs/amcs",
105         .TypeCPartnerUevent = "PRODUCT_TYPE="};
106 
main()107 int main() {
108     LOG(INFO) << "starting PixelStats";
109 
110     UeventListener ueventListener(ueventPaths);
111     std::thread listenThread(&UeventListener::ListenForever, &ueventListener);
112     listenThread.detach();
113 
114     SysfsCollector collector(sysfs_paths);
115     collector.collect();  // This blocks forever.
116 
117     return 0;
118 }
119