Add solana-upload-perf to parse json from bench and upload to influx (#1166)

This commit is contained in:
sakridge 2018-09-19 13:16:55 -07:00 committed by GitHub
parent 5740ea3807
commit 2981076a14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 1 deletions

View File

@ -17,6 +17,10 @@ authors = [
]
license = "Apache-2.0"
[[bin]]
name = "solana-upload-perf"
path = "src/bin/upload-perf.rs"
[[bin]]
name = "solana-bench-streamer"
path = "src/bin/bench-streamer.rs"

View File

@ -10,4 +10,6 @@ _() {
"$@"
}
_ cargo bench --features=unstable --verbose
BENCH_FILE=bench_output.log
_ cargo +nightly bench --features=unstable --verbose -- -Z unstable-options --format=json | tee $BENCH_FILE
_ cargo run --bin solana-upload-perf -- $BENCH_FILE

49
src/bin/upload-perf.rs Normal file
View File

@ -0,0 +1,49 @@
extern crate influx_db_client;
extern crate serde_json;
extern crate solana;
use influx_db_client as influxdb;
use serde_json::Value;
use solana::metrics;
use std::env;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::process::Command;
fn main() {
let args: Vec<String> = env::args().collect();
// Open the path in read-only mode, returns `io::Result<File>`
let fname = &args[1];
let file = match File::open(fname) {
Err(why) => panic!("couldn't open {}: {:?}", fname, why),
Ok(file) => file,
};
let git_output = Command::new("git")
.args(&["rev-parse", "HEAD"])
.output()
.expect("failed to execute git rev-parse");
let git_commit_hash = String::from_utf8_lossy(&git_output.stdout);
let trimmed_hash = git_commit_hash.trim().to_string();
println!("uploading hash: {}", trimmed_hash);
for line in BufReader::new(file).lines() {
if let Ok(v) = serde_json::from_str(&line.unwrap()) {
let v: Value = v;
if v["type"] == "bench" {
println!("{}", v);
println!(" {}", v["type"]);
let median = v["median"].to_string().parse().unwrap();
let deviation = v["deviation"].to_string().parse().unwrap();
metrics::submit(
influxdb::Point::new(&v["name"].to_string())
.add_field("median", influxdb::Value::Integer(median))
.add_field("deviation", influxdb::Value::Integer(deviation))
.add_field(
"commit",
influxdb::Value::String(git_commit_hash.trim().to_string()),
).to_owned(),
);
}
}
}
}