laixintao / mactop

GNU General Public License v3.0
136 stars 1 forks source link

Failed to load sensors data #1

Open luosheng opened 9 months ago

luosheng commented 9 months ago

As mentioned in Twitter yesterday, the Sensors section always shows loading progress bars. Upon some investigations, I think it's related to powermetrics' arguments not being passed correctly on my machine.

powermetrics -h ``` Usage: powermetrics [-i sample_interval] [-r order] [-t wakeup_cost] Gather and display CPU usage statistics (divided into time spent in user mode and supervisor mode), timer and interrupt wakeup frequency (total and, for near-idle workloads, those that resulted in package C-state exits), and on supported platforms, interrupt frequencies (categorized by CPU number), package C-state statistics (an indication of the time the core complex + integrated graphics, if any, were in low-power idle states), CPU frequency distribution during the sample. The tool may also display estimated power consumed by various SoC subsystems, such as CPU, GPU, ANE (Apple Neural Engine). Note: Average power values reported by powermetrics are estimated and may be inaccurate - hence they should not be used for any comparison between devices, but can be used to help optimize apps for energy efficiency. The following command-line options are supported: -h | --help show this message -A | --show-all Enables all samplers and displays all the available information for each sampler. -a | --poweravg display poweravg every N samples (0=disabled) [default: 10] -b | --buffer-size set output buffer size (0=none, 1=line) -f | --format display data in specified format [default: text] -i | --sample-rate sample every N ms (0=disabled) [default: 5000ms] -n | --sample-count obtain N periodic samples (-1=infinite) [default: -1] -o | --output-file output to file [default: stdout] -r | --order order process list using specified method [default: composite] -s | --samplers comma separated list of samplers and sampler groups -t | --wakeup-cost assume package idle wakeups have a CPU time cost of N us when using hybrid sort orders using idle wakeups with time-based metrics --show-initial-usage print initial sample for entire uptime --show-usage-summary print final usage summary when exiting --show-extra-power-info unsupported power info (may change between releases) --show-pstates show pstate distribution (XCPM only) --show-plimits cpu limiting information --show-cpu-qos show per cpu QOS breakdowns --show-cpu-scalability show per cpu workload scalability --show-hwp-capability show per cpu-thread HWP estimated efficient and guarateed frequencies (instantaneous) --show-process-coalition group processes by coalitions and show per coalition information --show-process-wait-times show per-process sfi wait time info --show-process-qos-tiers show per-process QOS latency and throughput tiers --show-process-io show per-process io information --show-process-gpu show per-process gpu time --show-process-netstats show per-process network information --show-process-qos show QOS times aggregated by process --show-process-amp show per-process AMP information --show-process-energy show per-process energy impact number This implicitly enables sampling of all the above per-process statistics. --show-process-samp-norm Show CPU time normailzed by the sample window. --handle-invalid-values powermetrics will output invalid=true rather than abort when it sees invalid values. --hide-cpu-duty-cycle hide CPU duty cycle data --unhide-info comma separated list of samplers to unhide (backwards compatibility) The following sort orders are supported by --order: pid process identifier wakeups total package idle wakeups (alias: -W) cputime total CPU time used (alias: -C) composite weighted hybrid of package idle wakeups and CPU time used (alias: -O) The following output formats are supported by --format: text human-readable text output plist machine-readable property list, NUL-separated This tool also implements special behavior upon receipt of certain signals to aid with the automated collection of data: SIGINFO take an immediate sample SIGIO flush any buffered output SIGINT/SIGTERM/SIGHUP stop sampling and exit The following samplers are supported by --samplers: tasks per task cpu usage and wakeup stats battery battery and backlight info network network usage info disk disk usage info interrupts interrupt distribution cpu_power cpu power and frequency info thermal thermal pressure notifications sfi selective forced idle information gpu_power gpu power and frequency info ane_power ane power and frequency info and the following sampler groups are supported by --samplers: all tasks,battery,network,disk,interrupts,cpu_power,thermal,sfi,gpu_power,ane_power default tasks,battery,network,disk,interrupts,cpu_power,gpu_power,ane_power ```

As you can see above, the option and value are separate by a space rather than = sign. So the command here might need to be adapted. I'm assuming the = sign style works on your machine. So it might be necessary to run powermetrics -h prior to the sudo powermetrics ... to determine the argument style.

A simple change of the arguments style doesn't fix the problems though. I think it's much likely related to the output format differences between powermetrics distributions, but I didn't dig further. However I did gather a sample json output (by converting from plist) so you might take a look at.

mactop_debug_20231206_15:11:31.json

BTW, this is also the root cause of 'q' key not being responsive. Because powermetrics failed to output the desired output, the readline part just infinitely loops there.

laixintao commented 9 months ago

Hi @luosheng

Thank you so much for the detailed issue.

It seems that your powermetrics didn't include smc info in powermetrics, apple didn't keep any compatibility for powermetrics and ioreg tools, it's very hard for us to write tools based on that.

That's my powermetrics, compare to yours.

image

For now I think you can try mactop -t m1.xml to run based on another theme without the sensors panel? (Or create your own themes!)

I am planning to use https://github.com/dkorunic/iSMC to fetch more data instead of depend on powermetrics.

Args issue fixed. Released in 0.1.10, upgrade by pip install -U mactop.

Btw, you can use the build-in debug feature to get powermetrics samples, I update the doc here: https://github.com/laixintao/mactop#debug

Thank you again for trying mactop and file issues. ;D