Replace time with std::time in components/devtools (#30927)

Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com>
This commit is contained in:
Taym Haddadi 2024-01-03 17:52:04 +01:00 committed by GitHub
parent d0998a771a
commit 65cbc95d38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 41 additions and 22 deletions

2
Cargo.lock generated
View file

@ -1351,6 +1351,7 @@ dependencies = [
name = "devtools" name = "devtools"
version = "0.0.1" version = "0.0.1"
dependencies = [ dependencies = [
"chrono",
"crossbeam-channel", "crossbeam-channel",
"devtools_traits", "devtools_traits",
"embedder_traits", "embedder_traits",
@ -1364,7 +1365,6 @@ dependencies = [
"servo_config", "servo_config",
"servo_rand", "servo_rand",
"servo_url", "servo_url",
"time 0.1.45",
"uuid", "uuid",
] ]

View file

@ -11,6 +11,7 @@ name = "devtools"
path = "lib.rs" path = "lib.rs"
[dependencies] [dependencies]
chrono = "0.4"
crossbeam-channel = { workspace = true } crossbeam-channel = { workspace = true }
devtools_traits = { workspace = true } devtools_traits = { workspace = true }
embedder_traits = { workspace = true } embedder_traits = { workspace = true }
@ -24,5 +25,4 @@ serde_json = { workspace = true }
servo_config = { path = "../config" } servo_config = { path = "../config" }
servo_rand = { path = "../rand" } servo_rand = { path = "../rand" }
servo_url = { path = "../url" } servo_url = { path = "../url" }
time = { workspace = true }
uuid = { workspace = true } uuid = { workspace = true }

View file

@ -10,6 +10,7 @@
use std::cell::RefCell; use std::cell::RefCell;
use std::collections::HashMap; use std::collections::HashMap;
use std::net::TcpStream; use std::net::TcpStream;
use std::time::{SystemTime, UNIX_EPOCH};
use devtools_traits::EvaluateJSReply::{ use devtools_traits::EvaluateJSReply::{
ActorValue, BooleanValue, NullValue, NumberValue, StringValue, VoidValue, ActorValue, BooleanValue, NullValue, NumberValue, StringValue, VoidValue,
@ -23,7 +24,6 @@ use log::debug;
use msg::constellation_msg::TEST_PIPELINE_ID; use msg::constellation_msg::TEST_PIPELINE_ID;
use serde::Serialize; use serde::Serialize;
use serde_json::{self, Map, Number, Value}; use serde_json::{self, Map, Number, Value};
use time::precise_time_ns;
use uuid::Uuid; use uuid::Uuid;
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry}; use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
@ -295,7 +295,10 @@ impl ConsoleActor {
filename: console_message.filename.clone(), filename: console_message.filename.clone(),
lineNumber: console_message.lineNumber as u32, lineNumber: console_message.lineNumber as u32,
functionName: "".to_string(), //TODO functionName: "".to_string(), //TODO
timeStamp: precise_time_ns(), timeStamp: SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
.as_nanos() as u64,
private: false, private: false,
arguments: vec![console_message.message.clone()], arguments: vec![console_message.message.clone()],
})); }));
@ -305,7 +308,10 @@ impl ConsoleActor {
type_: "consoleAPICall".to_owned(), type_: "consoleAPICall".to_owned(),
message: ConsoleMsg { message: ConsoleMsg {
level: level, 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], arguments: vec![console_message.message],
filename: console_message.filename, filename: console_message.filename,
lineNumber: console_message.lineNumber, lineNumber: console_message.lineNumber,

View file

@ -7,13 +7,14 @@
//! Handles interaction with the remote web console on network events (HTTP requests, responses) in Servo. //! Handles interaction with the remote web console on network events (HTTP requests, responses) in Servo.
use std::net::TcpStream; 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 devtools_traits::{HttpRequest as DevtoolsHttpRequest, HttpResponse as DevtoolsHttpResponse};
use headers::{ContentType, Cookie, HeaderMapExt}; use headers::{ContentType, Cookie, HeaderMapExt};
use http::{header, HeaderMap, Method, StatusCode}; use http::{header, HeaderMap, Method, StatusCode};
use serde::Serialize; use serde::Serialize;
use serde_json::{Map, Value}; use serde_json::{Map, Value};
use time::Tm;
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry}; use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
use crate::protocol::JsonPacketStream; use crate::protocol::JsonPacketStream;
@ -24,7 +25,7 @@ struct HttpRequest {
method: Method, method: Method,
headers: HeaderMap, headers: HeaderMap,
body: Option<Vec<u8>>, body: Option<Vec<u8>>,
startedDateTime: Tm, startedDateTime: SystemTime,
timeStamp: i64, timeStamp: i64,
connect_time: u64, connect_time: u64,
send_time: u64, send_time: u64,
@ -328,8 +329,11 @@ impl NetworkEventActor {
method: Method::GET, method: Method::GET,
headers: HeaderMap::new(), headers: HeaderMap::new(),
body: None, body: None,
startedDateTime: time::now(), startedDateTime: SystemTime::now(),
timeStamp: time::get_time().sec, timeStamp: SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
.as_secs() as i64,
send_time: 0, send_time: 0,
connect_time: 0, connect_time: 0,
}, },
@ -366,11 +370,24 @@ impl NetworkEventActor {
pub fn event_actor(&self) -> EventActor { pub fn event_actor(&self) -> EventActor {
// TODO: Send the correct values for startedDateTime, isXHR, private // 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 { EventActor {
actor: self.name(), actor: self.name(),
url: self.request.url.clone(), url: self.request.url.clone(),
method: format!("{}", self.request.method), method: format!("{}", self.request.method),
startedDateTime: format!("{}", self.request.startedDateTime.rfc3339()), startedDateTime: started_datetime_rfc3339,
timeStamp: self.request.timeStamp, timeStamp: self.request.timeStamp,
isXHR: self.is_xhr, isXHR: self.is_xhr,
private: false, private: false,

View file

@ -106,10 +106,7 @@ pub struct HighResolutionStamp(f64);
impl HighResolutionStamp { impl HighResolutionStamp {
pub fn new(start_stamp: PreciseTime, time: PreciseTime) -> HighResolutionStamp { pub fn new(start_stamp: PreciseTime, time: PreciseTime) -> HighResolutionStamp {
let duration = start_stamp let duration = start_stamp.to(time).as_micros();
.to(time)
.num_microseconds()
.expect("Too big duration in microseconds");
HighResolutionStamp(duration as f64 / 1000 as f64) HighResolutionStamp(duration as f64 / 1000 as f64)
} }

View file

@ -8,7 +8,7 @@ use std::iter::FromIterator;
use std::mem; use std::mem;
use std::ops::Deref; use std::ops::Deref;
use std::sync::{Arc as StdArc, Condvar, Mutex, RwLock}; 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 async_recursion::async_recursion;
use crossbeam_channel::Sender; use crossbeam_channel::Sender;
@ -52,7 +52,6 @@ use net_traits::{
}; };
use servo_arc::Arc; use servo_arc::Arc;
use servo_url::{ImmutableOrigin, ServoUrl}; use servo_url::{ImmutableOrigin, ServoUrl};
use time::{self, Tm};
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
use tokio::sync::mpsc::{ use tokio::sync::mpsc::{
channel, unbounded_channel, Receiver as TokioReceiver, Sender as TokioSender, channel, unbounded_channel, Receiver as TokioReceiver, Sender as TokioSender,
@ -358,7 +357,7 @@ fn prepare_devtools_request(
headers: HeaderMap, headers: HeaderMap,
body: Option<Vec<u8>>, body: Option<Vec<u8>>,
pipeline_id: PipelineId, pipeline_id: PipelineId,
now: Tm, now: SystemTime,
connect_time: u64, connect_time: u64,
send_time: u64, send_time: u64,
is_xhr: bool, is_xhr: bool,
@ -370,7 +369,7 @@ fn prepare_devtools_request(
body: body, body: body,
pipeline_id: pipeline_id, pipeline_id: pipeline_id,
startedDateTime: now, startedDateTime: now,
timeStamp: now.to_timespec().sec, timeStamp: now.duration_since(UNIX_EPOCH).unwrap_or_default().as_secs() as i64,
connect_time: connect_time, connect_time: connect_time,
send_time: send_time, send_time: send_time,
is_xhr: is_xhr, is_xhr: is_xhr,
@ -675,7 +674,7 @@ async fn obtain_response(
headers, headers,
Some(devtools_bytes.lock().unwrap().clone()), Some(devtools_bytes.lock().unwrap().clone()),
pipeline_id, pipeline_id,
time::now(), SystemTime::now(),
connect_end - connect_start, connect_end - connect_start,
send_end - send_start, send_end - send_start,
is_xhr, is_xhr,

View file

@ -12,6 +12,7 @@
#![deny(unsafe_code)] #![deny(unsafe_code)]
use std::net::TcpStream; use std::net::TcpStream;
use std::time::{Duration, SystemTime};
use bitflags::bitflags; use bitflags::bitflags;
use http::{HeaderMap, Method}; use http::{HeaderMap, Method};
@ -20,7 +21,6 @@ use malloc_size_of_derive::MallocSizeOf;
use msg::constellation_msg::{BrowsingContextId, PipelineId}; use msg::constellation_msg::{BrowsingContextId, PipelineId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use servo_url::ServoUrl; use servo_url::ServoUrl;
use time::{self, Duration, Tm};
use uuid::Uuid; use uuid::Uuid;
// Information would be attached to NewGlobal to be received and show in devtools. // Information would be attached to NewGlobal to be received and show in devtools.
@ -306,7 +306,7 @@ pub struct HttpRequest {
pub headers: HeaderMap, pub headers: HeaderMap,
pub body: Option<Vec<u8>>, pub body: Option<Vec<u8>>,
pub pipeline_id: PipelineId, pub pipeline_id: PipelineId,
pub startedDateTime: Tm, pub startedDateTime: SystemTime,
pub timeStamp: i64, pub timeStamp: i64,
pub connect_time: u64, pub connect_time: u64,
pub send_time: u64, pub send_time: u64,
@ -364,7 +364,7 @@ impl PreciseTime {
} }
pub fn to(&self, later: PreciseTime) -> Duration { pub fn to(&self, later: PreciseTime) -> Duration {
Duration::nanoseconds((later.0 - self.0) as i64) Duration::from_nanos(later.0 - self.0)
} }
} }