Skip to content

Commit

Permalink
fix: Write results file
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugoch committed Sep 20, 2024
1 parent ce70757 commit 469edab
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
10 changes: 6 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::fs::File;
use std::io::Write;
use std::path::Path;
use std::sync::Arc;

use chrono::Local;
use log::{error, info, Level, LevelFilter};
use log::{debug, error, info, Level, LevelFilter};
use tokio::sync::broadcast::Sender;
use tokio::sync::Mutex;
use writers::BenchmarkReportWriter;
Expand Down Expand Up @@ -94,7 +95,7 @@ pub async fn run(run_config: RunConfiguration,
let ui_thread = tokio::spawn(async move {
tokio::select! {
_ = stop_receiver.recv() => {
error!("Received stop signal, stopping benchmark");
debug!("Received stop signal, stopping benchmark");
}
_ = async{
if run_config.interactive {
Expand Down Expand Up @@ -126,8 +127,9 @@ pub async fn run(run_config: RunConfiguration,
info!("Throughput is {requests_throughput} req/s",requests_throughput = results.get_results()[0].successful_request_rate().unwrap());
let report = benchmark.get_report();
let path = format!("results/{}_{}.json", chrono::Utc::now().format("%Y-%m-%d-%H-%M-%S"),run_config.tokenizer_name.replace("/","_"));
let path=Path::new(&path);
let writer=BenchmarkReportWriter::new(config.clone(), report)?;
writer.json(&path).await?;
writer.json(path).await?;
},
Err(e) => {
error!("Error running benchmark: {:?}", e.to_string());
Expand All @@ -136,7 +138,7 @@ pub async fn run(run_config: RunConfiguration,
};
}
_ = stop_receiver.recv() => {
error!("Received stop signal, stopping benchmark");
debug!("Received stop signal, stopping benchmark");
}
}
let _ = tx.send(Event::BenchmarkReportEnd);
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::time::Duration;
use clap::{Error, Parser};
use clap::error::ErrorKind::InvalidValue;
use log::error;
use log::{debug};
use reqwest::Url;
use tokio::sync::broadcast;
use text_generation_inference_benchmark::{run, RunConfiguration, TokenizeOptions};
Expand Down Expand Up @@ -123,7 +123,7 @@ async fn main() {
let stop_sender_clone = stop_sender.clone();
tokio::spawn(async move {
tokio::signal::ctrl_c().await.expect("Failed to listen for ctrl-c");
error!("Received stop signal, stopping benchmark");
debug!("Received stop signal, stopping benchmark");
stop_sender_clone.send(()).expect("Failed to send stop signal");
});

Expand Down
4 changes: 2 additions & 2 deletions src/scheduler.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;
use std::time::Instant;
use log::{debug, info, trace, warn};
use log::{debug, trace, warn};
use tokio::sync::mpsc::{Sender, UnboundedReceiver, UnboundedSender};
use crate::executors::{ConstantArrivalRateExecutor, Executor, ExecutorConfig, ConstantVUsExecutor};
use crate::requests::{TextGenerationAggregatedResponse, TextGenerationBackend, TextRequestGenerator};
Expand Down Expand Up @@ -77,7 +77,7 @@ impl Scheduler {
tokio::spawn(async move {
tokio::select! {
_ = stop_receiver.recv() => {
info!("Received stop signal, stopping benchmark");
debug!("Received stop signal, stopping benchmark");
return
}
_ = async{
Expand Down
16 changes: 10 additions & 6 deletions src/writers.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::path::Path;
use serde::Serialize;
use tokio::fs;
use sysinfo::{CpuRefreshKind, MemoryRefreshKind, System};
Expand Down Expand Up @@ -108,13 +109,16 @@ impl BenchmarkReportWriter {
system: SystemInfo::new(),
})
}
pub async fn json(&self, path: &str) -> anyhow::Result<()> {
pub async fn json(&self, path: &Path) -> anyhow::Result<()> {
// write the benchmark report to json
let report = serde_json::to_string(&self).unwrap();
let path = path.to_string();
// create path
if !std::path::Path::new(&path).exists() {
fs::create_dir_all(&path).await?;
let report = serde_json::to_string(&self)?;

// create path hierarchy if it doesn't exist
if !path.exists() {
match path.parent() {
Some(parent) => fs::create_dir_all(parent).await?,
None => {}
}
}
fs::write(path, report).await?;
Ok(())
Expand Down

0 comments on commit 469edab

Please sign in to comment.