mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Send high resolution millisecond timestamps in timeline markers #5665
This commit is contained in:
parent
bdcf606f48
commit
491851610e
3 changed files with 54 additions and 20 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
/// General actor system infrastructure.
|
/// General actor system infrastructure.
|
||||||
|
|
||||||
|
use rustc_serialize::json;
|
||||||
use std::any::{Any, TypeId};
|
use std::any::{Any, TypeId};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
|
@ -11,7 +12,7 @@ use std::mem::{replace, transmute};
|
||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
use std::raw::TraitObject;
|
use std::raw::TraitObject;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use rustc_serialize::json;
|
use time::PreciseTime;
|
||||||
|
|
||||||
/// A common trait for all devtools actors that encompasses an immutable name
|
/// A common trait for all devtools actors that encompasses an immutable name
|
||||||
/// and the ability to process messages that are directed to particular actors.
|
/// and the ability to process messages that are directed to particular actors.
|
||||||
|
@ -82,6 +83,7 @@ pub struct ActorRegistry {
|
||||||
script_actors: RefCell<HashMap<String, String>>,
|
script_actors: RefCell<HashMap<String, String>>,
|
||||||
shareable: Option<Arc<Mutex<ActorRegistry>>>,
|
shareable: Option<Arc<Mutex<ActorRegistry>>>,
|
||||||
next: Cell<u32>,
|
next: Cell<u32>,
|
||||||
|
start_stamp: PreciseTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ActorRegistry {
|
impl ActorRegistry {
|
||||||
|
@ -94,6 +96,7 @@ impl ActorRegistry {
|
||||||
script_actors: RefCell::new(HashMap::new()),
|
script_actors: RefCell::new(HashMap::new()),
|
||||||
shareable: None,
|
shareable: None,
|
||||||
next: Cell::new(0),
|
next: Cell::new(0),
|
||||||
|
start_stamp: PreciseTime::now(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +118,11 @@ impl ActorRegistry {
|
||||||
self.shareable.as_ref().unwrap().clone()
|
self.shareable.as_ref().unwrap().clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get start stamp when registry was started
|
||||||
|
pub fn get_start_stamp(&self) -> PreciseTime {
|
||||||
|
self.start_stamp.clone()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn register_script_actor(&self, script_id: String, actor: String) {
|
pub fn register_script_actor(&self, script_id: String, actor: String) {
|
||||||
println!("registering {} ({})", actor, script_id);
|
println!("registering {} ({})", actor, script_id);
|
||||||
let mut script_actors = self.script_actors.borrow_mut();
|
let mut script_actors = self.script_actors.borrow_mut();
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use core::iter::FromIterator;
|
use core::iter::FromIterator;
|
||||||
use msg::constellation_msg::PipelineId;
|
use msg::constellation_msg::PipelineId;
|
||||||
use rustc_serialize::json;
|
use rustc_serialize::{json, Encoder, Encodable};
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::{HashMap, VecDeque};
|
use std::collections::{HashMap, VecDeque};
|
||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
|
@ -12,7 +12,7 @@ use std::old_io::timer::sleep;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::time::duration::Duration;
|
use std::time::duration::Duration;
|
||||||
use std::sync::mpsc::{channel, Sender, Receiver};
|
use std::sync::mpsc::{channel, Sender, Receiver};
|
||||||
use time::precise_time_ns;
|
use time::PreciseTime;
|
||||||
|
|
||||||
use actor::{Actor, ActorRegistry};
|
use actor::{Actor, ActorRegistry};
|
||||||
use actors::memory::{MemoryActor, TimelineMemoryReply};
|
use actors::memory::{MemoryActor, TimelineMemoryReply};
|
||||||
|
@ -40,6 +40,7 @@ struct Emitter {
|
||||||
stream: TcpStream,
|
stream: TcpStream,
|
||||||
markers: Vec<TimelineMarkerReply>,
|
markers: Vec<TimelineMarkerReply>,
|
||||||
registry: Arc<Mutex<ActorRegistry>>,
|
registry: Arc<Mutex<ActorRegistry>>,
|
||||||
|
start_stamp: PreciseTime,
|
||||||
|
|
||||||
framerate_actor: Option<String>,
|
framerate_actor: Option<String>,
|
||||||
memory_actor: Option<String>,
|
memory_actor: Option<String>,
|
||||||
|
@ -54,20 +55,20 @@ struct IsRecordingReply {
|
||||||
#[derive(RustcEncodable)]
|
#[derive(RustcEncodable)]
|
||||||
struct StartReply {
|
struct StartReply {
|
||||||
from: String,
|
from: String,
|
||||||
value: u64
|
value: HighResolutionStamp,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(RustcEncodable)]
|
#[derive(RustcEncodable)]
|
||||||
struct StopReply {
|
struct StopReply {
|
||||||
from: String,
|
from: String,
|
||||||
value: u64
|
value: HighResolutionStamp,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(RustcEncodable)]
|
#[derive(RustcEncodable)]
|
||||||
struct TimelineMarkerReply {
|
struct TimelineMarkerReply {
|
||||||
name: String,
|
name: String,
|
||||||
start: u64,
|
start: HighResolutionStamp,
|
||||||
end: u64,
|
end: HighResolutionStamp,
|
||||||
stack: Option<Vec<()>>,
|
stack: Option<Vec<()>>,
|
||||||
endStack: Option<Vec<()>>,
|
endStack: Option<Vec<()>>,
|
||||||
}
|
}
|
||||||
|
@ -77,14 +78,14 @@ struct MarkersEmitterReply {
|
||||||
__type__: String,
|
__type__: String,
|
||||||
markers: Vec<TimelineMarkerReply>,
|
markers: Vec<TimelineMarkerReply>,
|
||||||
from: String,
|
from: String,
|
||||||
endTime: u64,
|
endTime: HighResolutionStamp,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(RustcEncodable)]
|
#[derive(RustcEncodable)]
|
||||||
struct MemoryEmitterReply {
|
struct MemoryEmitterReply {
|
||||||
__type__: String,
|
__type__: String,
|
||||||
from: String,
|
from: String,
|
||||||
delta: u64,
|
delta: HighResolutionStamp,
|
||||||
measurement: TimelineMemoryReply,
|
measurement: TimelineMemoryReply,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,10 +93,30 @@ struct MemoryEmitterReply {
|
||||||
struct FramerateEmitterReply {
|
struct FramerateEmitterReply {
|
||||||
__type__: String,
|
__type__: String,
|
||||||
from: String,
|
from: String,
|
||||||
delta: u64,
|
delta: HighResolutionStamp,
|
||||||
timestamps: Vec<u64>,
|
timestamps: Vec<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// HighResolutionStamp is struct that contains duration in milliseconds
|
||||||
|
/// with accuracy to microsecond that shows how much time has passed since
|
||||||
|
/// actor registry inited
|
||||||
|
/// analog https://w3c.github.io/hr-time/#sec-DOMHighResTimeStamp
|
||||||
|
struct HighResolutionStamp(f64);
|
||||||
|
|
||||||
|
impl HighResolutionStamp {
|
||||||
|
fn new(start_stamp: PreciseTime, time: PreciseTime) -> HighResolutionStamp {
|
||||||
|
let duration = start_stamp.to(time).num_microseconds()
|
||||||
|
.expect("Too big duration in microseconds");
|
||||||
|
HighResolutionStamp(duration as f64 / 1000 as f64)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Encodable for HighResolutionStamp {
|
||||||
|
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||||
|
self.0.encode(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static DEFAULT_TIMELINE_DATA_PULL_TIMEOUT: usize = 200; //ms
|
static DEFAULT_TIMELINE_DATA_PULL_TIMEOUT: usize = 200; //ms
|
||||||
|
|
||||||
impl TimelineActor {
|
impl TimelineActor {
|
||||||
|
@ -233,6 +254,7 @@ impl Actor for TimelineActor {
|
||||||
}
|
}
|
||||||
|
|
||||||
let emitter = Emitter::new(self.name(), registry.get_shareable(),
|
let emitter = Emitter::new(self.name(), registry.get_shareable(),
|
||||||
|
registry.get_start_stamp(),
|
||||||
stream.try_clone().unwrap(),
|
stream.try_clone().unwrap(),
|
||||||
self.memory_actor.borrow().clone(),
|
self.memory_actor.borrow().clone(),
|
||||||
self.framerate_actor.borrow().clone());
|
self.framerate_actor.borrow().clone());
|
||||||
|
@ -241,7 +263,8 @@ impl Actor for TimelineActor {
|
||||||
|
|
||||||
let msg = StartReply {
|
let msg = StartReply {
|
||||||
from: self.name(),
|
from: self.name(),
|
||||||
value: precise_time_ns(),
|
value: HighResolutionStamp::new(registry.get_start_stamp(),
|
||||||
|
PreciseTime::now()),
|
||||||
};
|
};
|
||||||
stream.write_json_packet(&msg);
|
stream.write_json_packet(&msg);
|
||||||
true
|
true
|
||||||
|
@ -250,7 +273,8 @@ impl Actor for TimelineActor {
|
||||||
"stop" => {
|
"stop" => {
|
||||||
let msg = StopReply {
|
let msg = StopReply {
|
||||||
from: self.name(),
|
from: self.name(),
|
||||||
value: precise_time_ns()
|
value: HighResolutionStamp::new(registry.get_start_stamp(),
|
||||||
|
PreciseTime::now()),
|
||||||
};
|
};
|
||||||
|
|
||||||
stream.write_json_packet(&msg);
|
stream.write_json_packet(&msg);
|
||||||
|
@ -289,6 +313,7 @@ impl Actor for TimelineActor {
|
||||||
impl Emitter {
|
impl Emitter {
|
||||||
pub fn new(name: String,
|
pub fn new(name: String,
|
||||||
registry: Arc<Mutex<ActorRegistry>>,
|
registry: Arc<Mutex<ActorRegistry>>,
|
||||||
|
start_stamp: PreciseTime,
|
||||||
stream: TcpStream,
|
stream: TcpStream,
|
||||||
memory_actor_name: Option<String>,
|
memory_actor_name: Option<String>,
|
||||||
framerate_actor_name: Option<String>) -> Emitter {
|
framerate_actor_name: Option<String>) -> Emitter {
|
||||||
|
@ -298,6 +323,7 @@ impl Emitter {
|
||||||
stream: stream,
|
stream: stream,
|
||||||
markers: Vec::new(),
|
markers: Vec::new(),
|
||||||
registry: registry,
|
registry: registry,
|
||||||
|
start_stamp: start_stamp,
|
||||||
|
|
||||||
framerate_actor: framerate_actor_name,
|
framerate_actor: framerate_actor_name,
|
||||||
memory_actor: memory_actor_name,
|
memory_actor: memory_actor_name,
|
||||||
|
@ -307,20 +333,20 @@ impl Emitter {
|
||||||
fn add_marker(&mut self, start_payload: TimelineMarker, end_payload: TimelineMarker) -> () {
|
fn add_marker(&mut self, start_payload: TimelineMarker, end_payload: TimelineMarker) -> () {
|
||||||
self.markers.push(TimelineMarkerReply {
|
self.markers.push(TimelineMarkerReply {
|
||||||
name: start_payload.name,
|
name: start_payload.name,
|
||||||
start: start_payload.time,
|
start: HighResolutionStamp::new(self.start_stamp, start_payload.time),
|
||||||
end: end_payload.time,
|
end: HighResolutionStamp::new(self.start_stamp, end_payload.time),
|
||||||
stack: start_payload.stack,
|
stack: start_payload.stack,
|
||||||
endStack: end_payload.stack,
|
endStack: end_payload.stack,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send(&mut self) -> () {
|
fn send(&mut self) -> () {
|
||||||
let end_time = precise_time_ns();
|
let end_time = PreciseTime::now();
|
||||||
let reply = MarkersEmitterReply {
|
let reply = MarkersEmitterReply {
|
||||||
__type__: "markers".to_string(),
|
__type__: "markers".to_string(),
|
||||||
markers: Vec::from_iter(self.markers.drain()),
|
markers: Vec::from_iter(self.markers.drain()),
|
||||||
from: self.from.clone(),
|
from: self.from.clone(),
|
||||||
endTime: end_time,
|
endTime: HighResolutionStamp::new(self.start_stamp, end_time),
|
||||||
};
|
};
|
||||||
self.stream.write_json_packet(&reply);
|
self.stream.write_json_packet(&reply);
|
||||||
|
|
||||||
|
@ -331,7 +357,7 @@ impl Emitter {
|
||||||
let framerateReply = FramerateEmitterReply {
|
let framerateReply = FramerateEmitterReply {
|
||||||
__type__: "framerate".to_string(),
|
__type__: "framerate".to_string(),
|
||||||
from: framerate_actor.name(),
|
from: framerate_actor.name(),
|
||||||
delta: end_time,
|
delta: HighResolutionStamp::new(self.start_stamp, end_time),
|
||||||
timestamps: framerate_actor.take_pending_ticks(),
|
timestamps: framerate_actor.take_pending_ticks(),
|
||||||
};
|
};
|
||||||
self.stream.write_json_packet(&framerateReply);
|
self.stream.write_json_packet(&framerateReply);
|
||||||
|
@ -343,7 +369,7 @@ impl Emitter {
|
||||||
let memoryReply = MemoryEmitterReply {
|
let memoryReply = MemoryEmitterReply {
|
||||||
__type__: "memory".to_string(),
|
__type__: "memory".to_string(),
|
||||||
from: memory_actor.name(),
|
from: memory_actor.name(),
|
||||||
delta: end_time,
|
delta: HighResolutionStamp::new(self.start_stamp, end_time),
|
||||||
measurement: memory_actor.measure(),
|
measurement: memory_actor.measure(),
|
||||||
};
|
};
|
||||||
self.stream.write_json_packet(&memoryReply);
|
self.stream.write_json_packet(&memoryReply);
|
||||||
|
|
|
@ -96,7 +96,7 @@ pub enum TracingMetadata {
|
||||||
pub struct TimelineMarker {
|
pub struct TimelineMarker {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub metadata: TracingMetadata,
|
pub metadata: TracingMetadata,
|
||||||
pub time: u64,
|
pub time: time::PreciseTime,
|
||||||
pub stack: Option<Vec<()>>,
|
pub stack: Option<Vec<()>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ impl TimelineMarker {
|
||||||
TimelineMarker {
|
TimelineMarker {
|
||||||
name: name,
|
name: name,
|
||||||
metadata: metadata,
|
metadata: metadata,
|
||||||
time: time::precise_time_ns(),
|
time: time::PreciseTime::now(),
|
||||||
stack: None,
|
stack: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue