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 BLOCK_STATS_LENGTH 17
32 #define UFSHC_PATH(filename) "/dev/sys/block/bootdevice/" #filename
33 #define UFS_ERR_PATH(err_type) UFSHC_PATH(err_stats/) #err_type
34 const struct SysfsCollector::SysfsPaths sysfs_paths = {
35     .SlowioReadCntPath = UFSHC_PATH(slowio_read_cnt),
36     .SlowioWriteCntPath = UFSHC_PATH(slowio_write_cnt),
37     .SlowioUnmapCntPath = UFSHC_PATH(slowio_unmap_cnt),
38     .SlowioSyncCntPath = UFSHC_PATH(slowio_sync_cnt),
39     .CycleCountBinsPath = "/sys/class/power_supply/battery/cycle_counts",
40     .UFSLifetimeA = UFSHC_PATH(health_descriptor/life_time_estimation_a),
41     .UFSLifetimeB = UFSHC_PATH(health_descriptor/life_time_estimation_b),
42     .UFSLifetimeC = UFSHC_PATH(health_descriptor/life_time_estimation_c),
43     .F2fsStatsPath = "/sys/fs/f2fs/",
44     .ImpedancePath = "/sys/devices/platform/audiometrics/speaker_impedance",
45     .CodecPath =     "/sys/devices/platform/audiometrics/codec_state",
46     .EEPROMPath = "/dev/battery_history",
47     .MitigationPath = "/sys/devices/virtual/pmic/mitigation",
48     .MitigationDurationPath = "/sys/devices/virtual/pmic/mitigation/irq_dur_cnt",
49     .BrownoutReasonProp = "vendor.brownout_reason",
50     .BrownoutLogPath = "/data/vendor/mitigation/lastmeal.txt",
51     .SpeakerTemperaturePath = "/sys/devices/platform/audiometrics/speaker_temp",
52     .SpeakerExcursionPath = "/sys/devices/platform/audiometrics/speaker_excursion",
53     .SpeakerHeartBeatPath = "/sys/devices/platform/audiometrics/speaker_heartbeat",
54     .UFSErrStatsPath = {
55         UFS_ERR_PATH(pa_err_count),
56         UFS_ERR_PATH(dl_err_count),
57         UFS_ERR_PATH(nl_err_count),
58         UFS_ERR_PATH(tl_err_count),
59         UFS_ERR_PATH(dme_err_count),
60         UFS_ERR_PATH(fatal_err_count),
61         UFS_ERR_PATH(auto_hibern8_err_count)
62     },
63     .BlockStatsLength = BLOCK_STATS_LENGTH,
64     .AmsRatePath = "/sys/devices/platform/audiometrics/ams_rate_read_once",
65     .MitigationPath = "/sys/devices/virtual/pmic/mitigation",
66     .ThermalStatsPaths = {
67         "/sys/devices/platform/100a0000.BIG/trip_counter",
68         "/sys/devices/platform/100a0000.MID/trip_counter",
69         "/sys/devices/platform/100a0000.LITTLE/trip_counter",
70         "/sys/devices/platform/100b0000.G3D/trip_counter",
71         "/sys/devices/platform/100b0000.TPU/trip_counter",
72         "/sys/devices/platform/100b0000.AUR/trip_counter",
73     },
74     .CCARatePath = "/sys/devices/platform/audiometrics/cca_count_read_once",
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     .ResumeLatencyMetricsPath = "/sys/kernel/metrics/resume_latency/resume_latency_metrics",
86     .LongIRQMetricsPath = "/sys/kernel/metrics/irq/long_irq_metrics",
87     .StormIRQMetricsPath = "/sys/kernel/metrics/irq/storm_irq_metrics",
88     .IRQStatsResetPath = "/sys/kernel/metrics/irq/stats_reset",
89     .ModemPcieLinkStatsPath = "/sys/devices/platform/11920000.pcie/link_stats",
90     .WifiPcieLinkStatsPath = "/sys/devices/platform/14520000.pcie/link_stats",
91     .GMSRPath = {
92         "/sys/class/power_supply/maxfg/gmsr",
93         "/sys/class/power_supply/maxfg_base/gmsr",
94     },
95     .FGModelLoadingPath = {
96         "/sys/class/power_supply/maxfg/m5_model_state",
97         "/sys/class/power_supply/maxfg_base/m5_model_state"
98     },
99     .FGLogBufferPath = {
100         "/dev/logbuffer_maxfg_monitor",
101         "/dev/logbuffer_max77779fg_monitor",
102         "/dev/logbuffer_maxfg_base_monitor",
103         "/dev/logbuffer_maxfg_secondary_monitor"
104     },
105     .TotalCallCountPath = "/sys/devices/platform/audiometrics/call_count"
106 };
107 
108 const struct UeventListener::UeventPaths ueventPaths = {
109         .AudioUevent = "/devices/virtual/amcs/amcs",
110         .TypeCPartnerUevent = "PRODUCT_TYPE=",
111         .FwUpdatePath = ""
112 };
113 
main()114 int main() {
115     LOG(INFO) << "starting PixelStats";
116 
117     UeventListener ueventListener(ueventPaths);
118     std::thread listenThread(&UeventListener::ListenForever, &ueventListener);
119     listenThread.detach();
120 
121     SysfsCollector collector(sysfs_paths);
122     collector.collect();  // This blocks forever.
123 
124     return 0;
125 }
126