Last active
November 6, 2018 20:20
-
-
Save jrfondren/cd396d2c156e46d4ac4d73ea55a067e8 to your computer and use it in GitHub Desktop.
unwanted struct initialization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// on macOS: zig build-exe getr.zig --library c --libc-include-dir /usr/local/Cellar/musl-cross/0.9.7_1/libexec/x86_64-linux-musl/include | |
const std = @import("std"); | |
const c = @cImport({ | |
@cInclude("sys/resource.h"); | |
@cInclude("spawn.h"); | |
}); | |
const warn = std.debug.warn; | |
const report_time = | |
\\User time : {} s, {} us | |
\\System time : {} s, {} us | |
\\Time : {} ms ({} ms/per) | |
\\ | |
; | |
const report_rss = | |
\\Max RSS : {} kB | |
\\Shared RSS : {} kB | |
\\Unshared Data : {} | |
\\Unshared Stack : {} | |
\\ | |
; | |
const report = | |
\\Page reclaims : {} | |
\\Page faults : {} | |
\\Swaps : {} | |
\\Block inputs : {} | |
\\Block outputs : {} | |
\\Sigs received : {} | |
\\vol ctx switches : {} | |
\\invol ctx switches : {} | |
\\ | |
; | |
pub fn main() void { | |
const count = 2; | |
var usage: c.struct_rusage = undefined; | |
if (c.getrusage(c.RUSAGE_SELF, @ptrCast(?[*]c.struct_rusage, &usage)) == 0) { | |
const time = @divTrunc((usage.ru_utime.tv_usec + usage.ru_stime.tv_usec), 1000) | |
+ @divTrunc((usage.ru_utime.tv_sec + usage.ru_stime.tv_sec), 1000); | |
const ptime = (@intToFloat(f64, usage.ru_utime.tv_usec + usage.ru_stime.tv_usec)/1000.0 | |
+ (@intToFloat(f64, usage.ru_utime.tv_sec + usage.ru_stime.tv_sec)*1000.0))/@intToFloat(f64, count); | |
warn(report_time, | |
usage.ru_utime.tv_sec, usage.ru_utime.tv_usec, | |
usage.ru_stime.tv_sec, usage.ru_stime.tv_usec, | |
time, ptime); | |
warn(report_rss, | |
usage.ru_maxrss, | |
usage.ru_ixrss, | |
usage.ru_idrss, | |
usage.ru_idrss); | |
warn(report, | |
usage.ru_minflt, | |
usage.ru_majflt, | |
usage.ru_nswap, | |
usage.ru_inblock, | |
usage.ru_oublock, | |
usage.ru_nsignals, | |
usage.ru_nvcsw, | |
usage.ru_nivcsw); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment