Skip to content

Commit

Permalink
Stats tooling improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
karolk91 committed May 1, 2024
1 parent 20b3d15 commit b409e9c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
18 changes: 18 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ mod integration_tests;
mod stats;
mod wasm;

use std::fmt::Display;

// export for use by contract! macro
use clap::Parser;
pub use stats::{collect_block_stats, print_block_info, BlockInfo};
Expand Down Expand Up @@ -54,12 +56,28 @@ pub enum Contract {
StorageReadWrite,
}

impl Display for TargetPlatform {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", clap::ArgEnum::to_possible_value(self).unwrap_or("unknown".into()).get_name())
}
}

impl Display for Contract {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", clap::ArgEnum::to_possible_value(self).unwrap_or("unknown".into()).get_name())
}
}

#[tokio::main]
async fn main() -> color_eyre::Result<()> {
color_eyre::install()?;
let cli = Cli::parse();
tracing_subscriber::fmt::init();

println!("Smart-bench run parameters:");
println!("Platform: {}", cli.chain);
println!("Contracts: {}", cli.contracts.iter().map(|arg| arg.to_string()).collect::<Vec<_>>().join("+"));

match cli.chain {
TargetPlatform::InkWasm => wasm::exec(cli).await,
TargetPlatform::SolWasm => wasm::exec(cli).await,
Expand Down
23 changes: 18 additions & 5 deletions stats/get_graph.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ DOCKER_COMPOSE_FILE="docker-compose.yml"
HOST="localhost"
GRAFANA_DASHBOARD_JSON="grafana-provisioning/dashboards/tps.json"

check_command() {
command -v "$1" >/dev/null 2>&1 && { $1 --version >/dev/null 2>&1; }
}

if check_command "docker compose"; then
DOCKER_COMPOSE="docker compose"
elif check_command "docker-compose"; then
DOCKER_COMPOSE="docker-compose"
else
echo "Neither 'docker compose' nor 'docker-compose' could be found or are functional on your system."
exit 1
fi

function echoerr() { echo "$@" 1>&2; }

function usage {
Expand Down Expand Up @@ -125,24 +138,24 @@ wait_for_containers() {
local retry_interval=1

echo "Waiting for all Docker containers to be running..."
retry_command "$max_retries" "$retry_interval" docker compose -f "$DOCKER_COMPOSE_FILE" \
retry_command "$max_retries" "$retry_interval" ${DOCKER_COMPOSE} -f "$DOCKER_COMPOSE_FILE" \
ps --services --filter "status=running" | grep -qvx " "
}

start_containers() {
echo "Starting docker containers"
docker compose -f "$DOCKER_COMPOSE_FILE" up -d
${DOCKER_COMPOSE} -f "$DOCKER_COMPOSE_FILE" up -d
wait_for_containers
}

stop_containers() {
echo "Stopping docker containers"
docker compose -f "$DOCKER_COMPOSE_FILE" down
${DOCKER_COMPOSE} -f "$DOCKER_COMPOSE_FILE" down
}

print_containers_logs() {
echo "Container logs -- START"
docker-compose -f "$DOCKER_COMPOSE_FILE" logs
${DOCKER_COMPOSE} -f "$DOCKER_COMPOSE_FILE" logs
echo "Container logs -- END"
}

Expand All @@ -158,7 +171,7 @@ convert_csv_to_line_protocol() {
gsub(/ /,"\\ ", field);
return field
}{
printf "%s,platform=%s,parachain_ver=%s,contract_type=%s,contract_compiler_ver=\"%s\" tx_per_sec=%s %s\n",
printf "%s,platform=\"%s\",parachain_ver=\"%s\",contract_type=\"%s\",contract_compiler_ver=\"%s\" tx_per_sec=%s %s\n",
"tps",
trim($2),
trim($3),
Expand Down
12 changes: 3 additions & 9 deletions stats/smart_bench_to_csv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ SCRIPT_PATH=$(dirname "$(realpath -s "${BASH_SOURCE[0]}")")
TIMESTAMP=$(date +%s)

if [ -p /dev/stdin ]; then
PROCESS_LIST=$(ps -u)
CONTRACT_TYPE=$(echo "${PROCESS_LIST}" | grep -v grep | grep -oE "erc20|flipper|incrementer|erc721|erc1155|odd-product|triangle-number|storage-read|storage-write|storage-read-write")
PLATFORM=$(echo "${PROCESS_LIST}" | grep -v grep | grep -oE "ink-wasm|sol-wasm|evm")

echo "${CONTRACT_TYPE}"
echo "${PLATFORM}"
STATS=$(</dev/stdin)
else
echo "No input was found on stdin, skipping!"
Expand Down Expand Up @@ -74,8 +68,8 @@ function parse_args {
parse_args "$@"


blocks=$(echo ${STATS} | grep -o 'Total Blocks: [0-9]*' | awk '{print $3}')
extrinsics=$(echo ${STATS} | grep -o 'Total Extrinsics: [0-9]*' | awk '{print $3}')
platform=$(echo ${STATS} | grep -o 'Platform: [a-z0-9-]*' | awk '{print $2}')
contract_types=$(echo ${STATS} | grep -o 'Contracts: [+a-z0-9-]*' | awk '{print $2}')
tps=$(echo ${STATS} | grep -o 'sTPS: [0-9]*' | awk '{print $2}')

echo "${TIMESTAMP}, ${PLATFORM}, not-supp, ${CONTRACT_TYPE}, ${tps}, not-supp, not-supp" >> "${CSV_OUTPUT}"
echo "${TIMESTAMP}, ${platform}, n/a, ${contract_types}, ${tps}, n/a, n/a" >> "${CSV_OUTPUT}"

0 comments on commit b409e9c

Please sign in to comment.