2018-11-29 22:11:05 +00:00
|
|
|
# beacon_chain
|
2021-04-26 19:41:35 +00:00
|
|
|
# Copyright (c) 2018-2021 Status Research & Development GmbH
|
2018-11-29 22:11:05 +00:00
|
|
|
# Licensed and distributed under either of
|
2019-11-25 15:30:02 +00:00
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
2018-11-29 22:11:05 +00:00
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2021-04-28 16:41:02 +00:00
|
|
|
{.push raises: [Defect].}
|
|
|
|
{.used.}
|
|
|
|
|
2018-11-29 22:11:05 +00:00
|
|
|
import
|
2021-04-28 16:41:02 +00:00
|
|
|
std/[algorithm, strformat, stats, tables, times],
|
|
|
|
testutils/markdown_reports,
|
|
|
|
unittest2,
|
|
|
|
../beacon_chain/spec/presets
|
2018-11-29 22:11:05 +00:00
|
|
|
|
2021-04-28 16:41:02 +00:00
|
|
|
export unittest2
|
2021-03-01 19:50:43 +00:00
|
|
|
|
2019-12-05 10:27:00 +00:00
|
|
|
type
|
|
|
|
TestDuration = tuple[duration: float, label: string]
|
|
|
|
|
2019-05-27 12:48:13 +00:00
|
|
|
func preset*(): string =
|
|
|
|
" [Preset: " & const_preset & ']'
|
|
|
|
|
2019-12-05 10:27:00 +00:00
|
|
|
# For state_sim
|
|
|
|
template withTimer*(duration: var float, body: untyped) =
|
|
|
|
let start = getMonoTime()
|
|
|
|
|
|
|
|
block:
|
|
|
|
body
|
|
|
|
|
|
|
|
duration = (getMonoTime() - start).inMicroseconds.float / 1000000.0
|
|
|
|
|
|
|
|
# For state_sim
|
2019-12-03 16:45:12 +00:00
|
|
|
template withTimerRet*(stats: var RunningStat, body: untyped): untyped =
|
|
|
|
let start = getMonoTime()
|
|
|
|
let tmp = block:
|
|
|
|
body
|
|
|
|
let stop = getMonoTime()
|
|
|
|
stats.push (stop - start).inMicroseconds.float / 1000000.0
|
2018-12-13 16:00:55 +00:00
|
|
|
|
2019-12-03 16:45:12 +00:00
|
|
|
tmp
|
2019-11-27 22:48:12 +00:00
|
|
|
|
2019-12-05 10:27:00 +00:00
|
|
|
var testTimes: seq[TestDuration]
|
2020-03-10 04:00:19 +00:00
|
|
|
var status = initOrderedTable[string, OrderedTable[string, Status]]()
|
|
|
|
var last: string
|
2019-12-05 10:27:00 +00:00
|
|
|
|
2021-04-28 16:41:02 +00:00
|
|
|
type TimingCollector = ref object of OutputFormatter
|
|
|
|
|
|
|
|
func toFloatSeconds(duration: Duration): float =
|
|
|
|
duration.inNanoseconds().float / 1_000_000_000.0
|
|
|
|
|
|
|
|
method testEnded*(formatter: TimingCollector, testResult: TestResult) =
|
|
|
|
{.gcsafe.}: # Lie!
|
|
|
|
status.mGetOrPut(testResult.suiteName, initOrderedTable[string, Status]())[testResult.testName] =
|
|
|
|
case testResult.status
|
|
|
|
of TestStatus.OK: Status.OK
|
|
|
|
of TestStatus.FAILED: Status.Fail
|
|
|
|
of TestStatus.SKIPPED: Status.Skip
|
|
|
|
testTimes.add (testResult.duration.toFloatSeconds, testResult.testName)
|
|
|
|
|
2020-03-10 04:00:19 +00:00
|
|
|
proc summarizeLongTests*(name: string) =
|
2019-12-05 10:27:00 +00:00
|
|
|
# TODO clean-up and make machine-readable/storable the output
|
|
|
|
sort(testTimes, system.cmp, SortOrder.Descending)
|
|
|
|
|
2021-04-28 16:41:02 +00:00
|
|
|
try:
|
|
|
|
echo ""
|
|
|
|
echo "10 longest individual test durations"
|
|
|
|
echo "------------------------------------"
|
|
|
|
for i, item in testTimes:
|
|
|
|
echo &"{item.duration:6.2f}s for {item.label}"
|
|
|
|
if i >= 10:
|
|
|
|
break
|
|
|
|
|
|
|
|
status.sort do (a: (string, OrderedTable[string, Status]),
|
|
|
|
b: (string, OrderedTable[string, Status])) -> int: cmp(a[0], b[0])
|
|
|
|
|
|
|
|
generateReport(name & "-" & const_preset, status, width=90)
|
|
|
|
except CatchableError as exc:
|
|
|
|
raiseAssert exc.msg
|
|
|
|
|
|
|
|
addOutputFormatter(new TimingCollector)
|