Skip to content

Commit

Permalink
refactor: replace byte-slice Dir paths with Dir handlers (#280)
Browse files Browse the repository at this point in the history
* replace byte-slice dir in gossip dump

* use sig.utils.fmt.boundedFmt instead of std.fmt.allocPrint

* replace forgotten allocPrint with boundedFmt

* fix conflicts with main
  • Loading branch information
sonicfromnewyoke authored Oct 3, 2024
1 parent 734b76e commit 0f04586
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/accountsdb/db.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4304,7 +4304,8 @@ pub const BenchmarkAccountsDB = struct {
);
}
const aligned_size = std.mem.alignForward(usize, size, std.mem.page_size);
const filepath = try std.fmt.allocPrint(allocator, disk_path ++ "slot{d}.bin", .{s});
const filepath_bounded = sig.utils.fmt.boundedFmt(disk_path ++ "slot{d}.bin", .{s});
const filepath = filepath_bounded.constSlice();

const length = blk: {
var file = try std.fs.cwd().createFile(filepath, .{ .read = true });
Expand Down
21 changes: 13 additions & 8 deletions src/gossip/dump_service.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ const Allocator = std.mem.Allocator;
const Atomic = std.atomic.Value;
const SignedGossipData = sig.gossip.data.SignedGossipData;
const GossipTable = sig.gossip.table.GossipTable;
const Duration = sig.time.Duration;
const Logger = sig.trace.log.Logger;
const RwMux = sig.sync.mux.RwMux;

pub const DUMP_INTERVAL = Duration.fromSecs(10);

pub const GossipDumpService = struct {
allocator: Allocator,
logger: Logger,
Expand All @@ -24,16 +27,18 @@ pub const GossipDumpService = struct {
}

const start_time = std.time.timestamp();
const dir = try std.fmt.allocPrint(self.allocator, "gossip-dumps/{}", .{start_time});
defer self.allocator.free(dir);
try std.fs.cwd().makePath(dir);
const dir_name_bounded = sig.utils.fmt.boundedFmt("gossip-dumps/{}", .{start_time});

var dir = try std.fs.cwd().makeOpenPath(dir_name_bounded.constSlice(), .{});
defer dir.close();

while (self.counter.load(.acquire) != idx) {
try self.dumpGossip(dir, start_time);
std.time.sleep(std.time.ns_per_s * 10);
std.time.sleep(DUMP_INTERVAL.asNanos());
}
}

fn dumpGossip(self: *const Self, dir: []const u8, start_time: i64) !void {
fn dumpGossip(self: *const Self, dir: std.fs.Dir, start_time: i64) !void {
const data = blk: {
var gossip_table_lock = self.gossip_table_rw.read();
defer gossip_table_lock.unlock();
Expand Down Expand Up @@ -76,9 +81,9 @@ pub const GossipDumpService = struct {

// create file
const now = std.time.timestamp();
const filename = try std.fmt.allocPrint(self.allocator, "{s}/gossip-dump-{}.csv", .{ dir, now });
defer self.allocator.free(filename);
var file = try std.fs.cwd().createFile(filename, .{});
const filename_bounded = sig.utils.fmt.boundedFmt("gossip-dump-{}.csv", .{now});

var file = try dir.createFile(filename_bounded.constSlice(), .{});
defer file.close();

// output results
Expand Down

0 comments on commit 0f04586

Please sign in to comment.