diff --git a/src/main.zig b/src/main.zig index ec50afa8..56812480 100644 --- a/src/main.zig +++ b/src/main.zig @@ -161,26 +161,18 @@ fn runFile(allocator: Allocator, file_name: []const u8, args: [][:0]u8, flavor: } if (BuildOptions.show_perf and flavor != .Check and flavor != .Fmt) { - const parsing_ms = @as(f64, @floatFromInt(parsing_time)) / 1000000; - const codegen_ms = @as(f64, @floatFromInt(codegen_time)) / 1000000; - const running_ms = @as(f64, @floatFromInt(running_time)) / 1000000; - const gc_ms = @as(f64, @floatFromInt(gc.gc_time)) / 1000000; - const jit_ms = if (vm.jit) |jit| - @as(f64, @floatFromInt(jit.jit_time)) / 1000000 - else - 0; std.debug.print( - "\u{001b}[2mParsing: {d} ms\nCodegen: {d} ms\nRun: {d} ms\nJIT: {d} ms\nGC: {d} ms\nTotal: {d} ms\nFull GC: {} | GC: {} | Max allocated: {} bytes\n\u{001b}[0m", + "\u{001b}[2mParsing: {d}\nCodegen: {d}\nRun: {d}\nJIT: {d}\nGC: {d}\nTotal: {d}\nFull GC: {} | GC: {} | Max allocated: {}\n\u{001b}[0m", .{ - parsing_ms, - codegen_ms, - running_ms, - jit_ms, - gc_ms, - @as(f64, @floatFromInt(if (!is_wasm) total_timer.read() else 0)) / 1000000, + std.fmt.fmtDuration(parsing_time), + std.fmt.fmtDuration(codegen_time), + std.fmt.fmtDuration(running_time), + std.fmt.fmtDuration(if (vm.jit) |jit| jit.jit_time else 0), + std.fmt.fmtDuration(gc.gc_time), + std.fmt.fmtDuration(if (!is_wasm) total_timer.read() else 0), gc.full_collection_count, gc.light_collection_count, - gc.max_allocated, + std.fmt.fmtIntSizeDec(gc.max_allocated), }, ); } diff --git a/src/memory.zig b/src/memory.zig index 0168d1c0..2347fca5 100644 --- a/src/memory.zig +++ b/src/memory.zig @@ -229,7 +229,13 @@ pub const GarbageCollector = struct { const allocated = try self.allocator.create(T); if (BuildOptions.gc_debug) { - std.debug.print("Allocated @{} {}\n", .{ @intFromPtr(allocated), T }); + std.debug.print( + "Allocated @{} {}\n", + .{ + std.fmt.fmtIntSizeDec(@intFromPtr(allocated)), + T, + }, + ); } if (!is_wasm) { @@ -375,7 +381,11 @@ pub const GarbageCollector = struct { if (BuildOptions.gc_debug) { std.debug.print( "(from {}), collected {}, {} allocated\n", - .{ self.bytes_allocated + @sizeOf(T), @sizeOf(T), self.bytes_allocated }, + .{ + std.fmt.fmtIntSizeDec(self.bytes_allocated + @sizeOf(T)), + std.fmt.fmtIntSizeDec(@sizeOf(T)), + std.fmt.fmtIntSizeDec(self.bytes_allocated), + }, ); } @@ -399,9 +409,9 @@ pub const GarbageCollector = struct { std.debug.print( "(from {}), collected {}, {} allocated\n", .{ - self.bytes_allocated + n, - n, - self.bytes_allocated, + std.fmt.fmtIntSizeDec(self.bytes_allocated + n), + std.fmt.fmtIntSizeDec(n), + std.fmt.fmtIntSizeDec(self.bytes_allocated), }, ); } @@ -902,11 +912,11 @@ pub const GarbageCollector = struct { } std.debug.print( - "\nSwept {} objects for {} bytes, now {} bytes\n", + "\nSwept {} objects for {}, now {}\n", .{ obj_count, - @max(swept, self.bytes_allocated) - self.bytes_allocated, - self.bytes_allocated, + std.fmt.fmtIntSizeDec(@max(swept, self.bytes_allocated) - self.bytes_allocated), + std.fmt.fmtIntSizeDec(self.bytes_allocated), }, ); } @@ -930,7 +940,14 @@ pub const GarbageCollector = struct { const mode: Mode = if (self.bytes_allocated > self.next_full_gc and self.last_gc != null) .Full else .Young; if (BuildOptions.gc_debug or BuildOptions.gc_debug_light) { - std.debug.print("-- gc starts mode {}, {} bytes, {} objects\n", .{ mode, self.bytes_allocated, self.objects.len }); + std.debug.print( + "-- gc starts mode {s}, {}, {} objects\n", + .{ + @tagName(mode), + std.fmt.fmtIntSizeDec(self.bytes_allocated), + self.objects.len, + }, + ); // var it = self.active_vms.iterator(); // dumpStack(it.next().?.key_ptr.*); @@ -974,12 +991,12 @@ pub const GarbageCollector = struct { if (BuildOptions.gc_debug or BuildOptions.gc_debug_light) { std.debug.print( - "-- gc end, {} bytes, {} objects, next_gc {}, next_full_gc {}\n", + "-- gc end, {}, {} objects, next_gc {}, next_full_gc {}\n", .{ - self.bytes_allocated, + std.fmt.fmtIntSizeDec(self.bytes_allocated), self.objects.len, - self.next_gc, - self.next_full_gc, + std.fmt.fmtIntSizeDec(self.next_gc), + std.fmt.fmtIntSizeDec(self.next_full_gc), }, ); } diff --git a/src/repl.zig b/src/repl.zig index 19a23513..af422098 100644 --- a/src/repl.zig +++ b/src/repl.zig @@ -292,26 +292,18 @@ fn runSource( } if (BuildOptions.show_perf) { - const parsing_ms: f64 = @as(f64, @floatFromInt(parsing_time)) / 1000000; - const codegen_ms: f64 = @as(f64, @floatFromInt(codegen_time)) / 1000000; - const running_ms: f64 = @as(f64, @floatFromInt(running_time)) / 1000000; - const gc_ms: f64 = @as(f64, @floatFromInt(gc.gc_time)) / 1000000; - const jit_ms: f64 = if (vm.jit) |jit| - @as(f64, @floatFromInt(jit.jit_time)) / 1000000 - else - 0; std.debug.print( - "\u{001b}[2mParsing: {d} ms\nCodegen: {d} ms\nRun: {d} ms\nJIT: {d} ms\nGC: {d} ms\nTotal: {d} ms\nFull GC: {} | GC: {} | Max allocated: {} bytes\n\u{001b}[0m", + "\u{001b}[2mParsing: {d}\nCodegen: {d}\nRun: {d}\nJIT: {d}\nGC: {d}\nTotal: {d}\nFull GC: {} | GC: {} | Max allocated: {} bytes\n\u{001b}[0m", .{ - parsing_ms, - codegen_ms, - running_ms, - jit_ms, - gc_ms, - @as(f64, @floatFromInt(total_timer.read())) / 1000000, + std.fmt.fmtDuration(parsing_time), + std.fmt.fmtDuration(codegen_time), + std.fmt.fmtDuration(running_time), + std.fmt.fmtDuration(if (vm.jit) |jit| jit.jit_time else 0), + std.fmt.fmtDuration(gc.gc_time), + std.fmt.fmtDuration(total_timer.read()), gc.full_collection_count, gc.light_collection_count, - gc.max_allocated, + std.fmt.fmtIntSizeDec(gc.max_allocated), }, ); } diff --git a/src/vm.zig b/src/vm.zig index 466ace62..f5214c10 100644 --- a/src/vm.zig +++ b/src/vm.zig @@ -1956,7 +1956,14 @@ pub const VM = struct { fn OP_LIST(self: *Self, _: *CallFrame, _: u32, _: OpCode, arg: u24) void { var list: *ObjList = self.gc.allocateObject( ObjList, - ObjList.init(self.gc.allocator, self.readConstant(arg).obj().access(ObjTypeDef, .Type, self.gc).?), + ObjList.init( + self.gc.allocator, + self.readConstant(arg).obj().access( + ObjTypeDef, + .Type, + self.gc, + ).?, + ), ) catch |e| { vmPanic(e); unreachable;