Skip to content

Commit 08c11ac

Browse files
Add performance.enable
Signed-off-by: Francis Bouvier <[email protected]>
1 parent cecc03e commit 08c11ac

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/cdp/cdp.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const runtime = @import("runtime.zig").runtime;
1111
const network = @import("network.zig").network;
1212
const emulation = @import("emulation.zig").emulation;
1313
const fetch = @import("fetch.zig").fetch;
14+
const performance = @import("performance.zig").performance;
1415

1516
pub const Error = error{
1617
UnknonwDomain,
@@ -37,6 +38,7 @@ const Domains = enum {
3738
Network,
3839
Emulation,
3940
Fetch,
41+
Performance,
4042
};
4143

4244
// The caller is responsible for calling `free` on the returned slice.
@@ -87,6 +89,7 @@ pub fn do(
8789
.Network => network(alloc, id, iter.next().?, &scanner, ctx),
8890
.Emulation => emulation(alloc, id, iter.next().?, &scanner, ctx),
8991
.Fetch => fetch(alloc, id, iter.next().?, &scanner, ctx),
92+
.Performance => performance(alloc, id, iter.next().?, &scanner, ctx),
9093
};
9194
}
9295

src/cdp/performance.zig

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const std = @import("std");
2+
3+
const server = @import("../server.zig");
4+
const Ctx = server.Cmd;
5+
const cdp = @import("cdp.zig");
6+
const result = cdp.result;
7+
const getMsg = cdp.getMsg;
8+
9+
const PerformanceMethods = enum {
10+
enable,
11+
};
12+
13+
pub fn performance(
14+
alloc: std.mem.Allocator,
15+
id: ?u16,
16+
action: []const u8,
17+
scanner: *std.json.Scanner,
18+
ctx: *Ctx,
19+
) ![]const u8 {
20+
const method = std.meta.stringToEnum(PerformanceMethods, action) orelse
21+
return error.UnknownMethod;
22+
23+
return switch (method) {
24+
.enable => performanceEnable(alloc, id, scanner, ctx),
25+
};
26+
}
27+
28+
fn performanceEnable(
29+
alloc: std.mem.Allocator,
30+
id: ?u16,
31+
scanner: *std.json.Scanner,
32+
_: *Ctx,
33+
) ![]const u8 {
34+
const msg = try getMsg(alloc, void, scanner);
35+
36+
return result(alloc, id orelse msg.id.?, null, null, msg.sessionID);
37+
}

0 commit comments

Comments
 (0)