Skip to content
Open
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
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ repos:
args: [--all-targets]
- id: clippy
args: [--all-targets, --, -D, warnings]
- repo: local
hooks:
- id: check-config-schema
name: check config schema is up to date
entry: bash -c 'cargo run --bin generate-config-schema && git diff --exit-code schemas/codspeed.schema.json'
language: system
42 changes: 42 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ version = "4.9.0"
edition = "2024"
repository = "https://github.com/CodSpeedHQ/codspeed"
publish = false
default-run = "codspeed"

[[bin]]
name = "codspeed"
path = "src/main.rs"

[[bin]]
name = "generate-config-schema"
path = "src/bin/generate_config_schema.rs"

[dependencies]
anyhow = { workspace = true }
Expand All @@ -27,6 +31,7 @@ reqwest = { version = "0.11.22", features = [
] }
reqwest-middleware = "0.2.4"
reqwest-retry = "0.3.0"
schemars = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true, features = ["preserve_order"] }
url = "2.4.1"
Expand Down Expand Up @@ -91,6 +96,7 @@ anyhow = "1.0"
clap = { version = "4.5", features = ["derive", "env"] }
libc = "0.2"
log = "0.4.28"
schemars = "0.8"
serde_json = "1.0"
serde = { version = "1.0.228", features = ["derive"] }
ipc-channel = "0.18"
Expand Down Expand Up @@ -119,3 +125,5 @@ strip = true

[package.metadata.dist]
targets = ["aarch64-unknown-linux-musl", "x86_64-unknown-linux-musl"]
binaries.aarch64-unknown-linux-musl = ["codspeed"]
binaries.x86_64-unknown-linux-musl = ["codspeed"]
159 changes: 159 additions & 0 deletions schemas/codspeed.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ProjectConfig",
"description": "Project-level configuration from codspeed.yaml file\n\nThis configuration provides default options for the run and exec commands. CLI arguments always take precedence over config file values.",
"type": "object",
"properties": {
"options": {
"description": "Default options to apply to all benchmark runs",
"anyOf": [
{
"$ref": "#/definitions/ProjectOptions"
},
{
"type": "null"
}
]
},
"targets": {
"description": "List of benchmark targets to execute",
"type": [
"array",
"null"
],
"items": {
"$ref": "#/definitions/Target"
}
}
},
"definitions": {
"ProjectOptions": {
"description": "Root-level options that apply to all benchmark runs unless overridden by CLI",
"type": "object",
"properties": {
"max-rounds": {
"description": "Maximum number of rounds",
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
},
"max-time": {
"description": "Maximum total execution time",
"type": [
"string",
"null"
]
},
"min-rounds": {
"description": "Minimum number of rounds",
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
},
"min-time": {
"description": "Minimum total execution time",
"type": [
"string",
"null"
]
},
"warmup-time": {
"description": "Duration of warmup phase (e.g., \"1s\", \"500ms\")",
"type": [
"string",
"null"
]
},
"working-directory": {
"description": "Working directory where commands will be executed (relative to config file)",
"type": [
"string",
"null"
]
}
}
},
"Target": {
"description": "A benchmark target to execute",
"type": "object",
"required": [
"exec"
],
"properties": {
"exec": {
"description": "Command to execute",
"type": "string"
},
"name": {
"description": "Optional name for this target",
"type": [
"string",
"null"
]
},
"options": {
"description": "Target-specific options",
"anyOf": [
{
"$ref": "#/definitions/TargetOptions"
},
{
"type": "null"
}
]
}
}
},
"TargetOptions": {
"description": "Walltime execution options matching WalltimeExecutionArgs structure",
"type": "object",
"properties": {
"max-rounds": {
"description": "Maximum number of rounds",
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
},
"max-time": {
"description": "Maximum total execution time",
"type": [
"string",
"null"
]
},
"min-rounds": {
"description": "Minimum number of rounds",
"type": [
"integer",
"null"
],
"format": "uint64",
"minimum": 0.0
},
"min-time": {
"description": "Minimum total execution time",
"type": [
"string",
"null"
]
},
"warmup-time": {
"description": "Duration of warmup phase (e.g., \"1s\", \"500ms\")",
"type": [
"string",
"null"
]
}
}
}
}
}
23 changes: 23 additions & 0 deletions src/bin/generate_config_schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//! Generates JSON Schema for codspeed.yaml configuration file
//!
//! Run with:
//! ```
//! cargo run --bin generate-config-schema
//! ```

use std::fs;

use codspeed_runner::ProjectConfig;
use schemars::schema_for;

const OUTPUT_FILE: &str = "schemas/codspeed.schema.json";

fn main() {
let schema = schema_for!(ProjectConfig);
let schema_json = serde_json::to_string_pretty(&schema).expect("Failed to serialize schema");
let output_file_path = std::path::Path::new(OUTPUT_FILE);
fs::create_dir_all(output_file_path.parent().unwrap())
.expect("Failed to create schemas directory");
fs::write(OUTPUT_FILE, format!("{schema_json}\n")).expect("Failed to write schema file");
println!("Schema written to {OUTPUT_FILE}");
}
38 changes: 38 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//! CodSpeed Runner library

mod api_client;
pub mod app;
mod auth;
mod binary_installer;
mod config;
mod exec;
mod executor;
mod instruments;
mod local_logger;
mod logger;
mod prelude;
mod project_config;
mod request_client;
mod run;
mod run_environment;
mod runner_mode;
mod setup;

pub use local_logger::clean_logger;
pub use project_config::{ProjectConfig, ProjectOptions, Target, TargetOptions, WalltimeOptions};
pub use runner_mode::RunnerMode;

use lazy_static::lazy_static;
use semver::Version;

pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const MONGODB_TRACER_VERSION: &str = "cs-mongo-tracer-v0.2.0";

pub const VALGRIND_CODSPEED_VERSION: Version = Version::new(3, 26, 0);
pub const VALGRIND_CODSPEED_DEB_REVISION_SUFFIX: &str = "0codspeed0";
lazy_static! {
pub static ref VALGRIND_CODSPEED_VERSION_STRING: String =
format!("{VALGRIND_CODSPEED_VERSION}.codspeed");
pub static ref VALGRIND_CODSPEED_DEB_VERSION: String =
format!("{VALGRIND_CODSPEED_VERSION}-{VALGRIND_CODSPEED_DEB_REVISION_SUFFIX}");
}
Loading
Loading