aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs4
-rw-r--r--crates/shirabe-external-packages/src/symfony/process/process.rs14
-rw-r--r--crates/shirabe-php-shim/src/datetime.rs7
-rw-r--r--crates/shirabe/src/console/application.rs4
-rw-r--r--crates/shirabe/src/dependency_resolver/pool_builder.rs8
-rw-r--r--crates/shirabe/src/dependency_resolver/solver.rs4
-rw-r--r--crates/shirabe/src/io/console_io.rs2
-rw-r--r--crates/shirabe/tests/util/silencer_test.rs3
8 files changed, 24 insertions, 22 deletions
diff --git a/crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs b/crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs
index d9d3fd6..1cd50ac 100644
--- a/crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs
+++ b/crates/shirabe-external-packages/src/symfony/console/helper/progress_bar.rs
@@ -391,7 +391,7 @@ impl ProgressBar {
} else {
0.0
};
- let time_interval = shirabe_php_shim::microtime(true) - self.last_write_time;
+ let time_interval = shirabe_php_shim::microtime() - self.last_write_time;
// Draw regardless of other limits
if self.max == step {
@@ -534,7 +534,7 @@ impl ProgressBar {
}
self.previous_message = Some(original_message);
- self.last_write_time = shirabe_php_shim::microtime(true);
+ self.last_write_time = shirabe_php_shim::microtime();
self.output
.borrow()
diff --git a/crates/shirabe-external-packages/src/symfony/process/process.rs b/crates/shirabe-external-packages/src/symfony/process/process.rs
index 2466613..fe7b06c 100644
--- a/crates/shirabe-external-packages/src/symfony/process/process.rs
+++ b/crates/shirabe-external-packages/src/symfony/process/process.rs
@@ -318,7 +318,7 @@ impl Process {
}
self.reset_process_data();
- self.starttime = Some(php::microtime(true));
+ self.starttime = Some(php::microtime());
self.last_output_time = self.starttime;
let has_callback = callback.is_some();
self.callback = Some(self.build_callback(callback));
@@ -847,14 +847,14 @@ impl Process {
/// Stops the process.
pub fn stop(&mut self, timeout: f64, signal: Option<i64>) -> Option<i64> {
- let timeout_micro = php::microtime(true) + timeout;
+ let timeout_micro = php::microtime() + timeout;
if self.is_running() {
// given SIGTERM may not be defined and that "proc_terminate" uses the constant value
// and not the constant itself, we use the same here
let _ = self.do_signal(15, false);
loop {
php::usleep(1000);
- if !(self.is_running() && php::microtime(true) < timeout_micro) {
+ if !(self.is_running() && php::microtime() < timeout_micro) {
break;
}
}
@@ -880,7 +880,7 @@ impl Process {
/// Adds a line to the STDOUT stream.
pub fn add_output(&mut self, line: &str) {
- self.last_output_time = Some(php::microtime(true));
+ self.last_output_time = Some(php::microtime());
php::fseek3(self.stdout.clone(), 0, php::SEEK_END);
php::fwrite(self.stdout.clone(), line, line.len() as i64);
@@ -889,7 +889,7 @@ impl Process {
/// Adds a line to the STDERR stream.
pub fn add_error_output(&mut self, line: &str) {
- self.last_output_time = Some(php::microtime(true));
+ self.last_output_time = Some(php::microtime());
php::fseek3(self.stderr.clone(), 0, php::SEEK_END);
php::fwrite(self.stderr.clone(), line, line.len() as i64);
@@ -1039,7 +1039,7 @@ impl Process {
}
if let Some(timeout) = self.timeout {
- if timeout < php::microtime(true) - self.starttime.unwrap_or(0.0) {
+ if timeout < php::microtime() - self.starttime.unwrap_or(0.0) {
self.stop(0.0, None);
return Err(ProcessTimedOutException::new(
@@ -1051,7 +1051,7 @@ impl Process {
}
if let Some(idle_timeout) = self.idle_timeout {
- if idle_timeout < php::microtime(true) - self.last_output_time.unwrap_or(0.0) {
+ if idle_timeout < php::microtime() - self.last_output_time.unwrap_or(0.0) {
self.stop(0.0, None);
return Err(ProcessTimedOutException::new(
diff --git a/crates/shirabe-php-shim/src/datetime.rs b/crates/shirabe-php-shim/src/datetime.rs
index 79c5ea2..9810966 100644
--- a/crates/shirabe-php-shim/src/datetime.rs
+++ b/crates/shirabe-php-shim/src/datetime.rs
@@ -32,8 +32,11 @@ pub fn time() -> i64 {
.as_secs() as i64
}
-pub fn microtime(_get_as_float: bool) -> f64 {
- todo!()
+pub fn microtime() -> f64 {
+ let duration = std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .unwrap();
+ duration.as_secs_f64()
}
// PHP defaults to "UTC" when no default timezone has been configured.
diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs
index 94f904f..01515a1 100644
--- a/crates/shirabe/src/console/application.rs
+++ b/crates/shirabe/src/console/application.rs
@@ -911,7 +911,7 @@ impl Application {
.borrow()
.has_parameter_option(PhpMixed::from(vec!["--profile"]), false)
{
- start_time = Some(microtime(true));
+ start_time = Some(microtime());
// PHP: $this->io->enableDebugging($startTime).
// TODO(phase-c): enableDebugging exists only on ConsoleIO, not on IOInterface,
// and self.io is still the NullIO because the ConsoleIO construction above is
@@ -951,7 +951,7 @@ impl Application {
"<info>Memory usage: {}MiB (peak: {}MiB), time: {}s</info>",
round((memory_get_usage() as f64) / 1024.0 / 1024.0, 2),
round((memory_get_peak_usage(false) as f64) / 1024.0 / 1024.0, 2),
- round(microtime(true) - st, 2)
+ round(microtime() - st, 2)
));
}
diff --git a/crates/shirabe/src/dependency_resolver/pool_builder.rs b/crates/shirabe/src/dependency_resolver/pool_builder.rs
index 9b4c561..c2e328b 100644
--- a/crates/shirabe/src/dependency_resolver/pool_builder.rs
+++ b/crates/shirabe/src/dependency_resolver/pool_builder.rs
@@ -1060,7 +1060,7 @@ impl PoolBuilder {
self.io.debug("Running pool optimizer.", &[]);
- let before = microtime(true);
+ let before = microtime();
let total = pool.get_packages().len() as f64;
let pool = self
@@ -1078,7 +1078,7 @@ impl PoolBuilder {
self.io.write3(
&format!(
"Pool optimizer completed in {:.3} seconds",
- (microtime(true) - before),
+ (microtime() - before),
),
true,
io_interface::VERY_VERBOSE,
@@ -1109,7 +1109,7 @@ impl PoolBuilder {
self.io.debug("Running security advisory pool filter.", &[]);
- let before = microtime(true);
+ let before = microtime();
let total = pool.get_packages().len() as f64;
let repos_owned: Vec<RepositoryInterfaceHandle> = repositories.to_vec();
@@ -1128,7 +1128,7 @@ impl PoolBuilder {
self.io.write3(
&format!(
"Security advisory pool filter completed in {:.3} seconds",
- (microtime(true) - before),
+ (microtime() - before),
),
true,
io_interface::VERY_VERBOSE,
diff --git a/crates/shirabe/src/dependency_resolver/solver.rs b/crates/shirabe/src/dependency_resolver/solver.rs
index d6654a9..52c4580 100644
--- a/crates/shirabe/src/dependency_resolver/solver.rs
+++ b/crates/shirabe/src/dependency_resolver/solver.rs
@@ -259,13 +259,13 @@ impl Solver {
self.io
.write_error3("Resolving dependencies through SAT", true, crate::io::DEBUG);
- let before = microtime(true);
+ let before = microtime();
self.run_sat()?;
self.io.write_error3("", true, crate::io::DEBUG);
self.io.write_error3(
&format!(
"Dependency resolution completed in {:.3} seconds",
- microtime(true) - before,
+ microtime() - before,
),
true,
crate::io::VERBOSE,
diff --git a/crates/shirabe/src/io/console_io.rs b/crates/shirabe/src/io/console_io.rs
index 25ec02d..e6261c7 100644
--- a/crates/shirabe/src/io/console_io.rs
+++ b/crates/shirabe/src/io/console_io.rs
@@ -96,7 +96,7 @@ impl ConsoleIO {
let messages = if let Some(start_time) = self.start_time {
let memory_usage = (shirabe_php_shim::memory_get_usage() as f64) / 1024.0 / 1024.0;
- let time_spent = microtime(true) - start_time;
+ let time_spent = microtime() - start_time;
// PHP: array_map(fn ($message): string => sprintf(...), (array) $messages)
let arr: Vec<String> = match &messages {
PhpMixed::String(s) => vec![s.clone()],
diff --git a/crates/shirabe/tests/util/silencer_test.rs b/crates/shirabe/tests/util/silencer_test.rs
index c4e3baa..88d33c6 100644
--- a/crates/shirabe/tests/util/silencer_test.rs
+++ b/crates/shirabe/tests/util/silencer_test.rs
@@ -32,9 +32,8 @@ fn test_silencer() {
/// Test whether exception from silent callbacks are correctly forwarded.
#[test]
-#[ignore = "microtime is todo!() in the php-shim"]
fn test_silenced_exception() {
- let verification = format!("{}", microtime(false));
+ let verification = format!("{}", microtime());
let err = Silencer::call(|| -> anyhow::Result<()> {
Err(RuntimeException {
message: verification.clone(),