mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Replace time with std::time in components/devtools (#30927)
Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com>
This commit is contained in:
parent
d0998a771a
commit
65cbc95d38
7 changed files with 41 additions and 22 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1351,6 +1351,7 @@ dependencies = [
|
|||
name = "devtools"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"crossbeam-channel",
|
||||
"devtools_traits",
|
||||
"embedder_traits",
|
||||
|
@ -1364,7 +1365,6 @@ dependencies = [
|
|||
"servo_config",
|
||||
"servo_rand",
|
||||
"servo_url",
|
||||
"time 0.1.45",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ name = "devtools"
|
|||
path = "lib.rs"
|
||||
|
||||
[dependencies]
|
||||
chrono = "0.4"
|
||||
crossbeam-channel = { workspace = true }
|
||||
devtools_traits = { workspace = true }
|
||||
embedder_traits = { workspace = true }
|
||||
|
@ -24,5 +25,4 @@ serde_json = { workspace = true }
|
|||
servo_config = { path = "../config" }
|
||||
servo_rand = { path = "../rand" }
|
||||
servo_url = { path = "../url" }
|
||||
time = { workspace = true }
|
||||
uuid = { workspace = true }
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use std::net::TcpStream;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use devtools_traits::EvaluateJSReply::{
|
||||
ActorValue, BooleanValue, NullValue, NumberValue, StringValue, VoidValue,
|
||||
|
@ -23,7 +24,6 @@ use log::debug;
|
|||
use msg::constellation_msg::TEST_PIPELINE_ID;
|
||||
use serde::Serialize;
|
||||
use serde_json::{self, Map, Number, Value};
|
||||
use time::precise_time_ns;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
|
||||
|
@ -295,7 +295,10 @@ impl ConsoleActor {
|
|||
filename: console_message.filename.clone(),
|
||||
lineNumber: console_message.lineNumber as u32,
|
||||
functionName: "".to_string(), //TODO
|
||||
timeStamp: precise_time_ns(),
|
||||
timeStamp: SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_nanos() as u64,
|
||||
private: false,
|
||||
arguments: vec![console_message.message.clone()],
|
||||
}));
|
||||
|
@ -305,7 +308,10 @@ impl ConsoleActor {
|
|||
type_: "consoleAPICall".to_owned(),
|
||||
message: ConsoleMsg {
|
||||
level: level,
|
||||
timeStamp: precise_time_ns(),
|
||||
timeStamp: SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_nanos() as u64,
|
||||
arguments: vec![console_message.message],
|
||||
filename: console_message.filename,
|
||||
lineNumber: console_message.lineNumber,
|
||||
|
|
|
@ -7,13 +7,14 @@
|
|||
//! Handles interaction with the remote web console on network events (HTTP requests, responses) in Servo.
|
||||
|
||||
use std::net::TcpStream;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use chrono::{Local, LocalResult, TimeZone};
|
||||
use devtools_traits::{HttpRequest as DevtoolsHttpRequest, HttpResponse as DevtoolsHttpResponse};
|
||||
use headers::{ContentType, Cookie, HeaderMapExt};
|
||||
use http::{header, HeaderMap, Method, StatusCode};
|
||||
use serde::Serialize;
|
||||
use serde_json::{Map, Value};
|
||||
use time::Tm;
|
||||
|
||||
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
|
||||
use crate::protocol::JsonPacketStream;
|
||||
|
@ -24,7 +25,7 @@ struct HttpRequest {
|
|||
method: Method,
|
||||
headers: HeaderMap,
|
||||
body: Option<Vec<u8>>,
|
||||
startedDateTime: Tm,
|
||||
startedDateTime: SystemTime,
|
||||
timeStamp: i64,
|
||||
connect_time: u64,
|
||||
send_time: u64,
|
||||
|
@ -328,8 +329,11 @@ impl NetworkEventActor {
|
|||
method: Method::GET,
|
||||
headers: HeaderMap::new(),
|
||||
body: None,
|
||||
startedDateTime: time::now(),
|
||||
timeStamp: time::get_time().sec,
|
||||
startedDateTime: SystemTime::now(),
|
||||
timeStamp: SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_secs() as i64,
|
||||
send_time: 0,
|
||||
connect_time: 0,
|
||||
},
|
||||
|
@ -366,11 +370,24 @@ impl NetworkEventActor {
|
|||
|
||||
pub fn event_actor(&self) -> EventActor {
|
||||
// TODO: Send the correct values for startedDateTime, isXHR, private
|
||||
|
||||
let started_datetime_rfc3339 = match Local.timestamp_millis_opt(
|
||||
self.request
|
||||
.startedDateTime
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_millis() as i64,
|
||||
) {
|
||||
LocalResult::None => "".to_owned(),
|
||||
LocalResult::Single(dateTime) => format!("{}", dateTime.to_rfc3339()),
|
||||
LocalResult::Ambiguous(dateTime, _) => format!("{}", dateTime.to_rfc3339()),
|
||||
};
|
||||
|
||||
EventActor {
|
||||
actor: self.name(),
|
||||
url: self.request.url.clone(),
|
||||
method: format!("{}", self.request.method),
|
||||
startedDateTime: format!("{}", self.request.startedDateTime.rfc3339()),
|
||||
startedDateTime: started_datetime_rfc3339,
|
||||
timeStamp: self.request.timeStamp,
|
||||
isXHR: self.is_xhr,
|
||||
private: false,
|
||||
|
|
|
@ -106,10 +106,7 @@ pub struct HighResolutionStamp(f64);
|
|||
|
||||
impl HighResolutionStamp {
|
||||
pub fn new(start_stamp: PreciseTime, time: PreciseTime) -> HighResolutionStamp {
|
||||
let duration = start_stamp
|
||||
.to(time)
|
||||
.num_microseconds()
|
||||
.expect("Too big duration in microseconds");
|
||||
let duration = start_stamp.to(time).as_micros();
|
||||
HighResolutionStamp(duration as f64 / 1000 as f64)
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use std::iter::FromIterator;
|
|||
use std::mem;
|
||||
use std::ops::Deref;
|
||||
use std::sync::{Arc as StdArc, Condvar, Mutex, RwLock};
|
||||
use std::time::{Duration, SystemTime};
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
|
||||
use async_recursion::async_recursion;
|
||||
use crossbeam_channel::Sender;
|
||||
|
@ -52,7 +52,6 @@ use net_traits::{
|
|||
};
|
||||
use servo_arc::Arc;
|
||||
use servo_url::{ImmutableOrigin, ServoUrl};
|
||||
use time::{self, Tm};
|
||||
use tokio::runtime::Runtime;
|
||||
use tokio::sync::mpsc::{
|
||||
channel, unbounded_channel, Receiver as TokioReceiver, Sender as TokioSender,
|
||||
|
@ -358,7 +357,7 @@ fn prepare_devtools_request(
|
|||
headers: HeaderMap,
|
||||
body: Option<Vec<u8>>,
|
||||
pipeline_id: PipelineId,
|
||||
now: Tm,
|
||||
now: SystemTime,
|
||||
connect_time: u64,
|
||||
send_time: u64,
|
||||
is_xhr: bool,
|
||||
|
@ -370,7 +369,7 @@ fn prepare_devtools_request(
|
|||
body: body,
|
||||
pipeline_id: pipeline_id,
|
||||
startedDateTime: now,
|
||||
timeStamp: now.to_timespec().sec,
|
||||
timeStamp: now.duration_since(UNIX_EPOCH).unwrap_or_default().as_secs() as i64,
|
||||
connect_time: connect_time,
|
||||
send_time: send_time,
|
||||
is_xhr: is_xhr,
|
||||
|
@ -675,7 +674,7 @@ async fn obtain_response(
|
|||
headers,
|
||||
Some(devtools_bytes.lock().unwrap().clone()),
|
||||
pipeline_id,
|
||||
time::now(),
|
||||
SystemTime::now(),
|
||||
connect_end - connect_start,
|
||||
send_end - send_start,
|
||||
is_xhr,
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#![deny(unsafe_code)]
|
||||
|
||||
use std::net::TcpStream;
|
||||
use std::time::{Duration, SystemTime};
|
||||
|
||||
use bitflags::bitflags;
|
||||
use http::{HeaderMap, Method};
|
||||
|
@ -20,7 +21,6 @@ use malloc_size_of_derive::MallocSizeOf;
|
|||
use msg::constellation_msg::{BrowsingContextId, PipelineId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use servo_url::ServoUrl;
|
||||
use time::{self, Duration, Tm};
|
||||
use uuid::Uuid;
|
||||
|
||||
// Information would be attached to NewGlobal to be received and show in devtools.
|
||||
|
@ -306,7 +306,7 @@ pub struct HttpRequest {
|
|||
pub headers: HeaderMap,
|
||||
pub body: Option<Vec<u8>>,
|
||||
pub pipeline_id: PipelineId,
|
||||
pub startedDateTime: Tm,
|
||||
pub startedDateTime: SystemTime,
|
||||
pub timeStamp: i64,
|
||||
pub connect_time: u64,
|
||||
pub send_time: u64,
|
||||
|
@ -364,7 +364,7 @@ impl PreciseTime {
|
|||
}
|
||||
|
||||
pub fn to(&self, later: PreciseTime) -> Duration {
|
||||
Duration::nanoseconds((later.0 - self.0) as i64)
|
||||
Duration::from_nanos(later.0 - self.0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue