Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Mac OSX support #13

Merged
merged 7 commits into from
Nov 18, 2017

Conversation

orls
Copy link
Contributor

@orls orls commented Nov 18, 2017

I saw that issue #7 was marked as postponed, but since I wanted this for my own purposes I decided to have a go.

This implements the minimum possible changes to build & run on OSX/macos. Some notable points:

  • Fine-grained timing isn't available as cheaply/simply as on linux, so I've used coarser clocks/timing info. I doubt this is too much of an issue, as everything in the linux impl is converted down to µsec anyway.
  • No I/O stats. I've searched high and low and can't find any I/O stats per-process in osx without using dtrace, which feels excessive: it would be a complicated integration, requires root, and requires a one-off SIP reconfiguration.

This was built & tested on 10.11 (El Capitan), which is the same as the travis tests. The clock_gettime shim is apparently not required in 10.12+ but I haven't tested it yet.

Owen Smith added 7 commits November 14, 2017 22:54
`clock_gettime` has only been available on mac since 10.12 (Sierra), so shim it on older vers.

This shim is lower resolution, but that matters a lot less given that this usage only wants CLOCK_REALTIME_COARSE. It may not have precisely the same semantics about consistency, but I'm not sure how real a problem that is for this use case.
The timings here are a little cruder than the linux versions, but as with the clock_gettime shim, I'm not sure they're so far from reality as to be problematic.

The I/O stats, however, are much worse. AFAICT macos has no way to get io counters equivalent to what procfs provides. The closest thing I could find would be dtrace probes, which would be ridiculously unwieldy (and I expect costly) for this use case, not to mention requiring root and a one-off SIP reconfig.

I've opted for basic disk io stats from getrusage, based on (hardcoded) block size. Of course, this doesn't include network io, which is a major difference to the linux version.
Using block count from getrusage only reports non-cached disk IO, which is nothing like what the linux impl reports. Short of using dtrace, I can't find anything in macos that does the same, so it's better to not even pretend.
@NoiseByNorthwest
Copy link
Owner

Thanks for your contribution and for bringing php-spx to macOS world !

Micro sec. accuracy is sufficient for timing.
The lack of OS backed I/O stats is not a big issue (as long as it is documented). I will probably end up implementing such metrics via PHP basic I/O function wrappers (already required for network I/O).

@NoiseByNorthwest NoiseByNorthwest merged commit 945367d into NoiseByNorthwest:master Nov 18, 2017
@NoiseByNorthwest
Copy link
Owner

Don't worry for the clock_gettime shim, it can be dropped. I will made some clean up and update README.

@NoiseByNorthwest NoiseByNorthwest mentioned this pull request Nov 18, 2017
@orls
Copy link
Contributor Author

orls commented Nov 18, 2017

Ahh, I did wonder if there was a reason why FP reporter did it's own clock check, instead of using spx_resource_stats_wall_time. That definitely makes things cleaner, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants