poop icon indicating copy to clipboard operation
poop copied to clipboard

Add support for non-Linux platforms (but with fewer measurements)

Open squeek502 opened this issue 2 years ago • 9 comments
trafficstars

This is something of a proof-of-concept. The idea is to include the perf measurements when they are available, but when they're not, only wall time and maxrss are measured and shown. The method of achieving this used in this PR could probably use some work, this is just what I came up with first.

Screenshot from Windows:

poop-on-windows

(benefits from https://github.com/ziglang/zig/pull/16294 to fix the colors)

~~Note: I've only tested it on Windows, so I may have broken Linux inadvertently. EDIT: Yep, I broke Linux--will fix that.~~

squeek502 avatar Jul 02 '23 05:07 squeek502

Potential additions (belongs into new issue, if not implemented here):

    1. Darwin perf counters https://lemire.me/blog/2021/03/24/counting-cycles-and-instructions-on-the-apple-m1-processor/
    1. Windows perfcounters https://learn.microsoft.com/en-us/windows/win32/wmisdk/accessing-performance-data-in-c-- and https://learn.microsoft.com/en-us/windows/win32/api/_perf/, however I have no idea about the ntdll apis and their stabililty.

matu3ba avatar Jul 02 '23 10:07 matu3ba

I'd love to see this merged once conflicts are resolved. Sorry to bother you, but any thoughts, @andrewrk?

p7r0x7 avatar Nov 27 '23 00:11 p7r0x7

I think windows has hardware counters, doesn't it? If so then I think a windows version should use them.

andrewrk avatar Nov 27 '23 00:11 andrewrk

If anyone can point me to a concrete example of how the relevant information can be obtained on Windows (like "here's C++ code that prints out the number of cache misses in a program"), I'd take a look. I can't make heads or tails of any of the documentation/information around it.

My best guess right now is that the answer is effectively, "windows does not have [relevant/useful] hardware counters." With possibly a caveat around Intel processors, specifically.

squeek502 avatar Nov 27 '23 01:11 squeek502

My best guess right now is that the answer is effectively, "windows does not have [relevant/useful] hardware counters." With possibly a caveat around Intel processors, specifically.

ETW are using them. Would be this blog post sufficient? https://adamsitnik.com/Hardware-Counters-ETW/ based on https://github.com/microsoft/perfview/blob/main/documentation/TraceEvent/TraceEventLibrary.md.

Otherwise, I would use this tool, which includes an sophisticated analyzer https://tinyurl.com/etwtracing.

Probably the most simple way is to use WPR and WPA as explained in https://learn.microsoft.com/en-us/windows-hardware/test/wpt/event-tracing-for-windows.

UPDATE: found the lib https://learn.microsoft.com/en-us/windows/win32/api/perflib/ and some more info https://learn.microsoft.com/en-us/windows/win32/perfctrs/using-the-perflib-functions-to-consume-counter-data.

matu3ba avatar Nov 27 '23 01:11 matu3ba

https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-performance_data seems relevant

notcancername avatar Nov 27 '23 01:11 notcancername

Building for MacOS proved successful, but running it only yielded a memory leak and and a couple new lines were printed to the terminal before I had to ^C it.

p7r0x7 avatar Dec 02 '23 01:12 p7r0x7

Any updates @squeek502 ?

p7r0x7 avatar Jan 12 '24 06:01 p7r0x7

Not currently planning on working on this much more. As mentioned in the OP, this is mostly meant as a proof-of-concept. If others want to take it further they are more than welcome to.

I've been hitting something like https://github.com/andrewrk/poop/issues/43 or other stdout/stderr/process spawning related issues often when trying to use poop (especially on Windows), so I've not been using it much personally.

squeek502 avatar Jan 12 '24 23:01 squeek502