Unverified Commit f6840d14 authored by Jeremy Morrell's avatar Jeremy Morrell Committed by GitHub

Add timing function to build data module (#595)

* Add timing function to builddata module
parent ecc54c1e
...@@ -17,6 +17,16 @@ bd_set() { ...@@ -17,6 +17,16 @@ bd_set() {
kv_set "$BUILD_DATA_FILE" "$1" "$2" kv_set "$BUILD_DATA_FILE" "$1" "$2"
} }
# similar to mtime from stdlib
bd_time() {
local key="$1"
local start="$2"
local end="${3:-$(nowms)}"
local time
time="$(echo "${start}" "${end}" | awk '{ printf "%.3f", ($2 - $1)/1000 }')"
kv_set "$BUILD_DATA_FILE" "$key" "$time"
}
log_build_data() { log_build_data() {
# print all values on one line in logfmt format # print all values on one line in logfmt format
# https://brandur.org/logfmt # https://brandur.org/logfmt
......
...@@ -166,6 +166,18 @@ testBuildData() { ...@@ -166,6 +166,18 @@ testBuildData() {
# this isn't required, and this test serves as documentation # this isn't required, and this test serves as documentation
bd_set "a" "this should come first" bd_set "a" "this should come first"
assertEquals "a=\"this should come first\" foo=\"value with spaces\" test=different-foo" "$(log_build_data)" assertEquals "a=\"this should come first\" foo=\"value with spaces\" test=different-foo" "$(log_build_data)"
# dates generated by running `nowms; sleep 10; nowms`
bd_time "time" "1545178120033" "1545178130043"
assertEquals "10.010" "$(bd_get time)"
# dates generated by running `nowms; sleep 1; nowms`
bd_time "time" "1545178503025" "1545178504027"
assertEquals "1.002" "$(bd_get time)"
# dates generated by running `nowms; sleep 30; nowms`
bd_time "time" "1545178521204" "1545178551206"
assertEquals "30.002" "$(bd_get time)"
} }
testWebConcurrencyProfileScript() { testWebConcurrencyProfileScript() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment