Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 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> |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 20 | #include <pixelstats/SysfsCollector.h> |
Stephane Lee | 33a1ce7 | 2021-03-17 15:00:12 -0700 | [diff] [blame] | 21 | #include <pixelstats/UeventListener.h> |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 22 | |
Denny cy Lee | 8101fbc | 2021-05-18 14:50:01 +0800 | [diff] [blame] | 23 | #include <thread> |
| 24 | |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 25 | using android::hardware::google::pixel::SysfsCollector; |
Stephane Lee | 33a1ce7 | 2021-03-17 15:00:12 -0700 | [diff] [blame] | 26 | using android::hardware::google::pixel::UeventListener; |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 27 | |
Ocean Chen | 40448dc | 2022-06-22 01:10:09 +0800 | [diff] [blame] | 28 | #define BLOCK_STATS_LENGTH 17 |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 29 | #define UFSHC_PATH(filename) "/dev/sys/block/bootdevice/" #filename |
Ocean Chen | dd652a2 | 2021-09-09 02:56:32 +0000 | [diff] [blame] | 30 | #define UFS_ERR_PATH(err_type) UFSHC_PATH(err_stats/) #err_type |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 31 | const struct SysfsCollector::SysfsPaths sysfs_paths = { |
Denny cy Lee | 8101fbc | 2021-05-18 14:50:01 +0800 | [diff] [blame] | 32 | .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 Lee | 8101fbc | 2021-05-18 14:50:01 +0800 | [diff] [blame] | 40 | .F2fsStatsPath = "/sys/fs/f2fs/", |
| 41 | .ImpedancePath = "/sys/devices/platform/audiometrics/speaker_impedance", |
| 42 | .CodecPath = "/sys/devices/platform/audiometrics/codec_state", |
George Lee | 99e8538 | 2021-06-29 13:57:58 -0700 | [diff] [blame] | 43 | .EEPROMPath = "/dev/battery_history", |
Roger Fang | a555dec | 2021-08-23 19:11:59 +0800 | [diff] [blame] | 44 | .MitigationPath = "/sys/devices/virtual/pmic/mitigation", |
| 45 | .SpeakerTemperaturePath = "/sys/devices/platform/audiometrics/speaker_temp", |
| 46 | .SpeakerExcursionPath = "/sys/devices/platform/audiometrics/speaker_excursion", |
Ocean Chen | dd652a2 | 2021-09-09 02:56:32 +0000 | [diff] [blame] | 47 | .SpeakerHeartBeatPath = "/sys/devices/platform/audiometrics/speaker_heartbeat", |
Ziyi Cui | cf6265f | 2022-10-24 11:48:16 -0700 | [diff] [blame] | 48 | .ResumeLatencyMetricsPath = "/sys/kernel/metrics/resume_latency/resume_latency_metrics", |
| 49 | .LongIRQMetricsPath = "/sys/kernel/metrics/irq/long_irq_metrics", |
Ziyi Cui | eb0c711 | 2023-05-11 04:02:33 +0000 | [diff] [blame^] | 50 | .StormIRQMetricsPath = "/sys/kernel/metrics/irq/storm_irq_metrics", |
| 51 | .IRQStatsResetPath = "/sys/kernel/metrics/irq/stats_reset", |
Ocean Chen | dd652a2 | 2021-09-09 02:56:32 +0000 | [diff] [blame] | 52 | .UFSErrStatsPath = { |
| 53 | UFS_ERR_PATH(pa_err_count), |
| 54 | UFS_ERR_PATH(dl_err_count), |
| 55 | UFS_ERR_PATH(nl_err_count), |
| 56 | UFS_ERR_PATH(tl_err_count), |
| 57 | UFS_ERR_PATH(dme_err_count), |
| 58 | UFS_ERR_PATH(fatal_err_count), |
| 59 | UFS_ERR_PATH(auto_hibern8_err_count) |
Roger Fang | 78e92a8 | 2022-08-23 17:03:36 +0800 | [diff] [blame] | 60 | }, |
| 61 | .AmsRatePath = "/sys/devices/platform/audiometrics/ams_rate_read_once", |
sashwinbalaji | 755241a | 2023-05-05 10:17:13 +0800 | [diff] [blame] | 62 | .TempResidencyAndResetPaths = { |
| 63 | { |
| 64 | "/sys/kernel/metrics/thermal/tr_by_group/tmu/stats", |
| 65 | "/sys/kernel/metrics/thermal/tr_by_group/tmu/stats_reset" |
| 66 | }, |
| 67 | { |
| 68 | "/sys/kernel/metrics/thermal/tr_by_group/spmic/stats", |
| 69 | "/sys/kernel/metrics/thermal/tr_by_group/spmic/stats_reset" |
| 70 | } |
Ziyi Cui | 607ea7a | 2023-01-24 23:54:10 +0000 | [diff] [blame] | 71 | }, |
Roger Fang | a555dec | 2021-08-23 19:11:59 +0800 | [diff] [blame] | 72 | }; |
| 73 | |
Denny cy Lee | f222773 | 2021-06-08 17:19:41 +0800 | [diff] [blame] | 74 | const struct UeventListener::UeventPaths ueventPaths = { |
| 75 | .AudioUevent = "/devices/virtual/amcs/amcs", |
Badhri Jagan Sridharan | a25b4d6 | 2021-10-05 21:11:41 -0700 | [diff] [blame] | 76 | .TypeCPartnerUevent = "PRODUCT_TYPE="}; |
Roger Fang | d351a65 | 2021-05-06 16:45:25 +0800 | [diff] [blame] | 77 | |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 78 | int main() { |
| 79 | LOG(INFO) << "starting PixelStats"; |
| 80 | |
Denny cy Lee | f222773 | 2021-06-08 17:19:41 +0800 | [diff] [blame] | 81 | UeventListener ueventListener(ueventPaths); |
Stephane Lee | 33a1ce7 | 2021-03-17 15:00:12 -0700 | [diff] [blame] | 82 | std::thread listenThread(&UeventListener::ListenForever, &ueventListener); |
| 83 | listenThread.detach(); |
| 84 | |
Robin Peng | c2b5ca9 | 2021-02-23 20:00:28 +0800 | [diff] [blame] | 85 | SysfsCollector collector(sysfs_paths); |
| 86 | collector.collect(); // This blocks forever. |
| 87 | |
| 88 | return 0; |
| 89 | } |