Replace the time crate with std::time in components/compositing (#30613)

* Replace the time crate with std::time in components/compositing

Signed-off-by: Reid Swan <reidswan@outlook.com>

* Remove elapsed_since_epoch function

---------

Signed-off-by: Reid Swan <reidswan@outlook.com>
This commit is contained in:
Reid Swan 2023-10-26 16:14:43 +02:00 committed by GitHub
parent 26a3dffd95
commit e4fc4fa3f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 8 deletions

View file

@ -8,6 +8,7 @@ use std::fs::{create_dir_all, File};
use std::io::Write; use std::io::Write;
use std::num::NonZeroU32; use std::num::NonZeroU32;
use std::rc::Rc; use std::rc::Rc;
use std::time::{SystemTime, UNIX_EPOCH};
use canvas::canvas_paint_thread::ImageUpdate; use canvas::canvas_paint_thread::ImageUpdate;
use compositing_traits::{ use compositing_traits::{
@ -42,7 +43,6 @@ use script_traits::{
}; };
use servo_geometry::{DeviceIndependentPixel, FramebufferUintLength}; use servo_geometry::{DeviceIndependentPixel, FramebufferUintLength};
use style_traits::{CSSPixel, DevicePixel, PinchZoomFactor}; use style_traits::{CSSPixel, DevicePixel, PinchZoomFactor};
use time::{now, precise_time_ns, precise_time_s};
use webrender; use webrender;
use webrender::{CaptureBits, RenderApi, Transaction}; use webrender::{CaptureBits, RenderApi, Transaction};
use webrender_api::units::{ use webrender_api::units::{
@ -1753,7 +1753,10 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
// we get the current time, inform the layout thread about it and remove the // we get the current time, inform the layout thread about it and remove the
// pending metric from the list. // pending metric from the list.
if !self.pending_paint_metrics.is_empty() { if !self.pending_paint_metrics.is_empty() {
let paint_time = precise_time_ns(); let paint_time = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
.as_nanos() as u64;
let mut to_remove = Vec::new(); let mut to_remove = Vec::new();
// For each pending paint metrics pipeline id // For each pending paint metrics pipeline id
for (id, pending_epoch) in &self.pending_paint_metrics { for (id, pending_epoch) in &self.pending_paint_metrics {
@ -1974,8 +1977,12 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
return false; return false;
} }
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
.as_secs() as f64;
// If a pinch-zoom happened recently, ask for tiles at the new resolution // If a pinch-zoom happened recently, ask for tiles at the new resolution
if self.zoom_action && precise_time_s() - self.zoom_time > 0.3 { if self.zoom_action && now - self.zoom_time > 0.3 {
self.zoom_action = false; self.zoom_action = false;
} }
@ -2055,7 +2062,11 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
} }
pub fn capture_webrender(&mut self) { pub fn capture_webrender(&mut self) {
let capture_id = now().to_timespec().sec.to_string(); let capture_id = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
.as_secs()
.to_string();
let available_path = [env::current_dir(), Ok(env::temp_dir())] let available_path = [env::current_dir(), Ok(env::temp_dir())]
.iter() .iter()
.filter_map(|val| { .filter_map(|val| {

View file

@ -2,11 +2,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::time::{SystemTime, UNIX_EPOCH};
use ipc_channel::ipc::IpcSender; use ipc_channel::ipc::IpcSender;
use log::warn; use log::warn;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use servo_config::opts; use servo_config::opts;
use time::precise_time_ns;
#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] #[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
pub struct TimerMetadata { pub struct TimerMetadata {
@ -138,16 +139,28 @@ where
if opts::get().debug.signpost { if opts::get().debug.signpost {
signpost::start(category as u32, &[0, 0, 0, (category as usize) >> 4]); signpost::start(category as u32, &[0, 0, 0, (category as usize) >> 4]);
} }
let start_time = precise_time_ns(); let start_time = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
.as_nanos();
let val = callback(); let val = callback();
let end_time = precise_time_ns(); let end_time = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap_or_default()
.as_nanos();
if opts::get().debug.signpost { if opts::get().debug.signpost {
signpost::end(category as u32, &[0, 0, 0, (category as usize) >> 4]); signpost::end(category as u32, &[0, 0, 0, (category as usize) >> 4]);
} }
send_profile_data(category, meta, &profiler_chan, start_time, end_time); send_profile_data(
category,
meta,
&profiler_chan,
start_time as u64,
end_time as u64,
);
val val
} }