Skip to content

Instantly share code, notes, and snippets.

@laanwj
Last active November 30, 2021 09:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save laanwj/108877a28ec03836568a to your computer and use it in GitHub Desktop.
Save laanwj/108877a28ec03836568a to your computer and use it in GitHub Desktop.
Measure during compile process
./configure --disable-ccache --with-gui=qt5 --with-incompatible-bdb CC="$PWD/../devtools/mtime.sh gcc" CXX="$PWD/../devtools/mtime.sh g++" CPP="$PWD/../devtools/mtime.sh cpp"
#!/bin/bash
# Write compile command and statistics for later processing
MEASURE_OUTPUT=/tmp/measurements
echo "$@" >> $MEASURE_OUTPUT
/usr/bin/time -a -o $MEASURE_OUTPUT "$@"
#!/usr/bin/python3
# Process measurements file into a csv
import re
MEASURE_OUTPUT='/tmp/measurements'
CSV_OUTPUT='compile_stats.csv'
#g++ -DHAVE_CONFIG_H -I. -I../src/config -I./obj -DBUILD_BITCOIN_INTERNAL -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -g -O2 -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter -Wstack-protector -fstack-protector-all -MT crypto/libbitcoinconsensus_la-hmac_sha512.lo -MD -MP -MF crypto/.deps/libbitcoinconsensus_la-hmac_sha512.Tpo -c crypto/hmac_sha512.cpp -fPIC -DPIC -o crypto/.libs/libbitcoinconsensus_la-hmac_sha512.o
#0.06user 0.01system 0:00.07elapsed 98%CPU (0avgtext+0avgdata 13876maxresident)k
#0inputs+96outputs (0major+5806minor)pagefaults 0swaps
re_source = re.compile('[^ ]+\.(cpp|cc)')
re_stats1 = re.compile('([0-9\.]+)user ([0-9\.]+)system ([0-9\.:]+)elapsed ([0-9]+)%CPU \(([0-9]+)avgtext\+([0-9]+)avgdata ([0-9]+)maxresident\)k')
re_stats2 = re.compile('([0-9]+)inputs\+([0-9]+)outputs \(([0-9]+)major\+([0-9]+)minor\)pagefaults ([0-9]+)swaps')
def read_stats(filename):
out = []
with open(filename) as f:
state = 0
for line in f:
line = line.rstrip()
if state == 0:
cmd = line
state = 1
elif state == 1:
if line.startswith("Command exited with non-zero status"):
continue # hack around leveldb detection
state = 2
m = re_stats1.match(line)
if not m:
print('could not parse line1: '+line)
exit(1)
line1 = m.groups()
elif state == 2:
state = 0
m = re_stats2.match(line)
if not m:
print('could not parse line2: '+line)
exit(1)
line2 = m.groups()
# Extract name
m = re_source.search(cmd)
ispic = '-fPIC' in cmd
if m:
name = m.group(0)
out.append((name,ispic) + line1 + line2)
else:
pass # no source file (linking stage etc...)
return out
out = read_stats(MEASURE_OUTPUT)
import csv
with open(CSV_OUTPUT,'w') as f:
w = csv.writer(f)
#re_stats1 = re.compile('([0-9\.]+)user ([0-9\.]+)system ([0-9\.:]+)elapsed ([0-9]+)%CPU \(([0-9]+)avgtext\+([0-9]+)avgdata ([0-9]+)maxresident\)k')
#re_stats2 = re.compile('([0-9]+)inputs\+([0-9]+)outputs \(([0-9]+)major\+([0-9]+)minor\)pagefaults ([0-9]+)swaps')
w.writerow(['source','PIC','user','system','elapsed','CPU','avgtext','avgdata','maxresident','inputs','outputs','major_pagefaults','minor_pagefaults','swaps'])
for line in out:
w.writerow(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment