• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 UFSHC_PATH(filename) "/sys/devices/platform/soc/1d84000.ufshc/" #filename
32 const struct SysfsCollector::SysfsPaths sysfs_paths = {
33     .SlowioReadCntPath = UFSHC_PATH(slowio_read_cnt),
34     .SlowioWriteCntPath = UFSHC_PATH(slowio_write_cnt),
35     .SlowioUnmapCntPath = UFSHC_PATH(slowio_unmap_cnt),
36     .SlowioSyncCntPath = UFSHC_PATH(slowio_sync_cnt),
37     .CycleCountBinsPath = "/sys/class/power_supply/battery/cycle_counts",
38     .ImpedancePath = "/sys/devices/platform/codec_detect/resistance_left_right",
39     .CodecPath =     "/sys/devices/platform/codec_detect/codec_state",
40     .SpeechDspPath = "/sys/devices/platform/codec_detect/wdsp_stat",
41     .Codec1Path = "/sys/devices/platform/codec_detect/headset_codec_state",
42     .UFSLifetimeA = UFSHC_PATH(health_descriptor/life_time_estimation_a),
43     .UFSLifetimeB = UFSHC_PATH(health_descriptor/life_time_estimation_b),
44     .UFSLifetimeC = UFSHC_PATH(health_descriptor/life_time_estimation_c),
45     .F2fsStatsPath = "/sys/fs/f2fs/",
46     .EEPROMPath = "/dev/battery_history"
47 };
48 
49 const char *const kAudioUevent = "/kernel/q6audio/q6voice_uevent";
50 const char *const kSSOCDetailsPath = "/sys/class/power_supply/battery/ssoc_details";
51 
main()52 int main() {
53     LOG(INFO) << "starting PixelStats";
54 
55     // b/118713028 Expect failure until drop detect nanoapp is enabled
56     sp<DropDetect> dropDetector = DropDetect::start();
57     if (!dropDetector) {
58         LOG(ERROR) << "Unable to launch drop detection";
59         return 1;
60     }
61 
62     UeventListener ueventListener(kAudioUevent, kSSOCDetailsPath);
63     std::thread listenThread(&UeventListener::ListenForever, &ueventListener);
64     listenThread.detach();
65 
66     SysfsCollector collector(sysfs_paths);
67     collector.collect();  // This blocks forever.
68 
69     return 0;
70 }
71