WARNING: THIS IS A PROJECT IN EARLY DEVELOPMENT, GIT HISTORY WILL BE REWRITTEN !!!
Perf is a package for the Julia programming language that enables you to query the CPU's performance monitoring counters (PMC) which trace how many CPU instructions have been spent for your process, and on which CPU. This feature is provided directly by the CPU, and accessible either directly or through a Linux kernel driver interface, but requires privileged access.
Status: Proof of concept
Works on Julia 0.5 and 0.6, Linux only, with Intel compatible CPUs.
Ultimately, Julia generates machine code. And different coding pattern may turn out to be different in their computational efficiency. Is there a better way than directly asking the CPU whether it has an opinion on this?
Perf is a not yet a registered Julia package; clone from GitHub master branch:
Linux with a kernel version of at least 2.6.33, enabled performance monitoring event feature, and privileged access for the same granted to the executing user, see below.
The performance monitoring capability of the kernel is indicated by the
existence of the file
To be enable to access the Linux kernel provided performance counters, the user must be granted access by setting a paranoid flag. The current setting is obtained from any user account with
$ cat /proc/sys/kernel/perf_event_paranoid
but setting it requires sudo priviledges:
$ sudo sh -c 'echo X > /proc/sys/kernel/perf_event_paranoid'
In the above, replace
X with any of the following integer values, as described
in the Linux kernel sources:
|Paranoia Lvl||Permitted measurements for regular users|
|0||Allow access to CPU-specific data but not raw tracepoint samples|
|1||Allow both kernel and user measurements (default on many systems)|
|2||Allow only user-space measurements|
|≥ 3||Disallow all measurements|
The Linux kernel also manages direct access privileges to the CPU's performance monitoring counters.
This initial release provides the basic wrappers to access the Linux kernel driver and the CPU's performance monitoring counters directly from Julia:
using Perf, the module initialises automatically, or gives warning messages with instructions to resolve the issue — if possible.
register(::Counter)creates and registers a new type.
disable(::Counter)selectively toggle counters.
get(::Counter)retrieves the current counter values.
rdpmc(eax,ecx)emit a low-level assembly instruction, which may be used if direct access privileges are granted, as indicated by
Potential future features may include improved definition and postprocessing of results. However, these features might also go into different packages that already provide dedicated benchmarking facilities.
Production-ready alternatives: ...
The difference: ...
This Julia package Perf is published as open source and licensed under the MIT "Expat" License.
You're welcome to report successful usage or issues on GitHub, and to open pull requests to extend the current functionality.
over 2 years ago