Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
Add more profiling payloads (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
mre authored Nov 19, 2018
1 parent 549386f commit 82749f5
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 19 deletions.
133 changes: 133 additions & 0 deletions Cargo.lock

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

12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
SHELL := /bin/bash
.PHONY: help

ts := $(shell date --utc +%FT%TZ)
ts := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")

help: ## This help message
@echo -e "$$(grep -hE '^\S+:.*##' $(MAKEFILE_LIST) | sed -e 's/:.*##\s*/:/' -e 's/^\(.\+\):\(.*\)/\\x1b[36m\1\\x1b[m:\2/' | column -c2 -t -s :)"
Expand Down Expand Up @@ -53,13 +53,17 @@ plot: bench-compare ## Plot graph from benchmarks
@echo "Rendering plots from benchmarks"
pipenv run python benchmarks/histogram.py

.PHONY: build-profile
build-profile: ## Builds binary for profiling
cd profiling && pipenv run cargo build --release

# Setup instructions here:
# https://gist.github.com/dlaehnemann/df31787c41bd50c0fe223df07cf6eb89
.PHONY: profile
profile: OUTPUT_PATH = measurements/flame-$(ts).svg
profile: nightly ## Run perf-based profiling (only works on Linux!)
cd profiling && pipenv run cargo build --release
perf record --call-graph dwarf,16384 -e cpu-clock -F 997 target/release/profiling
profile: FLAGS=booleans --iterations 10000
profile: nightly build-profile ## Run perf-based profiling (only works on Linux!)
perf record --call-graph dwarf,16384 -e cpu-clock -F 997 target/release/profiling $(FLAGS)
time perf script | stackcollapse-perf.pl | c++filt | flamegraph.pl > $(OUTPUT_PATH)
@echo "$(OUTPUT_PATH)"

2 changes: 2 additions & 0 deletions profiling/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ authors = ["Matthias Endler <[email protected]>"]
[dependencies]
# Disabling the default features makes pyo3 choose binary linking
hyperjson = { path = "..", default-features = false }
structopt = "0.2.13"
clap = "2.32.0"

[dependencies.pyo3]
version = "0.5.0"
Expand Down
45 changes: 30 additions & 15 deletions profiling/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,43 @@
//! callgrind_annotate --auto=yes callgrind.out.35583 >out.rs
//! qcachegrind callgrind.out.35583
//! ```
extern crate structopt;
#[macro_use]
extern crate clap;

extern crate hyperjson;
extern crate pyo3;

use pyo3::prelude::*;
use std::fs;

mod profiles;

fn main() {
let bench_file_name = "benchmarks/dict_string_int_plain.txt";
use structopt::StructOpt;

let dict_string_int = fs::read_to_string(bench_file_name)
.expect(&format!("Could not open bench file '{}'", bench_file_name));
arg_enum! {
#[derive(Debug)]
enum Profile {
DictStringIntPlain,
Booleans
}
}

let gil = Python::acquire_gil();
let py = gil.python();
#[derive(StructOpt, Debug)]
struct Opt {
/// Profile to use
#[structopt(raw(possible_values = "&Profile::variants()", case_insensitive = "true"))]
profile: Profile,

let obj = dict_string_int.to_object(py);
/// Number of profiling iterations
#[structopt(long = "iterations", default_value = "100")]
iterations: u64,
}

for _ in 1..100 {
println!(
"{}",
hyperjson::loads_impl(py, obj.clone_ref(py), None, None, None, None, None, None).is_ok()
);
fn main() {
let Opt {
profile,
iterations,
} = Opt::from_args();
match profile {
Profile::DictStringIntPlain => profiles::dict_string_int_plain::exec(iterations),
Profile::Booleans => profiles::booleans::exec(iterations),
}
}
33 changes: 33 additions & 0 deletions profiling/src/profiles/booleans.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use pyo3::prelude::*;

pub fn exec(iterations: u64) {
let gil = Python::acquire_gil();
let py = gil.python();

let booleans = format!("[{} \"true\"]", "\"true\",".repeat(255));
let obj = booleans.to_object(py);

for _ in 0..iterations {
let deserialized =
hyperjson::loads_impl(py, obj.clone_ref(py), None, None, None, None, None, None)
.unwrap();
println!(
"{}",
hyperjson::dumps(
py,
deserialized,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
)
.is_ok()
);
}
}
22 changes: 22 additions & 0 deletions profiling/src/profiles/dict_string_int_plain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use pyo3::prelude::*;
use std::fs;

pub fn exec(iterations: u64) {
let bench_file_name = "benchmarks/dict_string_int_plain.txt";

let dict_string_int = fs::read_to_string(bench_file_name)
.expect(&format!("Could not open bench file '{}'", bench_file_name));

let gil = Python::acquire_gil();
let py = gil.python();

let obj = dict_string_int.to_object(py);

for _ in 0..iterations {
println!(
"{}",
hyperjson::loads_impl(py, obj.clone_ref(py), None, None, None, None, None, None)
.is_ok()
);
}
}
2 changes: 2 additions & 0 deletions profiling/src/profiles/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod booleans;
pub mod dict_string_int_plain;

0 comments on commit 82749f5

Please sign in to comment.