Created
September 28, 2023 09:26
-
-
Save The-King-of-Toasters/aee448f5975c50f735fd1946794574f7 to your computer and use it in GitHub Desktop.
cachestat example
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
const std = @import("std"); | |
const os = std.os; | |
const process = std.process; | |
const linux = os.linux; | |
pub fn main() !void { | |
var args = std.process.ArgIteratorPosix.init(); | |
_ = args.skip(); | |
const out = std.io.getStdOut(); | |
var buf = std.io.bufferedWriter(out.writer()); | |
const writer = buf.writer(); | |
const range = linux.cache_stat_range{ | |
.off = 0, | |
.len = 0, | |
}; | |
var stat: linux.cache_stat = undefined; | |
while (args.next()) |arg| { | |
const file = std.fs.cwd().openFile(arg, .{}) catch |err| switch (err) { | |
error.AccessDenied, error.FileNotFound => continue, | |
else => return err, | |
}; | |
defer file.close(); | |
const meta = try file.metadata(); | |
if (meta.kind() != .file) | |
continue; | |
const rc = linux.cachestat(file.handle, &range, &stat, 0); | |
if (rc != 0) { | |
std.debug.print("could not get stat for file {s}, {}", .{ arg, rc }); | |
continue; | |
} | |
try writer.print( | |
\\Page stats for {s}: | |
\\Cached: {} | |
\\Dirty: {} | |
\\Marked for Writeback: {} | |
\\Total Evicted: {} | |
\\Recently Evicted: {} | |
\\ | |
\\ | |
, .{ | |
arg, | |
stat.cache, | |
stat.dirty, | |
stat.writeback, | |
stat.evicted, | |
stat.recently_evicted, | |
}); | |
} | |
try buf.flush(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment