blob: eb71d45eb8d2c7e4f64b75f219d23d64e3b29545 [file] [log] [blame]
Robin Pengc2b5ca92021-02-23 20:00:28 +08001/*
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>
Robin Pengc2b5ca92021-02-23 20:00:28 +080020#include <pixelstats/SysfsCollector.h>
Stephane Lee33a1ce72021-03-17 15:00:12 -070021#include <pixelstats/UeventListener.h>
Robin Pengc2b5ca92021-02-23 20:00:28 +080022
Denny cy Lee8101fbc2021-05-18 14:50:01 +080023#include <thread>
24
Robin Pengc2b5ca92021-02-23 20:00:28 +080025using android::hardware::google::pixel::SysfsCollector;
Stephane Lee33a1ce72021-03-17 15:00:12 -070026using android::hardware::google::pixel::UeventListener;
Robin Pengc2b5ca92021-02-23 20:00:28 +080027
Ocean Chen40448dc2022-06-22 01:10:09 +080028#define BLOCK_STATS_LENGTH 17
Robin Pengc2b5ca92021-02-23 20:00:28 +080029#define UFSHC_PATH(filename) "/dev/sys/block/bootdevice/" #filename
Ocean Chendd652a22021-09-09 02:56:32 +000030#define UFS_ERR_PATH(err_type) UFSHC_PATH(err_stats/) #err_type
Robin Pengc2b5ca92021-02-23 20:00:28 +080031const struct SysfsCollector::SysfsPaths sysfs_paths = {
Denny cy Lee8101fbc2021-05-18 14:50:01 +080032 .SlowioReadCntPath = UFSHC_PATH(slowio_read_cnt),
33 .SlowioWriteCntPath = UFSHC_PATH(slowio_write_cnt),
34 .SlowioUnmapCntPath = UFSHC_PATH(slowio_unmap_cnt),
35 .SlowioSyncCntPath = UFSHC_PATH(slowio_sync_cnt),
36 .CycleCountBinsPath = "/sys/class/power_supply/battery/cycle_counts",
37 .UFSLifetimeA = UFSHC_PATH(health_descriptor/life_time_estimation_a),
38 .UFSLifetimeB = UFSHC_PATH(health_descriptor/life_time_estimation_b),
39 .UFSLifetimeC = UFSHC_PATH(health_descriptor/life_time_estimation_c),
Denny cy Lee8101fbc2021-05-18 14:50:01 +080040 .F2fsStatsPath = "/sys/fs/f2fs/",
41 .ImpedancePath = "/sys/devices/platform/audiometrics/speaker_impedance",
42 .CodecPath = "/sys/devices/platform/audiometrics/codec_state",
George Lee99e85382021-06-29 13:57:58 -070043 .EEPROMPath = "/dev/battery_history",
Roger Fanga555dec2021-08-23 19:11:59 +080044 .MitigationPath = "/sys/devices/virtual/pmic/mitigation",
45 .SpeakerTemperaturePath = "/sys/devices/platform/audiometrics/speaker_temp",
46 .SpeakerExcursionPath = "/sys/devices/platform/audiometrics/speaker_excursion",
Ocean Chendd652a22021-09-09 02:56:32 +000047 .SpeakerHeartBeatPath = "/sys/devices/platform/audiometrics/speaker_heartbeat",
Ziyi Cuicf6265f2022-10-24 11:48:16 -070048 .ResumeLatencyMetricsPath = "/sys/kernel/metrics/resume_latency/resume_latency_metrics",
49 .LongIRQMetricsPath = "/sys/kernel/metrics/irq/long_irq_metrics",
Ocean Chendd652a22021-09-09 02:56:32 +000050 .UFSErrStatsPath = {
51 UFS_ERR_PATH(pa_err_count),
52 UFS_ERR_PATH(dl_err_count),
53 UFS_ERR_PATH(nl_err_count),
54 UFS_ERR_PATH(tl_err_count),
55 UFS_ERR_PATH(dme_err_count),
56 UFS_ERR_PATH(fatal_err_count),
57 UFS_ERR_PATH(auto_hibern8_err_count)
Roger Fang78e92a82022-08-23 17:03:36 +080058 },
59 .AmsRatePath = "/sys/devices/platform/audiometrics/ams_rate_read_once",
Ziyi Cuie7a25712022-11-17 18:52:10 +000060 .TempResidencyPath = "/sys/kernel/metrics/temp_residency/temp_residency_all/stats",
Roger Fanga555dec2021-08-23 19:11:59 +080061};
62
Denny cy Leef2227732021-06-08 17:19:41 +080063const struct UeventListener::UeventPaths ueventPaths = {
64 .AudioUevent = "/devices/virtual/amcs/amcs",
Badhri Jagan Sridharana25b4d62021-10-05 21:11:41 -070065 .WirelessChargerPtmcPath = "/sys/class/power_supply/wireless/device/ptmc_id",
66 .TypeCPartnerUevent = "PRODUCT_TYPE="};
Roger Fangd351a652021-05-06 16:45:25 +080067
Robin Pengc2b5ca92021-02-23 20:00:28 +080068int main() {
69 LOG(INFO) << "starting PixelStats";
70
Denny cy Leef2227732021-06-08 17:19:41 +080071 UeventListener ueventListener(ueventPaths);
Stephane Lee33a1ce72021-03-17 15:00:12 -070072 std::thread listenThread(&UeventListener::ListenForever, &ueventListener);
73 listenThread.detach();
74
Robin Pengc2b5ca92021-02-23 20:00:28 +080075 SysfsCollector collector(sysfs_paths);
76 collector.collect(); // This blocks forever.
77
78 return 0;
79}