pjrt: profiler support std writer API
expose a more low-level function to customize where to write profile reports
This commit is contained in:
parent
26558d6201
commit
8d795dd676
@ -126,6 +126,19 @@ pub const Profiler = struct {
|
|||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
dir: std.fs.Dir,
|
dir: std.fs.Dir,
|
||||||
file_name: []const u8,
|
file_name: []const u8,
|
||||||
|
) !void {
|
||||||
|
log.info("Writing profiling data to {s}", .{file_name});
|
||||||
|
var output_file = try dir.createFile(file_name, .{});
|
||||||
|
defer output_file.close();
|
||||||
|
var buffered_writer = std.io.bufferedWriter(output_file.writer());
|
||||||
|
try self.dumpAsJsonToWriter(allocator, buffered_writer.writer());
|
||||||
|
try buffered_writer.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn dumpAsJsonToWriter(
|
||||||
|
self: *Profiler,
|
||||||
|
allocator: std.mem.Allocator,
|
||||||
|
writer: anytype,
|
||||||
) !void {
|
) !void {
|
||||||
const profile_data = try self.collectData(allocator);
|
const profile_data = try self.collectData(allocator);
|
||||||
defer profile_data.free(allocator);
|
defer profile_data.free(allocator);
|
||||||
@ -139,12 +152,7 @@ pub const Profiler = struct {
|
|||||||
defer converter.deinit();
|
defer converter.deinit();
|
||||||
try converter.parseXSpaceBytes(profile_data.items(), 1_000_000);
|
try converter.parseXSpaceBytes(profile_data.items(), 1_000_000);
|
||||||
|
|
||||||
var output_file = try dir.createFile(file_name, .{});
|
try converter.toJson(writer);
|
||||||
defer output_file.close();
|
|
||||||
var buffered_writer = std.io.bufferedWriter(output_file.writer());
|
|
||||||
log.info("Writing profiling data to {s}", .{file_name});
|
|
||||||
try converter.toJson(buffered_writer.writer());
|
|
||||||
try buffered_writer.flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check(self: *Profiler, c_error: ?*Error) !void {
|
fn check(self: *Profiler, c_error: ?*Error) !void {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user