Crap - a fork of poop with macos support

This is a fork of Andrew Kelly’s excellent tool poop but with macOS support. All credit for macOS support should go to tensorush (see credits in readme). If you are a linux user, there is absolutely no reason to switch to this one, but if you happen to use a mac you can now get poops excellent metrics. If you run it normally it will only report time and max rss, while with sudo it will display most of poops full metrics.

It’s a fork since Andrew stated that he do not want to support more platforms than linux and tensorush never made one. I renamed it because it is slightly crappier due to requiring sudo support on mac and may want to support some more features in the future.

Also suggestions for what crap may stand for are very welcome.

20 Likes

Haha, nice! Thanks for fixing my crappy PR.

Since on macOS those metrics are acquired from performance counters, CRAP should stand for “Counter Reading Acquisition Platform”.

P.S. Btw, it’s tensorush, not tensorrush :wink:

8 Likes

stools of the trade

21 Likes

No thank you, been using poop for about a year but with time and rss only and had in mind to port Counting cycles and instructions on the Apple M1 processor – Daniel Lemire's blog to zig but being a new zig user at the time it was way over my skill level. Also like your naming suggestion.

Haha sorry :sweat_smile:, will fix the spelling, still can’t unsee the extra ’r’.

1 Like

Hi, do you think there are any major obstacles to porting this to Windows?

The timer will work, and rss should be possible as far as I know but don’t hold my word on it. As far as getting the rest of the performance counters I have no clue. I would have to look into that and I don’t really code on windows as my other pc is mainly booted into Linux but I can take a look when I get time.

Otherwise you can always use hyperfine.

1 Like

Thanks, I’m looking to explore cache misses, and i don’t think hyperfine does that, but thanks for mentioning it, I didn’t know about it.

Hyperfine only do wall time but it has a lot more options. It defaults to running the commands in a a shell which gives the option to run more commands (piping) and you can export the data. Also you can do warmup. Though I added the ability to run commands in a shell with -s and do warmup in crap in main branch.

1 Like

Also I don’t think they report cache misses but if you want more detailed profiling information I would look into Tracy and samply. I’m not 100% sure about windows support but may be worth checking out. You can see flamegraph of which functions are slowing you down.

1 Like

well at least I was right about that wall time and rss was going to work…

1 Like

Run chcp 65001 to change the code page to UTF-8. If you want to do that automatically when your program runs, you can do:

    if (builtin.os.tag == .windows) {
        _ = std.os.windows.kernel32.SetConsoleOutputCP(65001);
    }

(but note that the new code page persists past the program exiting)

I have an old branch with Windows support if it’s helpful at all. I think the only relevant thing might be the console size getting code:

        .windows => {
            var info: std.os.windows.CONSOLE_SCREEN_BUFFER_INFO = undefined;
            if (std.os.windows.kernel32.GetConsoleScreenBufferInfo(stdout, &info) != std.os.windows.TRUE) {
                return 80;
            }
            return @intCast(info.dwSize.X);
        },
4 Likes

Thank you! added the following and it works.

    var console_cp: c_uint = undefined;
    if (builtin.os.tag == .windows) {
        console_cp = std.os.windows.kernel32.GetConsoleOutputCP();
        _ = std.os.windows.kernel32.SetConsoleOutputCP(65001);
    }
    defer if (builtin.os.tag == .windows) {
        _ = std.os.windows.kernel32.SetConsoleOutputCP(console_cp);
    };

I love this! I might try to add a PR to add json and csv output support (if that is welcome :slight_smile:). I wanted to chart some benchmarks using poop and I ended up having to write some python code to regex them out of the output. This is a drop-in replacement and it works like a charm in macOS. It’s great to see that a windows support can be available.

Thanks, that would be welcome. Again look at the credits of the readme for the real credit of this tool. Initial windows support is now merged on main if someone would find it useful. Thanks again @squeek502.

1 Like

That \c should be /c FYI.

> cmd.exe /?
Starts a new instance of the Windows command interpreter

CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF]
    [[/S] [/C | /K] string]

/C      Carries out the command specified by string and then terminates
1 Like