-
Notifications
You must be signed in to change notification settings - Fork 466
Mac kext performance tracing #281
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
Changes from all commits
c2910a1
3c86170
5f7cc97
b268599
905258a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| #include "PerformanceTracing.hpp" | ||
| #include <sys/types.h> | ||
| #include <stdatomic.h> | ||
| #include <IOKit/IOUserClient.h> | ||
|
|
||
| PerfTracingProbe profile_probes[Probe_Count]; | ||
|
|
||
| void PerfTracing_Init() | ||
| { | ||
| for (size_t i = 0; i < Probe_Count; ++i) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been trying to minimise the amount of conditionally compiled code as @sanoursa was uneasy about having too much of it due to the potential of it going stale if it's not well exercised. Given the Init functions are only called once, this seemed a relatively benign one to always allow to run. |
||
| { | ||
| PerfTracing_ProbeInit(&profile_probes[i]); | ||
| } | ||
| } | ||
|
|
||
| void PerfTracing_ProbeInit(PerfTracingProbe* probe) | ||
|
pmj marked this conversation as resolved.
|
||
| { | ||
| *probe = PerfTracingProbe{ .min = UINT64_MAX }; | ||
| } | ||
|
|
||
| IOReturn PerfTracing_ExportDataUserClient(IOExternalMethodArguments* arguments) | ||
| { | ||
| #if PRJFS_PERFORMANCE_TRACING_ENABLE | ||
| if (arguments->structureOutput == nullptr || arguments->structureOutputSize != sizeof(profile_probes)) | ||
| { | ||
| return kIOReturnBadArgument; | ||
| } | ||
|
|
||
| memcpy(arguments->structureOutput, profile_probes, sizeof(profile_probes)); | ||
| return kIOReturnSuccess; | ||
| #else | ||
| return kIOReturnUnsupported; | ||
| #endif | ||
| } | ||
|
|
||
| void PerfTracing_RecordSample(PerfTracingProbe* probe, uint64_t startTime, uint64_t endTime) | ||
| { | ||
| uint64_t interval = endTime - startTime; | ||
|
|
||
| atomic_fetch_add(&probe->numSamples1, 1); | ||
| atomic_fetch_add(&probe->sum, interval); | ||
|
|
||
| __uint128_t intervalSquared = interval; | ||
| intervalSquared *= intervalSquared; | ||
| atomic_fetch_add(&probe->sumSquares, intervalSquared); | ||
|
|
||
| // Update minimum sample if necessary | ||
| { | ||
| uint64_t oldMin = atomic_load(&probe->min); | ||
| while (interval < oldMin && !atomic_compare_exchange_weak(&probe->min, &oldMin, interval)) | ||
| {} | ||
| } | ||
|
|
||
| // Update maximum sample if necessary | ||
| { | ||
| uint64_t oldMax = atomic_load(&probe->max); | ||
| while (interval > oldMax && !atomic_compare_exchange_weak(&probe->max, &oldMax, interval)) | ||
| {} | ||
| } | ||
|
|
||
| atomic_fetch_add(&probe->numSamples2, 1); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the impact of this change?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
<ProfileAction>refers to the "Profile" scheme in Xcode. You can't run/profile kexts directly from Xcode of course, but if you select "Product" -> "Build For" -> "Profiling" it will build using the configuration specified here. So with that Xcode command you can (a) quickly check that your code still builds with profiling enabled, and (b) easily build a profiling-enabled kext you can copy to your target machine without manually messing about with the macro.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok thanks!