Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop benchmarks #951

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 153 additions & 21 deletions integration_tests/src/bin/benchmark/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{path::PathBuf, time::Duration};

use compositor_pipeline::pipeline::{self, encoder::ffmpeg_h264};

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Argument {
IterateExp,
Maximize,
Expand Down Expand Up @@ -33,7 +33,7 @@ impl std::str::FromStr for Argument {

s.parse::<u64>()
.map(Argument::Constant)
.map_err(|e| format!("{e}"))
.map_err(|e| e.to_string())
}
}

Expand Down Expand Up @@ -99,6 +99,127 @@ impl From<EncoderPreset> for ffmpeg_h264::EncoderPreset {
}
}

#[derive(Debug, Clone, Copy)]
pub enum ResolutionPreset {
Res4320p,
Res2160p,
Res1440p,
Res1080p,
Res720p,
Res480p,
Res360p,
Res240p,
Res144p,
}

impl std::str::FromStr for ResolutionPreset {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"4320p" => Ok(ResolutionPreset::Res4320p),
"2160p" => Ok(ResolutionPreset::Res2160p),
"1440p" => Ok(ResolutionPreset::Res1440p),
"1080p" => Ok(ResolutionPreset::Res1080p),
"720p" => Ok(ResolutionPreset::Res720p),
"480p" => Ok(ResolutionPreset::Res480p),
"360p" => Ok(ResolutionPreset::Res360p),
"240p" => Ok(ResolutionPreset::Res240p),
"144p" => Ok(ResolutionPreset::Res144p),
_ => Err(
"invalid resolution preset, available options: sd, hd, fhd, qhd, uhd".to_string(),
),
}
}
}

#[derive(Debug, Clone, Copy)]
pub enum ResolutionConstant {
Preset(ResolutionPreset),
Value(Resolution),
}

impl std::str::FromStr for ResolutionConstant {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
if s.as_bytes()
.first()
.ok_or("error while parsing resolution argument".to_string())?
.is_ascii_digit()
{
let (width, height) = s
.split_once("x")
.ok_or("invalid resolution value, should look like eg. `1920x1080`")?;
Ok(ResolutionConstant::Value(Resolution {
width: width.parse::<u32>().map_err(|e| e.to_string())?,
height: height.parse::<u32>().map_err(|e| e.to_string())?,
}))
} else {
let preset = s.parse::<ResolutionPreset>().map_err(|e| e.to_string())?;
Ok(ResolutionConstant::Preset(preset))
}
}
}

#[derive(Debug, Clone, Copy)]
pub struct Resolution {
pub width: u32,
pub height: u32,
}

impl From<ResolutionConstant> for Resolution {
fn from(value: ResolutionConstant) -> Self {
match value {
ResolutionConstant::Value(resolution) => resolution,
ResolutionConstant::Preset(preset) => preset.into(),
}
}
}

impl From<ResolutionPreset> for Resolution {
fn from(value: ResolutionPreset) -> Self {
match value {
ResolutionPreset::Res4320p => Resolution {
width: 7680,
height: 4320,
},
ResolutionPreset::Res2160p => Resolution {
width: 3840,
height: 2160,
},
ResolutionPreset::Res1440p => Resolution {
width: 2560,
height: 1440,
},
ResolutionPreset::Res1080p => Resolution {
width: 1920,
height: 1080,
},
ResolutionPreset::Res720p => Resolution {
width: 1280,
height: 720,
},
ResolutionPreset::Res480p => Resolution {
width: 854,
height: 480,
},
ResolutionPreset::Res360p => Resolution {
width: 640,
height: 360,
},
ResolutionPreset::Res240p => Resolution {
width: 426,
height: 240,
},
ResolutionPreset::Res144p => Resolution {
width: 256,
height: 144,
},
}
}
}

/// Only one option can be set to "maximize"
#[derive(Debug, Clone, clap::Parser)]
pub struct Args {
Expand All @@ -108,19 +229,24 @@ pub struct Args {

/// [possible values: iterate_exp, maximize or a number]
#[arg(long)]
pub decoder_count: Argument,
pub input_count: Argument,

/// [possible values: iterate_exp, maximize or a number]
#[arg(long)]
pub file_path: PathBuf,
pub output_count: Argument,

#[arg(long)]
pub output_width: u32,
pub file_path: PathBuf,

/// [possible values: uhd, qhd, fhd, hd, sd or `<width>x<height>`]
#[arg(long)]
pub output_height: u32,
pub output_resolution: ResolutionConstant,

#[arg(long)]
pub encoder_preset: EncoderPreset,
pub disable_encoder: bool,

#[arg(long, required_unless_present("disable_encoder"))]
pub encoder_preset: Option<EncoderPreset>,

/// warm-up time in seconds
#[arg(long)]
Expand All @@ -141,33 +267,36 @@ pub struct Args {

impl Args {
pub fn arguments(&self) -> Box<[Argument]> {
vec![self.framerate, self.decoder_count].into_boxed_slice()
vec![self.framerate, self.input_count, self.output_count].into_boxed_slice()
}

pub fn with_arguments(&self, arguments: &[Argument]) -> SingleBenchConfig {
SingleBenchConfig {
framerate: arguments[0].as_constant().unwrap(),
decoder_count: arguments[1].as_constant().unwrap(),
input_count: arguments[1].as_constant().unwrap(),
output_count: arguments[2].as_constant().unwrap(),

file_path: self.file_path.clone(),
output_width: self.output_width,
output_height: self.output_height,
output_resolution: self.output_resolution.into(),
warm_up_time: self.warm_up_time.0,
measured_time: self.measured_time.0,
video_decoder: self.video_decoder.into(),
output_encoder_preset: self.encoder_preset.into(),
disable_encoder: self.disable_encoder,
output_encoder_preset: self.encoder_preset.map(|preset| preset.into()),
framerate_tolerance_multiplier: self.framerate_tolerance,
}
}
}

#[derive(Debug)]
pub struct SingleBenchConfig {
pub decoder_count: u64,
pub input_count: u64,
pub output_count: u64,
pub framerate: u64,
pub file_path: PathBuf,
pub output_width: u32,
pub output_height: u32,
pub output_encoder_preset: ffmpeg_h264::EncoderPreset,
pub output_resolution: Resolution,
pub disable_encoder: bool,
pub output_encoder_preset: Option<ffmpeg_h264::EncoderPreset>,
pub warm_up_time: Duration,
pub measured_time: Duration,
pub video_decoder: pipeline::VideoDecoder,
Expand All @@ -176,18 +305,21 @@ pub struct SingleBenchConfig {

impl SingleBenchConfig {
pub fn log_running_config(&self) {
tracing::info!("config: {:?}", self);
tracing::info!(
"checking configuration: framerate: {}, decoder count: {}",
"checking configuration: framerate: {}, decoder count: {}, encoder count: {}",
self.framerate,
self.decoder_count
self.input_count,
self.output_count
);
}

pub fn log_as_report(&self) {
print!("{}\t", self.decoder_count);
print!("{}\t", self.input_count);
print!("{}\t", self.output_count);
print!("{}\t", self.framerate);
print!("{}\t", self.output_width);
print!("{}\t", self.output_height);
print!("{:?}\t", self.output_resolution);
print!("{:?}\t", self.disable_encoder);
print!("{:?}\t", self.output_encoder_preset);
print!("{:?}\t", self.warm_up_time);
print!("{:?}\t", self.measured_time);
Expand Down
Loading
Loading