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 <utils/StrongPointer.h>
21
22 #include <pixelstats/DropDetect.h>
23 #include <pixelstats/SysfsCollector.h>
24 #include <pixelstats/UeventListener.h>
25
26 using android::sp;
27 using android::hardware::google::pixel::DropDetect;
28 using android::hardware::google::pixel::SysfsCollector;
29 using android::hardware::google::pixel::UeventListener;
30
31 #define BLOCK_STATS_LENGTH 11
32 #define MAXIM_DIR(filename) "/sys/class/power_supply/maxfg/" #filename
33 #define UFSHC_PATH(filename) "/dev/sys/block/bootdevice/" #filename
34 #define UFSHC_HEALTH_PATH(filename) "/dev/sys/block/bootdevice/health/" #filename
35 const struct SysfsCollector::SysfsPaths sysfs_paths = {
36 .SlowioReadCntPath = UFSHC_PATH(slowio_read_cnt),
37 .SlowioWriteCntPath = UFSHC_PATH(slowio_write_cnt),
38 .SlowioUnmapCntPath = UFSHC_PATH(slowio_unmap_cnt),
39 .SlowioSyncCntPath = UFSHC_PATH(slowio_sync_cnt),
40 .CycleCountBinsPath = "/sys/class/power_supply/battery/cycle_counts",
41 .ImpedancePath = "/sys/class/misc/msm_cirrus_playback/resistance_left_right",
42 .CodecPath = "/sys/class/iaxxx-dev/iaxxx_misc/codec_state",
43 .SpeechDspPath = "/sys/class/iaxxx-dev/iaxxx_misc/wdsp_stat",
44 .BatteryCapacityCC = MAXIM_DIR(delta_cc_sum),
45 .BatteryCapacityVFSOC = MAXIM_DIR(delta_vfsoc_sum),
46 .UFSLifetimeA = UFSHC_HEALTH_PATH(lifetimeA),
47 .UFSLifetimeB = UFSHC_HEALTH_PATH(lifetimeB),
48 .UFSLifetimeC = UFSHC_HEALTH_PATH(lifetimeC),
49 .F2fsStatsPath = "/sys/fs/f2fs/",
50 .UFSErrStatsPath = {
51 UFSHC_PATH(err_stats/err_host_reset)
52 }
53 };
54
55 const char *const kAudioUevent = "/kernel/q6audio/q6voice_uevent";
56 const char *const kSSOCDetailsPath = "/sys/class/power_supply/battery/ssoc_details";
57
main()58 int main() {
59 LOG(INFO) << "starting PixelStats";
60
61 sp<DropDetect> dropDetector = DropDetect::start();
62 if (!dropDetector) {
63 LOG(ERROR) << "Unable to launch drop detection";
64 return 1;
65 }
66
67 UeventListener ueventListener(kAudioUevent, kSSOCDetailsPath);
68 std::thread listenThread(&UeventListener::ListenForever, &ueventListener);
69 listenThread.detach();
70
71 SysfsCollector collector(sysfs_paths);
72 collector.collect(); // This blocks forever.
73
74 return 0;
75 }
76