Skip to content

Commit

Permalink
ci: WIP integrate benchmark plugin
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
  • Loading branch information
magik6k committed Apr 18, 2018
1 parent 6b3915b commit be62eca
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 1 deletion.
26 changes: 25 additions & 1 deletion ci/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def gobuild_step(list) {
}
}

def benchNodeAddr
def benchJsonHash

/* PIPELINE */

ansiColor('xterm') { withEnv(['TERM=xterm-color']) { timeout(time: 30, unit: 'MINUTES') {
Expand All @@ -79,7 +82,7 @@ ansiColor('xterm') { withEnv(['TERM=xterm-color']) { timeout(time: 30, unit: 'MI
},
'go build': {
gobuild_step(fast_build_platforms)
}
},
)
}

Expand Down Expand Up @@ -161,6 +164,27 @@ ansiColor('xterm') { withEnv(['TERM=xterm-color']) { timeout(time: 30, unit: 'MI
}
}
},
'benchmark': {
setupStep('linux') { run ->
// Figure out our IP + Multiaddr for master to ensure connection
// def nodeIP = run returnStdout: true, script: 'dig +short myip.opendns.com @resolver1.opendns.com'
// benchNodeAddr = run returnStdout: true, script: "ipfs id --format='<addrs>\n' | grep $nodeIP"

run 'make test/bench/bench-results.json'

// benchJsonHash = run(returnStdout: true, script: "ipfs add -Q test/bench/bench-results.json").trim()

benchmark altInputSchema: '', altInputSchemaLocation: '', inputLocation: 'test/bench/bench-results.json', schemaSelection: 'defaultSchema', truncateStrings: false
}
/*node(label: 'master') {
withEnv(["IPFS_PATH=/efs/.ipfs"]) {
sh "ipfs swarm connect $benchNodeAddr"
sh "ipfs get -o bench-results.json $benchJsonHash"
}
benchmark altInputSchema: '', altInputSchemaLocation: '', inputLocation: 'bench-results.json', schemaSelection: 'defaultSchema', truncateStrings: false
}*/
}
)
}
}}}
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,12 @@
"hash": "QmTbBs3Y3u5F69XNJzdnnc6SP5GKgcXxCDzx6w8m6piVRT",
"name": "go-bitfield",
"version": "0.1.1"
},
{
"author": "Magik6k",
"hash": "QmcpY7S3jQ47NhvLUQvSySpH5yPpYPpM6cfs9oGK6GkmW5",
"name": "tools",
"version": "1.0.3"
}
],
"gxVersion": "0.10.0",
Expand Down
3 changes: 3 additions & 0 deletions test/Rules.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
include mk/header.mk

dir := $(d)/bench
include $(dir)/Rules.mk

dir := $(d)/bin
include $(dir)/Rules.mk

Expand Down
2 changes: 2 additions & 0 deletions test/bench/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bench-results.json
gobench.out
12 changes: 12 additions & 0 deletions test/bench/Rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
include mk/header.mk

DEPS_$(d) := test/bin/gobench-to-json

$(d)/gobench.out:
go test -bench . -run '^Benchmark' ./... -benchmem | tee $(@D)/gobench.out
.PHONY: $(d)/gobench.out

$(d)/bench-results.json: $$(DEPS_$(d)) $(d)/gobench.out
cat $(@D)/gobench.out | test/bin/gobench-to-json $(@D)/bench-results.json

include mk/footer.mk
11 changes: 11 additions & 0 deletions test/bench/benchmark-plugin-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"description": "Schema for gobench-to-json output",
"type": "array",
"items": {
"type": "object",
"properties": {
"Name": { "type": "name" },
""
}
}
}
4 changes: 4 additions & 0 deletions test/bin/Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ $(d)/ma-pipe-unidir: test/dependencies/ma-pipe-unidir
$(go-build)
TGTS_$(d) += $(d)/ma-pipe-unidir

$(d)/gobench-to-json: test/dependencies/gobench-to-json
$(go-build)
TGTS_$(d) += $(d)/gobench-to-json

TGTS_GX_$(d) := hang-fds iptb
TGTS_GX_$(d) := $(addprefix $(d)/,$(TGTS_GX_$(d)))

Expand Down
131 changes: 131 additions & 0 deletions test/dependencies/gobench-to-json/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package main

import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"

"gx/ipfs/QmcpY7S3jQ47NhvLUQvSySpH5yPpYPpM6cfs9oGK6GkmW5/tools/benchmark/parse"
)

type Result struct {
Name string `json:"name"`
Description string `json:"description"`

Unit string `json:"unit"`
DblValue float64 `json:"dblValue"`
}

type Parameter struct {
Name string `json:"name"`
Description string `json:"description"`

Unit string `json:"unit"`
Value interface{} `json:"value"`
}

type Test struct {
Name string `json:"name"`
Description string `json:"description"`

Parameters []Parameter `json:"parameters,omitempty"`
Results []Result `json:"results,omitempty"`
}

type Group struct {
Name string `json:"name"`
Description string `json:"description"`

Tests []Test `json:"tests"`
}

type Out struct {
Groups []Group `json:"groups"`
}

func main() {
if err := mainErr(); err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(1)
}
}

func mainErr() error {
if len(os.Args) != 2 {
return errors.New("usage: gobench-to-json [outfile]")
}

benches, err := parse.ParseSet(os.Stdin)
if err != nil {
return err
}

tests := make([]Test, 0, len(benches))
for _, b := range benches {
for _, bench := range b {
results := make([]Result, 0, 4)

if bench.Measured&parse.NsPerOp != 0 {
results = append(results, Result{
Name: "time/op",
Description: "time per operation",
Unit: "ns",
DblValue: bench.NsPerOp,
})
}

if bench.Measured&parse.MBPerS != 0 {
results = append(results, Result{
Name: "throughput",
Description: "throughput",
Unit: "MB/s",
DblValue: bench.MBPerS,
})
}

if bench.Measured&parse.AllocsPerOp != 0 {
results = append(results, Result{
Name: "allocs/op",
Description: "number of allocations per operation",
Unit: "",
DblValue: float64(bench.AllocsPerOp), //TODO: figure out a better way
})
}

if bench.Measured&parse.AllocedBytesPerOp != 0 {
results = append(results, Result{
Name: "alloc B/op",
Description: "bytes allocated per operation",
Unit: "B",
DblValue: float64(bench.AllocedBytesPerOp), //TODO: figure out a better way
})
}

tests = append(tests, Test{
Name: bench.Name,

Results: results,
})
}
}

out := Out{
Groups: []Group{
{
Name: "Go benchmarks",
Description: "Go benchmarks",

Tests: tests,
},
},
}

b, err := json.Marshal(&out)
if err != nil {
return err
}

return ioutil.WriteFile(os.Args[1], b, 0664)
}

0 comments on commit be62eca

Please sign in to comment.