mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-15 15:58:57 +00:00
Merge pull request #1245 from lightpanda-io/nikneym/performance-api-changes
Performance API changes
This commit is contained in:
@@ -48,8 +48,81 @@ pub fn mark(self: *Performance, name: []const u8, _options: ?Mark.Options, page:
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn measure(self: *Performance, name: []const u8, _options: ?Measure.Options, page: *Page) !*Measure {
|
const MeasureOptionsOrStartMark = union(enum) {
|
||||||
const m = try Measure.init(name, _options, page);
|
measure_options: Measure.Options,
|
||||||
|
start_mark: []const u8,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn measure(
|
||||||
|
self: *Performance,
|
||||||
|
name: []const u8,
|
||||||
|
maybe_options_or_start: ?MeasureOptionsOrStartMark,
|
||||||
|
maybe_end_mark: ?[]const u8,
|
||||||
|
page: *Page,
|
||||||
|
) !*Measure {
|
||||||
|
if (maybe_options_or_start) |options_or_start| switch (options_or_start) {
|
||||||
|
.measure_options => |options| {
|
||||||
|
// Get start timestamp.
|
||||||
|
const start_timestamp = blk: {
|
||||||
|
if (options.start) |timestamp_or_mark| {
|
||||||
|
break :blk switch (timestamp_or_mark) {
|
||||||
|
.timestamp => |timestamp| timestamp,
|
||||||
|
.mark => |mark_name| try self.getMarkTime(mark_name),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
break :blk 0.0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get end timestamp.
|
||||||
|
const end_timestamp = blk: {
|
||||||
|
if (options.end) |timestamp_or_mark| {
|
||||||
|
break :blk switch (timestamp_or_mark) {
|
||||||
|
.timestamp => |timestamp| timestamp,
|
||||||
|
.mark => |mark_name| try self.getMarkTime(mark_name),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
break :blk self.now();
|
||||||
|
};
|
||||||
|
|
||||||
|
const m = try Measure.init(
|
||||||
|
name,
|
||||||
|
options.detail,
|
||||||
|
start_timestamp,
|
||||||
|
end_timestamp,
|
||||||
|
options.duration,
|
||||||
|
page,
|
||||||
|
);
|
||||||
|
try self._entries.append(page.arena, m._proto);
|
||||||
|
return m;
|
||||||
|
},
|
||||||
|
.start_mark => |start_mark| {
|
||||||
|
// Get start timestamp.
|
||||||
|
const start_timestamp = try self.getMarkTime(start_mark);
|
||||||
|
// Get end timestamp.
|
||||||
|
const end_timestamp = blk: {
|
||||||
|
if (maybe_end_mark) |mark_name| {
|
||||||
|
break :blk try self.getMarkTime(mark_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
break :blk self.now();
|
||||||
|
};
|
||||||
|
|
||||||
|
const m = try Measure.init(
|
||||||
|
name,
|
||||||
|
null,
|
||||||
|
start_timestamp,
|
||||||
|
end_timestamp,
|
||||||
|
null,
|
||||||
|
page,
|
||||||
|
);
|
||||||
|
try self._entries.append(page.arena, m._proto);
|
||||||
|
return m;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const m = try Measure.init(name, null, 0.0, self.now(), null, page);
|
||||||
try self._entries.append(page.arena, m._proto);
|
try self._entries.append(page.arena, m._proto);
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
@@ -121,6 +194,13 @@ fn getMarkTime(self: *const Performance, mark_name: []const u8) !f64 {
|
|||||||
return entry._start_time;
|
return entry._start_time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recognized mark names by browsers. `navigationStart` is an equivalent
|
||||||
|
// to 0. Others are dependant to request arrival, end of request etc.
|
||||||
|
if (std.mem.eql(u8, "navigationStart", mark_name)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return error.SyntaxError; // Mark not found
|
return error.SyntaxError; // Mark not found
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,39 +339,37 @@ pub const Measure = struct {
|
|||||||
|
|
||||||
const Options = struct {
|
const Options = struct {
|
||||||
detail: ?js.Object = null,
|
detail: ?js.Object = null,
|
||||||
start: ?[]const u8 = null,
|
start: ?TimestampOrMark,
|
||||||
end: ?[]const u8 = null,
|
end: ?TimestampOrMark,
|
||||||
duration: ?f64 = null,
|
duration: ?f64 = null,
|
||||||
|
|
||||||
|
const TimestampOrMark = union(enum) {
|
||||||
|
timestamp: f64,
|
||||||
|
mark: []const u8,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn init(name: []const u8, _opts: ?Options, page: *Page) !*Measure {
|
pub fn init(
|
||||||
const opts = _opts orelse Options{};
|
name: []const u8,
|
||||||
const perf = &page.window._performance;
|
maybe_detail: ?js.Object,
|
||||||
|
start_timestamp: f64,
|
||||||
const start_time = if (opts.start) |start_mark|
|
end_timestamp: f64,
|
||||||
try perf.getMarkTime(start_mark)
|
maybe_duration: ?f64,
|
||||||
else
|
page: *Page,
|
||||||
0.0;
|
) !*Measure {
|
||||||
|
const duration = maybe_duration orelse (end_timestamp - start_timestamp);
|
||||||
const end_time = if (opts.end) |end_mark|
|
|
||||||
try perf.getMarkTime(end_mark)
|
|
||||||
else
|
|
||||||
perf.now();
|
|
||||||
|
|
||||||
const duration = opts.duration orelse (end_time - start_time);
|
|
||||||
|
|
||||||
if (duration < 0.0) {
|
if (duration < 0.0) {
|
||||||
return error.TypeError;
|
return error.TypeError;
|
||||||
}
|
}
|
||||||
|
|
||||||
const detail = if (opts.detail) |d| try d.persist() else null;
|
const detail = if (maybe_detail) |d| try d.persist() else null;
|
||||||
const m = try page._factory.create(Measure{
|
const m = try page._factory.create(Measure{
|
||||||
._proto = undefined,
|
._proto = undefined,
|
||||||
._detail = detail,
|
._detail = detail,
|
||||||
});
|
});
|
||||||
|
|
||||||
const entry = try page._factory.create(Entry{
|
const entry = try page._factory.create(Entry{
|
||||||
._start_time = start_time,
|
._start_time = start_timestamp,
|
||||||
._duration = duration,
|
._duration = duration,
|
||||||
._name = try page.dupeString(name),
|
._name = try page.dupeString(name),
|
||||||
._type = .{ .measure = m },
|
._type = .{ .measure = m },
|
||||||
|
|||||||
Reference in New Issue
Block a user