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

View file

@ -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,

View file

@ -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,

View file

@ -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)
}