Timing class
Middleware that adds Server-Timing headers for performance monitoring.
The Server-Timing header communicates performance metrics to the browser's developer tools, useful for debugging and monitoring.
Example
final app = Chase();
app.use(Timing());
app.get('/users').handle((ctx) async {
// Measure database query
startTime(ctx, 'db');
final users = await db.getUsers();
endTime(ctx, 'db');
// Add custom metric
setMetric(ctx, 'cache', desc: 'Cache status', value: 'hit');
return users;
});
Response Header
Server-Timing: total;dur=123.45;desc="Total Response Time", db;dur=45.2
Browser DevTools
The metrics appear in the Network tab under "Timing" for each request.
- Implemented types
Constructors
Properties
- autoEnd → bool
-
Whether to automatically end unfinished timers.
final
- crossOrigin → String?
-
Cross-origin setting for Timing-Allow-Origin header.
final
- enabled → bool Function(Context ctx)?
-
Whether timing is enabled.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- total → bool
-
Whether to include total response time.
final
- totalDescription → String
-
Description for the total metric.
final
Methods
-
handle(
Context ctx, NextFunction next) → FutureOr< void> -
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited