Merge pull request #2112 from lightpanda-io/reduce_telemetry_size

Reduces the size of Telemetry.Lightpanda
This commit is contained in:
Karl Seguin
2026-04-10 07:07:55 +08:00
committed by GitHub
3 changed files with 13 additions and 13 deletions

View File

@@ -31,12 +31,13 @@ pub fn main() !void {
// allocator
// - in Debug mode we use the General Purpose Allocator to detect memory leaks
// - in Release mode we use the c allocator
var gpa_instance: std.heap.DebugAllocator(.{ .stack_trace_frames = 10 }) = .init;
const gpa = if (builtin.mode == .Debug) gpa_instance.allocator() else std.heap.c_allocator;
// var gpa_instance: std.heap.DebugAllocator(.{ .stack_trace_frames = 10 }) = .init;
// const gpa = if (builtin.mode == .Debug) gpa_instance.allocator() else std.heap.c_allocator;
const gpa = std.heap.c_allocator;
defer if (builtin.mode == .Debug) {
if (gpa_instance.detectLeaks()) std.posix.exit(1);
};
// defer if (builtin.mode == .Debug) {
// if (gpa_instance.detectLeaks()) std.posix.exit(1);
// };
// arena for main-specific allocations
var main_arena_instance = std.heap.ArenaAllocator.init(gpa);

View File

@@ -28,7 +28,7 @@ run_mode: Config.RunMode = .serve,
head: std.atomic.Value(usize) = .init(0),
tail: std.atomic.Value(usize) = .init(0),
dropped: std.atomic.Value(usize) = .init(0),
dropped: std.atomic.Value(u32) = .init(0),
buffer: [BUFFER_SIZE]telemetry.Event = undefined,
pub fn init(self: *LightPanda, app: *App, iid: ?[36]u8, run_mode: Config.RunMode) !void {

View File

@@ -103,16 +103,15 @@ pub const Event = union(enum) {
run: void,
navigate: Navigate,
buffer_overflow: BufferOverflow,
flag: []const u8, // used for testing
const Navigate = struct {
tls: bool,
proxy: bool,
driver: []const u8 = "cdp",
driver: enum { cdp } = .cdp,
};
const BufferOverflow = struct {
dropped: usize,
dropped: u32,
};
};
@@ -166,13 +165,13 @@ test "telemetry: sends event to provider" {
telemetry.disabled = false;
const mock = telemetry.provider;
telemetry.record(.{ .flag = "1" });
telemetry.record(.{ .flag = "2" });
telemetry.record(.{ .flag = "3" });
telemetry.record(.{ .buffer_overflow = .{ .dropped = 1 } });
telemetry.record(.{ .buffer_overflow = .{ .dropped = 2 } });
telemetry.record(.{ .buffer_overflow = .{ .dropped = 3 } });
try testing.expectEqual(3, mock.events.items.len);
for (mock.events.items, 0..) |event, i| {
try testing.expectEqual(i + 1, std.fmt.parseInt(usize, event.flag, 10));
try testing.expectEqual(i + 1, event.buffer_overflow.dropped);
}
}