├── gopool ├── .gitignore ├── go.mod └── gopool_test.go ├── memmodel ├── .gitignore ├── hbsc.go ├── hbunordered.go ├── hbtso.go ├── hbacqrel.go └── sc.go ├── rtcheck ├── .gitignore ├── TODO.md └── static │ └── tmpl-order.html ├── gc-S └── go.mod ├── foreachplatform └── go.mod ├── srgb ├── gamma_colors.png └── main.go ├── abi ├── go.mod └── go.sum ├── stress2 ├── go.mod ├── signal_notunix.go ├── signal_unix.go ├── go.sum ├── cmd_test.go └── stress_test.go ├── pcvaluetab ├── go.mod ├── go.sum ├── dist.go ├── alt_test.go └── enc.go ├── git-p ├── go.mod ├── go.sum ├── style.go ├── shell.go └── pager.go ├── rtanalysis ├── main.go └── directives │ └── analysis.go ├── split ├── stub.s ├── bench_test.go ├── README.md └── example_rwmutex_test.go ├── benchplot ├── vendor │ ├── github.com │ │ └── aclements │ │ │ ├── go-gg │ │ │ ├── generic │ │ │ │ ├── doc.go │ │ │ │ ├── slice │ │ │ │ │ ├── doc.go │ │ │ │ │ ├── util_test.go │ │ │ │ │ ├── concat_test.go │ │ │ │ │ ├── seq.go │ │ │ │ │ ├── concat.go │ │ │ │ │ ├── convert_test.go │ │ │ │ │ ├── select_test.go │ │ │ │ │ ├── cycle.go │ │ │ │ │ ├── nub.go │ │ │ │ │ ├── find.go │ │ │ │ │ ├── convert.go │ │ │ │ │ ├── index.go │ │ │ │ │ ├── min_test.go │ │ │ │ │ └── min.go │ │ │ │ ├── error.go │ │ │ │ └── order.go │ │ │ ├── ggstat │ │ │ │ ├── common.go │ │ │ │ ├── lsquares.go │ │ │ │ └── loess.go │ │ │ ├── README.md │ │ │ ├── gg │ │ │ │ ├── stepmode_string.go │ │ │ │ ├── transform.go │ │ │ │ ├── text.go │ │ │ │ ├── example_scale_test.go │ │ │ │ ├── group.go │ │ │ │ ├── testmain.go │ │ │ │ └── layout │ │ │ │ │ └── layout.go │ │ │ ├── palette │ │ │ │ ├── srgb.go │ │ │ │ ├── brewer │ │ │ │ │ └── package.go │ │ │ │ ├── palette.go │ │ │ │ └── blend.go │ │ │ ├── LICENSE │ │ │ └── table │ │ │ │ ├── head.go │ │ │ │ ├── print_test.go │ │ │ │ ├── pivot_test.go │ │ │ │ ├── join.go │ │ │ │ ├── sort.go │ │ │ │ ├── concat.go │ │ │ │ └── filter.go │ │ │ └── go-moremath │ │ │ ├── fit │ │ │ ├── package.go │ │ │ └── loess_test.go │ │ │ ├── vec │ │ │ ├── package.go │ │ │ └── vec.go │ │ │ ├── README.md │ │ │ ├── scale │ │ │ ├── util.go │ │ │ ├── err.go │ │ │ ├── package.go │ │ │ ├── ticks_test.go │ │ │ └── interface.go │ │ │ ├── mathx │ │ │ ├── package.go │ │ │ ├── sign.go │ │ │ ├── beta_test.go │ │ │ ├── gamma_test.go │ │ │ ├── choose.go │ │ │ ├── gamma.go │ │ │ └── beta.go │ │ │ ├── stats │ │ │ ├── kdekernel_string.go │ │ │ ├── kdeboundarymethod_string.go │ │ │ ├── sample_test.go │ │ │ ├── locationhypothesis_string.go │ │ │ ├── hypergdist_test.go │ │ │ ├── package.go │ │ │ ├── normaldist_test.go │ │ │ ├── tdist.go │ │ │ ├── dist_test.go │ │ │ ├── linearhist.go │ │ │ ├── deltadist.go │ │ │ ├── util_test.go │ │ │ ├── hist.go │ │ │ ├── loghist.go │ │ │ ├── kde_test.go │ │ │ ├── ttest_test.go │ │ │ ├── utest_test.go │ │ │ ├── stream.go │ │ │ ├── alg.go │ │ │ └── hypergdist.go │ │ │ ├── LICENSE │ │ │ ├── internal │ │ │ └── mathtest │ │ │ │ └── mathtest.go │ │ │ └── cmd │ │ │ └── dist │ │ │ └── dist.go │ └── update └── kza_test.go ├── benchmany ├── signal_notunix.go └── signal_unix.go ├── internal └── loganal │ └── doc.go ├── benchcmd ├── rss_nounix.go ├── rss_unix.go └── main.go ├── varint ├── README.md └── varint.go ├── greplogs └── main.go ├── go-weave ├── weave │ ├── tls.go │ ├── waitgroup.go │ ├── atomic.go │ ├── trace.go │ ├── sema.go │ └── mutex.go ├── amb │ ├── rand.go │ ├── det.go │ └── progress.go └── models │ ├── issue16083.go │ ├── markterm.go │ └── cl20858.go ├── gover └── shutil.go ├── findflakes ├── xdg.go ├── paths.go ├── geodist.go └── text.go ├── dashquery ├── xdg.go └── compile_test.go ├── go.mod ├── LICENSE ├── minutes3 ├── go.mod └── README.md ├── benchscripts └── bench-many └── whichtest └── whichtest /gopool/.gitignore: -------------------------------------------------------------------------------- 1 | /gopool -------------------------------------------------------------------------------- /memmodel/.gitignore: -------------------------------------------------------------------------------- 1 | /memmodel 2 | /model.dot 3 | -------------------------------------------------------------------------------- /rtcheck/.gitignore: -------------------------------------------------------------------------------- 1 | /rtcheck 2 | /*.dot 3 | /*.svg 4 | -------------------------------------------------------------------------------- /gc-S/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/aclements/go-misc/gc-S 2 | 3 | go 1.20 4 | -------------------------------------------------------------------------------- /foreachplatform/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/aclements/go-misc/foreachplatform 2 | 3 | go 1.21 4 | -------------------------------------------------------------------------------- /srgb/gamma_colors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aclements/go-misc/HEAD/srgb/gamma_colors.png -------------------------------------------------------------------------------- /abi/go.mod: -------------------------------------------------------------------------------- 1 | module abi 2 | 3 | go 1.15 4 | 5 | require golang.org/x/tools v0.0.0-20200815165600-90abf76919f3 6 | -------------------------------------------------------------------------------- /gopool/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/aclements/go-misc/gopool 2 | 3 | go 1.15 4 | 5 | require golang.org/x/build v0.0.0-20201024042912-d43b1a58120a 6 | -------------------------------------------------------------------------------- /stress2/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/aclements/go-misc/stress2 2 | 3 | go 1.15 4 | 5 | require golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 6 | -------------------------------------------------------------------------------- /pcvaluetab/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/aclements/go-misc/pcvaluetab 2 | 3 | go 1.21 4 | 5 | require golang.org/x/exp v0.0.0-20230807204917-050eac23e9de 6 | -------------------------------------------------------------------------------- /git-p/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/aclements/go-misc/git-p 2 | 3 | go 1.17 4 | 5 | require golang.org/x/term v0.16.0 6 | 7 | require golang.org/x/sys v0.16.0 // indirect 8 | -------------------------------------------------------------------------------- /pcvaluetab/go.sum: -------------------------------------------------------------------------------- 1 | golang.org/x/exp v0.0.0-20230807204917-050eac23e9de h1:l5Za6utMv/HsBWWqzt4S8X17j+kt1uVETUX5UFhn2rE= 2 | golang.org/x/exp v0.0.0-20230807204917-050eac23e9de/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= 3 | -------------------------------------------------------------------------------- /rtanalysis/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/aclements/go-misc/rtanalysis/systemstack" 5 | "golang.org/x/tools/go/analysis/singlechecker" 6 | ) 7 | 8 | func main() { singlechecker.Main(systemstack.Analyzer) } 9 | -------------------------------------------------------------------------------- /split/stub.s: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Allow linkname-ing procPin and procUnpin. 6 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/generic/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package generic provides type-generic functions. 6 | package generic 7 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/generic/slice/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package slice provides generic slice functions. 6 | package slice 7 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/fit/package.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package fit provides functions for fitting models to data. 6 | package fit 7 | -------------------------------------------------------------------------------- /benchmany/signal_notunix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build plan9 windows 6 | 7 | package main 8 | 9 | import "os" 10 | 11 | var signalTrace os.Signal = nil 12 | -------------------------------------------------------------------------------- /internal/loganal/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package loganal contains functions for analyzing build and test 6 | // logs produced by all.bash. 7 | package loganal 8 | -------------------------------------------------------------------------------- /git-p/go.sum: -------------------------------------------------------------------------------- 1 | golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= 2 | golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 3 | golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE= 4 | golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= 5 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/vec/package.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package vec provides functions for float64 vectors. 6 | package vec // import "github.com/aclements/go-moremath/vec" 7 | -------------------------------------------------------------------------------- /benchmany/signal_unix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !plan9,!windows 6 | 7 | package main 8 | 9 | import ( 10 | "os" 11 | "syscall" 12 | ) 13 | 14 | var signalTrace os.Signal = syscall.SIGQUIT 15 | -------------------------------------------------------------------------------- /stress2/signal_notunix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build plan9 windows 6 | 7 | package main 8 | 9 | import "os" 10 | 11 | var exitSignals = []os.Signal{os.Interrupt} 12 | 13 | var traceSignal = nil 14 | -------------------------------------------------------------------------------- /benchcmd/rss_nounix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2025 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !unix 6 | 7 | package main 8 | 9 | import "os" 10 | 11 | func getMaxRSS(ps *os.ProcessState) (bytes uint64, ok bool) { 12 | return 0, false 13 | } 14 | -------------------------------------------------------------------------------- /rtcheck/TODO.md: -------------------------------------------------------------------------------- 1 | - Real CLI 2 | 3 | - Non-mutex locks 4 | 5 | - HTML reports 6 | 7 | - More roots 8 | 9 | - Find the bug that started this all 10 | 11 | - Copyright notices 12 | 13 | - Model m.locks and system stack 14 | 15 | - Model morestack 16 | 17 | 18 | - Predicate/delta caching 19 | 20 | - Show/link to code in HTML 21 | 22 | - Opt-in argument/return value tracking 23 | -------------------------------------------------------------------------------- /gopool/gopool_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | // TODO: Test reusing 8 | 9 | // TODO: Test setup command 10 | 11 | // TODO: Test killing client in the middle 12 | 13 | // TODO: Test client with failed commands 14 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/ggstat/common.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ggstat 6 | 7 | import "reflect" 8 | 9 | var float64Type = reflect.TypeOf(float64(0)) 10 | var float64SliceType = reflect.TypeOf([]float64(nil)) 11 | -------------------------------------------------------------------------------- /benchplot/vendor/update: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | mv github.com github.com.old || true 6 | 7 | mkdir -p github.com/aclements/go-gg 8 | git -C $GOPATH/src/github.com/aclements/go-gg archive HEAD | tar xC github.com/aclements/go-gg 9 | 10 | mkdir -p github.com/aclements/go-moremath 11 | git -C $GOPATH/src/github.com/aclements/go-moremath archive HEAD | tar xC github.com/aclements/go-moremath 12 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/README.md: -------------------------------------------------------------------------------- 1 | These packages provide more specialized math routines than are 2 | available in the standard Go math package. go-moremath currently 3 | focuses on statistical routines, with particular focus on high-quality 4 | implementations and APIs for non-parametric methods. 5 | 6 | The API is not stable. 7 | 8 | Please see the [documentation](https://godoc.org/github.com/aclements/go-moremath). 9 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/scale/util.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package scale 6 | 7 | // clamp clamps x to the range [0, 1]. 8 | func clamp(x float64) float64 { 9 | if x < 0 { 10 | return 0 11 | } 12 | if x > 1 { 13 | return 1 14 | } 15 | return x 16 | } 17 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/scale/err.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package scale 6 | 7 | // RangeErr is an error that indicates some argument or value is out 8 | // of range. 9 | type RangeErr string 10 | 11 | func (r RangeErr) Error() string { 12 | return string(r) 13 | } 14 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/README.md: -------------------------------------------------------------------------------- 1 | # gg [![](https://godoc.org/github.com/aclements/go-gg?status.svg)](https://godoc.org/github.com/aclements/go-gg) 2 | 3 | gg is a plotting package for Go inspired by the Grammar of Graphics. 4 | 5 | Note that gg is currently very experimental and the API is still in 6 | flux. Please vendor this package before using it. 7 | 8 | To fetch gg, run 9 | 10 | go get github.com/aclements/go-gg 11 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/mathx/package.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package mathx implements special functions not provided by the 6 | // standard math package. 7 | package mathx // import "github.com/aclements/go-moremath/mathx" 8 | 9 | import "math" 10 | 11 | var nan = math.NaN() 12 | -------------------------------------------------------------------------------- /memmodel/hbsc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | // HBSC is a HBGenerator that implements sequential consistency. 8 | type HBSC struct{} 9 | 10 | func (HBSC) HappensBefore(p *Prog, i, j PC) HBType { 11 | return HBHappensBefore 12 | } 13 | 14 | func (HBSC) String() string { 15 | return "SC" 16 | } 17 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/gg/stepmode_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type StepMode"; DO NOT EDIT 2 | 3 | package gg 4 | 5 | import "fmt" 6 | 7 | const _StepMode_name = "StepHVStepVHStepHMidStepVMid" 8 | 9 | var _StepMode_index = [...]uint8{0, 6, 12, 20, 28} 10 | 11 | func (i StepMode) String() string { 12 | if i < 0 || i >= StepMode(len(_StepMode_index)-1) { 13 | return fmt.Sprintf("StepMode(%d)", i) 14 | } 15 | return _StepMode_name[_StepMode_index[i]:_StepMode_index[i+1]] 16 | } 17 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/stats/kdekernel_string.go: -------------------------------------------------------------------------------- 1 | // generated by stringer -type=KDEKernel; DO NOT EDIT 2 | 3 | package stats 4 | 5 | import "fmt" 6 | 7 | const _KDEKernel_name = "GaussianKernelDeltaKernel" 8 | 9 | var _KDEKernel_index = [...]uint8{0, 14, 25} 10 | 11 | func (i KDEKernel) String() string { 12 | if i < 0 || i+1 >= KDEKernel(len(_KDEKernel_index)) { 13 | return fmt.Sprintf("KDEKernel(%d)", i) 14 | } 15 | return _KDEKernel_name[_KDEKernel_index[i]:_KDEKernel_index[i+1]] 16 | } 17 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/mathx/sign.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package mathx 6 | 7 | // Sign returns the sign of x: -1 if x < 0, 0 if x == 0, 1 if x > 0. 8 | // If x is NaN, it returns NaN. 9 | func Sign(x float64) float64 { 10 | if x == 0 { 11 | return 0 12 | } else if x < 0 { 13 | return -1 14 | } else if x > 0 { 15 | return 1 16 | } 17 | return nan 18 | } 19 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/generic/error.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package generic 6 | 7 | import "reflect" 8 | 9 | type TypeError struct { 10 | Type1, Type2 reflect.Type 11 | Extra string 12 | } 13 | 14 | func (e TypeError) Error() string { 15 | msg := e.Type1.String() 16 | if e.Type2 != nil { 17 | msg += " and " + e.Type2.String() 18 | } 19 | msg += " " + e.Extra 20 | return msg 21 | } 22 | -------------------------------------------------------------------------------- /varint/README.md: -------------------------------------------------------------------------------- 1 | This directory contains experiments with varint decoding using 2 | hand-coded assembly. 3 | 4 | The simple assembly loop is 15–30% faster than the Go loop. The loop 5 | is somewhat clever, but in principle the compiler could probably 6 | produce this code. 7 | 8 | Most of the code experiments with BMI2 instructions. This requires 9 | Haswell or newer, which the benchmark will detect. This approach is 10 | constant time up to 8 byte varints (56 bit values). It's 50% faster 11 | than the Go code for 8 byte varints, but 80% slower for one byte 12 | varints. 13 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/scale/package.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package scale provides abstractions for scales that map from one 6 | // domain to another and provide methods for indicating human-readable 7 | // intervals in the input domain. The most common type of scale is a 8 | // quantitative scale, such as a linear or log scale, which is 9 | // captured by the Quantitative interface. 10 | package scale 11 | -------------------------------------------------------------------------------- /greplogs/main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Command greplogs is deprecated. 6 | // 7 | // Please see golang.org/x/build/cmd/greplogs. 8 | package main 9 | 10 | import ( 11 | "fmt" 12 | "os" 13 | ) 14 | 15 | func main() { 16 | fmt.Fprintf(os.Stderr, "This copy of greplogs is deprecated. Please update your greplogs using:\n") 17 | fmt.Fprintf(os.Stderr, "\tgo install golang.org/x/build/cmd/greplogs@latest\n") 18 | os.Exit(2) 19 | } 20 | -------------------------------------------------------------------------------- /stress2/signal_unix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build aix darwin dragonfly freebsd js linux netbsd openbsd solaris 6 | 7 | package main 8 | 9 | import ( 10 | "os" 11 | "syscall" 12 | ) 13 | 14 | var exitSignals = []os.Signal{syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM} 15 | 16 | // traceSignal is the signal to send a Go program to make it crash 17 | // with a stack trace. 18 | var traceSignal = syscall.SIGQUIT 19 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/stats/kdeboundarymethod_string.go: -------------------------------------------------------------------------------- 1 | // generated by stringer -type=KDEBoundaryMethod; DO NOT EDIT 2 | 3 | package stats 4 | 5 | import "fmt" 6 | 7 | const _KDEBoundaryMethod_name = "BoundaryReflect" 8 | 9 | var _KDEBoundaryMethod_index = [...]uint8{0, 15} 10 | 11 | func (i KDEBoundaryMethod) String() string { 12 | if i < 0 || i+1 >= KDEBoundaryMethod(len(_KDEBoundaryMethod_index)) { 13 | return fmt.Sprintf("KDEBoundaryMethod(%d)", i) 14 | } 15 | return _KDEBoundaryMethod_name[_KDEBoundaryMethod_index[i]:_KDEBoundaryMethod_index[i+1]] 16 | } 17 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/stats/sample_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package stats 6 | 7 | import "testing" 8 | 9 | func TestSampleQuantile(t *testing.T) { 10 | s := Sample{Xs: []float64{15, 20, 35, 40, 50}} 11 | testFunc(t, "Quantile", s.Quantile, map[float64]float64{ 12 | -1: 15, 13 | 0: 15, 14 | .05: 15, 15 | .30: 19.666666666666666, 16 | .40: 27, 17 | .95: 50, 18 | 1: 50, 19 | 2: 50, 20 | }) 21 | } 22 | -------------------------------------------------------------------------------- /go-weave/weave/tls.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package weave 6 | 7 | type TLS struct { 8 | _ byte 9 | } 10 | 11 | func NewTLS() *TLS { 12 | return &TLS{} 13 | } 14 | 15 | func (v *TLS) Get() interface{} { 16 | return globalSched.curThread.tls[v] 17 | } 18 | 19 | func (v *TLS) Set(val interface{}) { 20 | m := globalSched.curThread.tls 21 | if m == nil { 22 | m = make(map[*TLS]interface{}) 23 | globalSched.curThread.tls = m 24 | } 25 | m[v] = val 26 | } 27 | -------------------------------------------------------------------------------- /gover/shutil.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import "strings" 8 | 9 | func shellEscape(x string) string { 10 | if len(x) == 0 { 11 | return "''" 12 | } 13 | for _, r := range x { 14 | if 'a' <= r && r <= 'z' || 'A' <= r && r <= 'Z' || '0' <= r && r <= '9' || strings.ContainsRune("@%_-+:,./", r) { 15 | continue 16 | } 17 | // Unsafe character. 18 | return "'" + strings.Replace(x, "'", "'\"'\"'", -1) + "'" 19 | } 20 | return x 21 | 22 | } 23 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/stats/locationhypothesis_string.go: -------------------------------------------------------------------------------- 1 | // generated by stringer -type LocationHypothesis; DO NOT EDIT 2 | 3 | package stats 4 | 5 | import "fmt" 6 | 7 | const _LocationHypothesis_name = "LocationLessLocationDiffersLocationGreater" 8 | 9 | var _LocationHypothesis_index = [...]uint8{0, 12, 27, 42} 10 | 11 | func (i LocationHypothesis) String() string { 12 | i -= -1 13 | if i < 0 || i+1 >= LocationHypothesis(len(_LocationHypothesis_index)) { 14 | return fmt.Sprintf("LocationHypothesis(%d)", i+-1) 15 | } 16 | return _LocationHypothesis_name[_LocationHypothesis_index[i]:_LocationHypothesis_index[i+1]] 17 | } 18 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/palette/srgb.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package palette 6 | 7 | //go:generate go run makesrgbtab.go 8 | 9 | // sRGB8ToLinear converts 8-bit sRGB component x to a 16-bit linear 10 | // intensity. 11 | func sRGB8ToLinear(x uint8) uint16 { 12 | return sRGBToLinearTab[x] 13 | } 14 | 15 | // linearTosRGB8 converts 16-bit linear intensity x to an 8-bit sRGB 16 | // component. 17 | func linearTosRGB8(x uint16) uint8 { 18 | return linearTosRGBTab[(uint32(x)+linearTosRGBAddend)>>linearTosRGBShift] 19 | } 20 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/stats/hypergdist_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package stats 6 | 7 | import ( 8 | "fmt" 9 | "testing" 10 | ) 11 | 12 | func TestHypergeometricDist(t *testing.T) { 13 | dist1 := HypergeometicDist{N: 50, K: 5, Draws: 10} 14 | testFunc(t, fmt.Sprintf("%+v.PMF", dist1), dist1.PMF, 15 | map[float64]float64{ 16 | -0.1: 0, 17 | 4: 0.003964583058, 18 | 4.9: 0.003964583058, // Test rounding 19 | 5: 0.000118937492, 20 | 5.9: 0.000118937492, 21 | 6: 0, 22 | }) 23 | testDiscreteCDF(t, fmt.Sprintf("%+v.CDF", dist1), dist1) 24 | } 25 | -------------------------------------------------------------------------------- /git-p/style.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | var style = map[string]string{ 8 | "reset": "\x1b[0m", 9 | 10 | "branch": "\x1b[1;32m", // Bright green 11 | "symbolic-ref": "\x1b[1;36m", // Bright cyan 12 | 13 | // CL status styles 14 | 15 | "Not mailed": "\x1b[35m", // Magenta 16 | 17 | "Pending warn": "\x1b[33m", // Yellow 18 | "Ready warn": "\x1b[33m", // Yellow 19 | "Rejected warn": "\x1b[1;31m", // Bright red 20 | 21 | "Ready": "\x1b[32m", // Green 22 | 23 | "Submitted": "\x1b[37m", // Gray 24 | "Abandoned": "\x1b[9;37m", // Gray, strike-through 25 | "Draft": "\x1b[37m", // Gray 26 | } 27 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/generic/slice/util_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package slice 6 | 7 | import ( 8 | "fmt" 9 | "reflect" 10 | "regexp" 11 | "testing" 12 | ) 13 | 14 | func de(x, y interface{}) bool { 15 | return reflect.DeepEqual(x, y) 16 | } 17 | 18 | func shouldPanic(t *testing.T, re string, f func()) { 19 | r := regexp.MustCompile(re) 20 | defer func() { 21 | err := recover() 22 | if err == nil { 23 | t.Fatalf("want panic matching %q; got no panic", re) 24 | } else if !r.MatchString(fmt.Sprintf("%s", err)) { 25 | t.Fatalf("want panic matching %q; got %s", re, err) 26 | } 27 | }() 28 | f() 29 | } 30 | -------------------------------------------------------------------------------- /memmodel/hbunordered.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | // HBUnordered is an HBGenerator that implements fully relaxed memory 8 | // order where the *only* order observed is local program order. This 9 | // corresponds to how programming languages typically specify 10 | // non-atomic loads and stores, which is even weaker than typical 11 | // hardware RMO because loads aren't coherent (loads of the same 12 | // location may be reordered). 13 | type HBUnordered struct{} 14 | 15 | func (HBUnordered) HappensBefore(p *Prog, i, j PC) HBType { 16 | return HBConcurrent 17 | } 18 | 19 | func (HBUnordered) String() string { 20 | return "Unordered" 21 | } 22 | -------------------------------------------------------------------------------- /stress2/go.sum: -------------------------------------------------------------------------------- 1 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 2 | golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 h1:cg5LA/zNPRzIXIWSCxQW10Rvpy94aQh3LT/ShoCpkHw= 3 | golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 4 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 5 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 6 | golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= 7 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 8 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 9 | -------------------------------------------------------------------------------- /go-weave/weave/waitgroup.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package weave 6 | 7 | type WaitGroup struct { 8 | n int 9 | waiters []*thread 10 | } 11 | 12 | func (g *WaitGroup) Add(delta int) { 13 | g.n += delta 14 | if g.n == 0 { 15 | waiters := g.waiters 16 | g.waiters = nil 17 | for _, t := range waiters { 18 | t.unblock() 19 | } 20 | } 21 | } 22 | 23 | func (g *WaitGroup) Done() { 24 | g.Add(-1) 25 | } 26 | 27 | func (g *WaitGroup) Wait() { 28 | if g.n == 0 { 29 | globalSched.Sched() 30 | return 31 | } 32 | this := globalSched.curThread 33 | g.waiters = append(g.waiters, this) 34 | this.block(g.reset) 35 | } 36 | 37 | func (g *WaitGroup) reset() { 38 | *g = WaitGroup{} 39 | } 40 | -------------------------------------------------------------------------------- /benchcmd/rss_unix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2025 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build unix 6 | 7 | package main 8 | 9 | import ( 10 | "os" 11 | "runtime" 12 | "syscall" 13 | ) 14 | 15 | func getMaxRSS(ps *os.ProcessState) (bytes uint64, ok bool) { 16 | ru, ok := ps.SysUsage().(*syscall.Rusage) 17 | if !ok { 18 | return 0, false 19 | } 20 | 21 | var rssToBytes uint64 22 | switch runtime.GOOS { 23 | default: 24 | return 0, false 25 | case "aix", "android", "dragonfly", "freebsd", "linux", "netbsd", "openbsd": 26 | rssToBytes = 1 << 10 27 | case "darwin", "ios": 28 | rssToBytes = 1 29 | case "illumos", "solaris": 30 | rssToBytes = uint64(syscall.Getpagesize()) 31 | } 32 | return uint64(ru.Maxrss) * rssToBytes, true 33 | } 34 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/stats/package.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package stats implements several statistical distributions, 6 | // hypothesis tests, and functions for descriptive statistics. 7 | // 8 | // Currently stats is fairly small, but for what it does implement, it 9 | // focuses on high quality, fast implementations with good, idiomatic 10 | // Go APIs. 11 | package stats // import "github.com/aclements/go-moremath/stats" 12 | 13 | import ( 14 | "errors" 15 | "math" 16 | ) 17 | 18 | var inf = math.Inf(1) 19 | var nan = math.NaN() 20 | 21 | // TODO: Put all errors in the same place and maybe unify them. 22 | 23 | var ( 24 | ErrSamplesEqual = errors.New("all samples are equal") 25 | ) 26 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/generic/slice/concat_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package slice 6 | 7 | import "testing" 8 | 9 | func TestConcat(t *testing.T) { 10 | if g := Concat(); g != nil { 11 | t.Errorf("Concat() should be nil; got %v", g) 12 | } 13 | 14 | if g, w := Concat([]int{}), []int{}; !de(w, g) { 15 | t.Errorf("want %v; got %v", w, g) 16 | } 17 | 18 | if g, w := Concat([]int(nil)), []int{}; !de(w, g) { 19 | t.Errorf("want %v; got %v", w, g) 20 | } 21 | 22 | if g, w := Concat([]int{1, 2}, []int{3, 4}), []int{1, 2, 3, 4}; !de(w, g) { 23 | t.Errorf("want %v; got %v", w, g) 24 | } 25 | 26 | shouldPanic(t, "have different types", func() { 27 | Concat([]int{}, []string{}) 28 | }) 29 | } 30 | -------------------------------------------------------------------------------- /stress2/cmd_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import "testing" 8 | 9 | func TestStdoutExitRace(t *testing.T) { 10 | // The stdout pipe is asynchronous with exiting, so even if a 11 | // child cleanly writes to stdout, then exits, wait may return 12 | // before we're done reading from the pipe. Check that we 13 | // handle this correctly. 14 | 15 | for i := 0; i < 1000; i++ { 16 | cmd, err := StartCommand([]string{"/bin/echo", "hi"}) 17 | if err != nil { 18 | t.Fatal(err) 19 | } 20 | <-cmd.Done() 21 | if !cmd.Status.Success() { 22 | t.Fatal("command failed: ", cmd.Status) 23 | } 24 | if got, want := string(cmd.Output), "hi\n"; got != want { 25 | t.Errorf("got %q, want %q", got, want) 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/mathx/beta_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package mathx 6 | 7 | import ( 8 | "testing" 9 | 10 | . "github.com/aclements/go-moremath/internal/mathtest" 11 | ) 12 | 13 | func TestBetaInc(t *testing.T) { 14 | // Example values from MATLAB betainc documentation. 15 | WantFunc(t, "I_0.5(%v, 3)", 16 | func(a float64) float64 { return BetaInc(0.5, a, 3) }, 17 | map[float64]float64{ 18 | 0: 1.00000000000000, 19 | 1: 0.87500000000000, 20 | 2: 0.68750000000000, 21 | 3: 0.50000000000000, 22 | 4: 0.34375000000000, 23 | 5: 0.22656250000000, 24 | 6: 0.14453125000000, 25 | 7: 0.08984375000000, 26 | 8: 0.05468750000000, 27 | 9: 0.03271484375000, 28 | 10: 0.01928710937500}) 29 | } 30 | -------------------------------------------------------------------------------- /git-p/shell.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import "strings" 8 | 9 | // shellEscape escapes a single shell token. 10 | func shellEscape(x string) string { 11 | if len(x) == 0 { 12 | return "''" 13 | } 14 | for _, r := range x { 15 | if 'a' <= r && r <= 'z' || 'A' <= r && r <= 'Z' || '0' <= r && r <= '9' || strings.ContainsRune("@%_-+:,./", r) { 16 | continue 17 | } 18 | // Unsafe character. 19 | return "'" + strings.Replace(x, "'", "'\"'\"'", -1) + "'" 20 | } 21 | return x 22 | } 23 | 24 | // shellEscapeList escapes a list of shell tokens. 25 | func shellEscapeList(xs []string) string { 26 | out := make([]string, len(xs)) 27 | for i, x := range xs { 28 | out[i] = shellEscape(x) 29 | } 30 | return strings.Join(out, " ") 31 | } 32 | -------------------------------------------------------------------------------- /go-weave/weave/atomic.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package weave 6 | 7 | type AtomicInt32 struct { 8 | v int32 9 | } 10 | 11 | func (a *AtomicInt32) Add(delta int32) (new int32) { 12 | a.v += delta 13 | new = a.v 14 | globalSched.Sched() 15 | return new 16 | } 17 | 18 | func (a *AtomicInt32) CompareAndSwap(old, new int32) (swapped bool) { 19 | swapped = a.v == old 20 | if swapped { 21 | a.v = new 22 | } 23 | globalSched.Sched() 24 | return 25 | } 26 | 27 | func (a *AtomicInt32) Load() int32 { 28 | v := a.v 29 | globalSched.Sched() 30 | return v 31 | } 32 | 33 | func (a *AtomicInt32) Store(val int32) { 34 | a.v = val 35 | globalSched.Sched() 36 | } 37 | 38 | func (a *AtomicInt32) Swap(new int32) (old int32) { 39 | old, a.v = a.v, new 40 | globalSched.Sched() 41 | return 42 | } 43 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/gg/transform.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package gg 6 | 7 | import "github.com/aclements/go-gg/table" 8 | 9 | // SortBy sorts each group by the named columns. If a column's type 10 | // implements sort.Interface, rows will be sorted according to that 11 | // order. Otherwise, the values in the column must be naturally 12 | // ordered (their types must be orderable by the Go specification). If 13 | // neither is true, SortBy panics with a *generic.TypeError. If more 14 | // than one column is given, SortBy sorts by the tuple of the columns; 15 | // that is, if two values in the first column are equal, they are 16 | // sorted by the second column, and so on. 17 | func (p *Plot) SortBy(cols ...string) *Plot { 18 | return p.SetData(table.SortBy(p.Data(), cols...)) 19 | } 20 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/stats/normaldist_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package stats 6 | 7 | import ( 8 | "fmt" 9 | "math" 10 | "testing" 11 | ) 12 | 13 | func TestNormalDist(t *testing.T) { 14 | d := StdNormal 15 | 16 | testFunc(t, fmt.Sprintf("%+v.PDF", d), d.PDF, map[float64]float64{ 17 | -10000: 0, // approx 18 | -1: 1 / math.Sqrt(2*math.Pi) * math.Exp(-0.5), 19 | 0: 1 / math.Sqrt(2*math.Pi), 20 | 1: 1 / math.Sqrt(2*math.Pi) * math.Exp(-0.5), 21 | 10000: 0, // approx 22 | }) 23 | 24 | testFunc(t, fmt.Sprintf("%+v.CDF", d), d.CDF, map[float64]float64{ 25 | -10000: 0, // approx 26 | 0: 0.5, 27 | 10000: 1, // approx 28 | }) 29 | 30 | d2 := NormalDist{Mu: 2, Sigma: 5} 31 | testInvCDF(t, d, false) 32 | testInvCDF(t, d2, false) 33 | } 34 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/generic/slice/seq.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package slice 6 | 7 | import ( 8 | "reflect" 9 | 10 | "github.com/aclements/go-gg/generic" 11 | ) 12 | 13 | // T is a Go slice value of type []U. 14 | // 15 | // This is primarily for documentation. There is no way to statically 16 | // enforce this in Go; however, functions that expect a slice will 17 | // panic with a *generic.TypeError if passed a non-slice value. 18 | type T interface{} 19 | 20 | // reflectSlice checks that s is a slice and returns its 21 | // reflect.Value. It panics with a *generic.TypeError if s is not a slice. 22 | func reflectSlice(s T) reflect.Value { 23 | rv := reflect.ValueOf(s) 24 | if rv.Kind() != reflect.Slice { 25 | panic(&generic.TypeError{rv.Type(), nil, "is not a slice"}) 26 | } 27 | return rv 28 | } 29 | -------------------------------------------------------------------------------- /stress2/stress_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "strings" 9 | "testing" 10 | ) 11 | 12 | func TestPrintTail(t *testing.T) { 13 | check := func(t *testing.T, data, want string) { 14 | t.Helper() 15 | var got strings.Builder 16 | printTail(&got, []byte(data)) 17 | if got.String() != want { 18 | t.Errorf("for:\n%s\ngot:\n%s\nwant:\n%s", data, got.String(), want) 19 | } 20 | } 21 | 22 | // Basic 23 | check(t, "", "") 24 | check(t, "a", "a\n") 25 | check(t, "a\nb\n", "a\nb\n") 26 | // Line trimming 27 | a20 := strings.Repeat("a\n", 20) 28 | check(t, a20, strings.Repeat("a\n", 10)) 29 | check(t, a20[:len(a20)-1], strings.Repeat("a\n", 10)) 30 | // Test rune limits. 31 | long := strings.Repeat("a", 2000) + "\n" 32 | check(t, long, "") 33 | long += "x\n" 34 | check(t, long, "x\n") 35 | } 36 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/gg/text.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package gg 6 | 7 | import "unicode/utf8" 8 | 9 | type textMetrics struct { 10 | width float64 11 | leading float64 12 | } 13 | 14 | // measureString returns the metrics in pixels of s rendered in a font 15 | // with pixel size pxSize. 16 | // 17 | // TODO: Often all I want is the leading, which is much cheaper to get 18 | // than the width. Maybe textMetrics should have methods? 19 | func measureString(pxSize float64, s string) textMetrics { 20 | // TODO: This is absolutely horribly awful. Make it real, 21 | // perhaps using the freetype package. 22 | 23 | // Chrome's default font-size is 16px, so 20px is a reasonable 24 | // leading. 25 | return textMetrics{ 26 | width: 0.5 * pxSize * float64(utf8.RuneCountInString(s)), 27 | leading: 1.25 * pxSize, 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /pcvaluetab/dist.go: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "fmt" 9 | "sort" 10 | "strings" 11 | ) 12 | 13 | type Dist struct { 14 | vals []int 15 | sorted bool 16 | } 17 | 18 | func (d *Dist) Add(val int) { 19 | d.vals = append(d.vals, val) 20 | d.sorted = false 21 | } 22 | 23 | func (d *Dist) Quantile(q float64) int { 24 | if !d.sorted { 25 | sort.Ints(d.vals) 26 | } 27 | i := int((q * float64(len(d.vals)-1)) + 0.5) 28 | return d.vals[i] 29 | } 30 | 31 | func (d *Dist) StringSummary() string { 32 | const qs = 10 33 | var out strings.Builder 34 | for i := 0; i <= qs; i++ { 35 | fmt.Fprintf(&out, " %7s", fmt.Sprintf("p%d", i*100/qs)) 36 | } 37 | out.WriteByte('\n') 38 | for i := 0; i <= qs; i++ { 39 | v := d.Quantile(float64(i) / qs) 40 | fmt.Fprintf(&out, " %7d", v) 41 | } 42 | fmt.Fprintf(&out, " N=%d", len(d.vals)) 43 | return out.String() 44 | } 45 | -------------------------------------------------------------------------------- /srgb/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "image" 7 | "image/png" 8 | "log" 9 | "os" 10 | 11 | "golang.org/x/image/draw" 12 | ) 13 | 14 | func main() { 15 | var err error 16 | 17 | flag.Usage = func() { 18 | fmt.Fprintf(os.Stderr, "Usage: %s input output\n", os.Args[0]) 19 | } 20 | flag.Parse() 21 | if flag.NArg() != 2 { 22 | flag.Usage() 23 | os.Exit(2) 24 | } 25 | 26 | // Read input file. 27 | f, err := os.Open(os.Args[1]) 28 | if err != nil { 29 | log.Fatal(err) 30 | } 31 | defer f.Close() 32 | src, _, err := image.Decode(f) 33 | if err != nil { 34 | log.Fatal(err) 35 | } 36 | 37 | // Scale down by a factor of 2. 38 | sb := src.Bounds() 39 | dst := image.NewRGBA(image.Rect(0, 0, sb.Dx()/2, sb.Dy()/2)) 40 | draw.BiLinear.Scale(dst, dst.Bounds(), src, sb, draw.Over, nil) 41 | 42 | // Write output file. 43 | if f, err = os.Create(os.Args[2]); err != nil { 44 | log.Fatal(err) 45 | } 46 | defer f.Close() 47 | if err := png.Encode(f, dst); err != nil { 48 | log.Fatal(err) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /findflakes/xdg.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "os" 9 | "os/user" 10 | "path/filepath" 11 | "runtime" 12 | ) 13 | 14 | // xdgCacheDir returns the XDG Base Directory Specification cache 15 | // directory. 16 | func xdgCacheDir() string { 17 | cache := os.Getenv("XDG_CACHE_HOME") 18 | if cache == "" { 19 | home := os.Getenv("HOME") 20 | if home == "" { 21 | u, err := user.Current() 22 | if err != nil { 23 | home = u.HomeDir 24 | } 25 | } 26 | // Not XDG but standard for OS X. 27 | if runtime.GOOS == "darwin" { 28 | return filepath.Join(home, "Library/Caches") 29 | } 30 | cache = filepath.Join(home, ".cache") 31 | } 32 | return cache 33 | } 34 | 35 | // xdgCreateDir creates a directory and its parents in accordance with 36 | // the XDG Base Directory Specification. 37 | func xdgCreateDir(path string) error { 38 | return os.MkdirAll(path, 0700) 39 | } 40 | -------------------------------------------------------------------------------- /go-weave/weave/trace.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package weave 6 | 7 | import ( 8 | "bytes" 9 | "fmt" 10 | ) 11 | 12 | type traceEntry struct { 13 | tid int 14 | msg string 15 | } 16 | 17 | func (s *Scheduler) Trace(msg string) { 18 | s.trace = append(s.trace, traceEntry{s.curThread.id, msg}) 19 | } 20 | 21 | func (s *Scheduler) Tracef(msg string, args ...interface{}) { 22 | s.trace = append(s.trace, traceEntry{s.curThread.id, fmt.Sprintf(msg, args...)}) 23 | } 24 | 25 | type errorWithTrace struct { 26 | err interface{} 27 | trace []traceEntry 28 | } 29 | 30 | func (e errorWithTrace) Error() string { 31 | if len(e.trace) == 0 { 32 | return fmt.Sprint(e.err) 33 | } 34 | 35 | var buf bytes.Buffer 36 | fmt.Fprintf(&buf, "%v\n", e.err) 37 | fmt.Fprintf(&buf, "trace:") 38 | for _, ent := range e.trace { 39 | fmt.Fprintf(&buf, "\n T%d %s", ent.tid, ent.msg) 40 | } 41 | return buf.String() 42 | } 43 | -------------------------------------------------------------------------------- /dashquery/xdg.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package dashquery 6 | 7 | import ( 8 | "os" 9 | "os/user" 10 | "path/filepath" 11 | "runtime" 12 | ) 13 | 14 | // xdgCacheDir returns the XDG Base Directory Specification cache 15 | // directory. 16 | func xdgCacheDir() string { 17 | cache := os.Getenv("XDG_CACHE_HOME") 18 | if cache == "" { 19 | home := os.Getenv("HOME") 20 | if home == "" { 21 | u, err := user.Current() 22 | if err != nil { 23 | home = u.HomeDir 24 | } 25 | } 26 | // Not XDG but standard for OS X. 27 | if runtime.GOOS == "darwin" { 28 | return filepath.Join(home, "Library/Caches") 29 | } 30 | cache = filepath.Join(home, ".cache") 31 | } 32 | return cache 33 | } 34 | 35 | // xdgCreateDir creates a directory and its parents in accordance with 36 | // the XDG Base Directory Specification. 37 | func xdgCreateDir(path string) error { 38 | return os.MkdirAll(path, 0700) 39 | } 40 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/stats/tdist.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package stats 6 | 7 | import ( 8 | "math" 9 | 10 | "github.com/aclements/go-moremath/mathx" 11 | ) 12 | 13 | // A TDist is a Student's t-distribution with V degrees of freedom. 14 | type TDist struct { 15 | V float64 16 | } 17 | 18 | func lgamma(x float64) float64 { 19 | y, _ := math.Lgamma(x) 20 | return y 21 | } 22 | 23 | func (t TDist) PDF(x float64) float64 { 24 | return math.Exp(lgamma((t.V+1)/2)-lgamma(t.V/2)) / 25 | math.Sqrt(t.V*math.Pi) * math.Pow(1+(x*x)/t.V, -(t.V+1)/2) 26 | } 27 | 28 | func (t TDist) CDF(x float64) float64 { 29 | if x == 0 { 30 | return 0.5 31 | } else if x > 0 { 32 | return 1 - 0.5*mathx.BetaInc(t.V/(t.V+x*x), t.V/2, 0.5) 33 | } else if x < 0 { 34 | return 1 - t.CDF(-x) 35 | } else { 36 | return math.NaN() 37 | } 38 | } 39 | 40 | func (t TDist) Bounds() (float64, float64) { 41 | return -4, 4 42 | } 43 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/aclements/go-misc 2 | 3 | go 1.17 4 | 5 | require ( 6 | github.com/aclements/go-gg v0.0.0-20170323211221-abd1f791f5ee 7 | github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794 8 | golang.org/x/build v0.0.0-20210804225706-d1bc548deb19 9 | golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 10 | golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d 11 | golang.org/x/tools v0.1.5 12 | ) 13 | 14 | require ( 15 | github.com/ajstarks/svgo v0.0.0-20210406150507-75cfd577ce75 // indirect 16 | github.com/gonum/blas v0.0.0-20181208220705-f22b278b28ac // indirect 17 | github.com/gonum/floats v0.0.0-20181209220543-c233463c7e82 // indirect 18 | github.com/gonum/internal v0.0.0-20181124074243-f884aa714029 // indirect 19 | github.com/gonum/lapack v0.0.0-20181123203213-e4cdc5a0bff9 // indirect 20 | github.com/gonum/matrix v0.0.0-20181209220409-c518dec07be9 // indirect 21 | golang.org/x/mod v0.4.2 // indirect 22 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect 23 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect 24 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect 25 | ) 26 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/stats/dist_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package stats 6 | 7 | import ( 8 | "fmt" 9 | "testing" 10 | ) 11 | 12 | type funnyCDF struct { 13 | left float64 14 | } 15 | 16 | func (f funnyCDF) CDF(x float64) float64 { 17 | switch { 18 | case x < f.left: 19 | return 0 20 | case x < f.left+1: 21 | return (x - f.left) / 2 22 | case x < f.left+2: 23 | return 0.5 24 | case x < f.left+3: 25 | return (x-f.left-2)/2 + 0.5 26 | default: 27 | return 1 28 | } 29 | } 30 | 31 | func (f funnyCDF) Bounds() (float64, float64) { 32 | return f.left, f.left + 3 33 | } 34 | 35 | func TestInvCDF(t *testing.T) { 36 | for _, f := range []funnyCDF{funnyCDF{1}, funnyCDF{-1.5}, funnyCDF{-4}} { 37 | testFunc(t, fmt.Sprintf("InvCDF(funnyCDF%+v)", f), InvCDF(f), 38 | map[float64]float64{ 39 | -0.1: nan, 40 | 0: f.left, 41 | 0.25: f.left + 0.5, 42 | 0.5: f.left + 1, 43 | 0.75: f.left + 2.5, 44 | 1: f.left + 3, 45 | 1.1: nan, 46 | }) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /go-weave/weave/sema.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package weave 6 | 7 | // Semaphore is a FIFO counted semaphore. 8 | type Semaphore struct { 9 | avail int 10 | wait *semwait 11 | waitEnd *semwait 12 | } 13 | 14 | type semwait struct { 15 | n int 16 | thr *thread 17 | next *semwait 18 | } 19 | 20 | func (s *Semaphore) Acquire(n int) { 21 | if s.avail >= n { 22 | s.avail -= n 23 | return 24 | } 25 | this := globalSched.curThread 26 | w := &semwait{n, this, nil} 27 | if s.waitEnd != nil { 28 | s.waitEnd.next = w 29 | } else { 30 | s.wait = w 31 | } 32 | s.waitEnd = w 33 | this.block(s.reset) 34 | } 35 | 36 | func (s *Semaphore) Release(n int) { 37 | s.avail += n 38 | any := false 39 | for s.wait != nil && s.avail >= s.wait.n { 40 | any = true 41 | w := s.wait 42 | s.wait = w.next 43 | if s.wait == nil { 44 | s.waitEnd = nil 45 | } 46 | s.avail -= w.n 47 | w.thr.unblock() 48 | } 49 | if any { 50 | globalSched.Sched() 51 | } 52 | } 53 | 54 | func (s *Semaphore) reset() { 55 | *s = Semaphore{} 56 | } 57 | -------------------------------------------------------------------------------- /memmodel/hbtso.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | // HBTSO is an HBGenerator that implements TSO. 8 | type HBTSO struct{} 9 | 10 | func (HBTSO) HappensBefore(p *Prog, i, j PC) HBType { 11 | op1, op2 := p.OpAt(i), p.OpAt(j) 12 | sameThread := i.TID == j.TID 13 | 14 | switch { 15 | case op1.Type == OpStore && op2.Type == OpStore: 16 | // Stores are totally ordered. 17 | return HBHappensBefore 18 | 19 | case sameThread && op1.Type == OpLoad && op2.Type == OpLoad: 20 | // Loads are program ordered. 21 | return HBHappensBefore 22 | 23 | case sameThread && op1.Type == OpLoad && op2.Type == OpStore: 24 | // Loads are program ordered before stores. (But *not* 25 | // the other way around.) 26 | return HBHappensBefore 27 | 28 | case op1.Type == OpStore && op2.Type == OpLoad && op1.Var == op2.Var: 29 | // If the load observes the store, then the store 30 | // happened before the load. 31 | return HBConditional 32 | } 33 | 34 | return HBConcurrent 35 | } 36 | 37 | func (HBTSO) String() string { 38 | return "TSO" 39 | } 40 | -------------------------------------------------------------------------------- /dashquery/compile_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package dashquery 6 | 7 | import "testing" 8 | 9 | func TestEval(t *testing.T) { 10 | try := func(expr string, want bool) { 11 | t.Helper() 12 | q, err := Compile(expr) 13 | if err != nil { 14 | t.Errorf("%s: unexpected compile error %s", expr, err) 15 | return 16 | } 17 | if have := q.fn(pathInfo{}); have != want { 18 | t.Errorf("%s: want %v, have %v", expr, want, have) 19 | } 20 | } 21 | 22 | try(`true`, true) 23 | try(`false`, false) 24 | try(`1 == 1`, true) 25 | try(`1 == 2`, false) 26 | try(`"a" == "a"`, true) 27 | try(`"a" == "b"`, false) 28 | try(`1+1 == 2`, true) 29 | try(`"a"+"b" == "ab"`, true) 30 | try(`1-1 == 0`, true) 31 | try(`1==1 && 2==2`, true) 32 | try(`1==1 && 2==3`, false) 33 | try(`1==1 || 2==2`, true) 34 | try(`1==2 || 1==2`, false) 35 | try(`1 < 2`, true) 36 | try(`1 > 2`, false) 37 | try(`(1==1) == (2==2)`, true) 38 | try(`(1==1) == (1==2)`, false) 39 | try(`-1 == 1-2`, true) 40 | try(`+1 == 0+1`, true) 41 | try(`!(1==1) == (1==2)`, true) 42 | } 43 | -------------------------------------------------------------------------------- /findflakes/paths.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "bufio" 9 | "io" 10 | "os" 11 | "path/filepath" 12 | ) 13 | 14 | func readPaths(r io.Reader) ([]string, error) { 15 | out := []string{} 16 | scanner := bufio.NewScanner(os.Stdin) 17 | for scanner.Scan() { 18 | out = append(out, filepath.Join(*flagRevDir, scanner.Text())) 19 | } 20 | if err := scanner.Err(); err != nil { 21 | return nil, err 22 | } 23 | return out, nil 24 | } 25 | 26 | func pathFailures(revs []*Revision, paths []string) []*failure { 27 | pathSet := make(map[string]bool, len(paths)) 28 | for _, path := range paths { 29 | pathSet[path] = true 30 | } 31 | 32 | failures := []*failure{} 33 | for t, rev := range revs { 34 | for _, build := range rev.Builds { 35 | path := build.LogPath() 36 | if pathSet[path] { 37 | // TODO: Fill OS/Arch. 38 | failures = append(failures, &failure{ 39 | T: t, 40 | CommitsAgo: len(revs) - t - 1, 41 | Rev: rev, 42 | Build: build, 43 | }) 44 | } 45 | } 46 | } 47 | return failures 48 | } 49 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/stats/linearhist.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package stats 6 | 7 | // LinearHist is a Histogram with uniformly-sized bins. 8 | type LinearHist struct { 9 | min, max, delta float64 10 | low, high uint 11 | bins []uint 12 | } 13 | 14 | // NewLinearHist returns an empty histogram with nbins uniformly-sized 15 | // bins spanning [min, max]. 16 | func NewLinearHist(min, max float64, nbins int) *LinearHist { 17 | delta := float64(nbins) / (max - min) 18 | return &LinearHist{min, max, delta, 0, 0, make([]uint, nbins)} 19 | } 20 | 21 | func (h *LinearHist) bin(x float64) int { 22 | return int(h.delta * (x - h.min)) 23 | } 24 | 25 | func (h *LinearHist) Add(x float64) { 26 | bin := h.bin(x) 27 | if bin < 0 { 28 | h.low++ 29 | } else if bin >= len(h.bins) { 30 | h.high++ 31 | } else { 32 | h.bins[bin]++ 33 | } 34 | } 35 | 36 | func (h *LinearHist) Counts() (uint, []uint, uint) { 37 | return h.low, h.bins, h.high 38 | } 39 | 40 | func (h *LinearHist) BinToValue(bin float64) float64 { 41 | return h.min + bin*h.delta 42 | } 43 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/generic/slice/concat.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package slice 6 | 7 | import ( 8 | "reflect" 9 | 10 | "github.com/aclements/go-gg/generic" 11 | ) 12 | 13 | // Concat returns the concatenation of all of ss. The types of all of 14 | // the arguments must be identical or Concat will panic with a 15 | // *generic.TypeError. The returned slice will have the same type as the 16 | // inputs. If there are 0 arguments, Concat returns nil. Concat does 17 | // not modify any of the input slices. 18 | func Concat(ss ...T) T { 19 | if len(ss) == 0 { 20 | return nil 21 | } 22 | 23 | rvs := make([]reflect.Value, len(ss)) 24 | total := 0 25 | var typ reflect.Type 26 | for i, s := range ss { 27 | rvs[i] = reflectSlice(s) 28 | total += rvs[i].Len() 29 | if i == 0 { 30 | typ = rvs[i].Type() 31 | } else if rvs[i].Type() != typ { 32 | panic(&generic.TypeError{typ, rvs[i].Type(), "have different types"}) 33 | } 34 | } 35 | 36 | out := reflect.MakeSlice(typ, 0, total) 37 | for _, rv := range rvs { 38 | out = reflect.AppendSlice(out, rv) 39 | } 40 | return out.Interface() 41 | } 42 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/generic/slice/convert_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package slice 6 | 7 | import "testing" 8 | 9 | func TestConvert(t *testing.T) { 10 | var is []int 11 | Convert(&is, []int{1, 2, 3}) 12 | if w := []int{1, 2, 3}; !de(w, is) { 13 | t.Errorf("want %v; got %v", w, is) 14 | } 15 | Convert(&is, []float64{1, 2, 3}) 16 | if w := []int{1, 2, 3}; !de(w, is) { 17 | t.Errorf("want %v; got %v", w, is) 18 | } 19 | 20 | var fs []float64 21 | Convert(&fs, []int{1, 2, 3}) 22 | if w := []float64{1, 2, 3}; !de(w, fs) { 23 | t.Errorf("want %v; got %v", w, fs) 24 | } 25 | Convert(&fs, []float64{1, 2, 3}) 26 | if w := []float64{1, 2, 3}; !de(w, fs) { 27 | t.Errorf("want %v; got %v", w, fs) 28 | } 29 | 30 | shouldPanic(t, "cannot be converted", func() { 31 | Convert(&is, []string{"1", "2", "3"}) 32 | }) 33 | shouldPanic(t, `is not a \*\[\]T`, func() { 34 | Convert(is, []int{1, 2, 3}) 35 | }) 36 | shouldPanic(t, `is not a \*\[\]T`, func() { 37 | x := 1 38 | Convert(&x, []int{1, 2, 3}) 39 | }) 40 | shouldPanic(t, "is not a slice", func() { 41 | Convert(&is, 1) 42 | }) 43 | } 44 | -------------------------------------------------------------------------------- /varint/varint.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package varint 6 | 7 | const maxVarintBytes = 10 8 | 9 | // EncodeVarint and DecodeVarint from https://github.com/golang/protobuf 10 | 11 | func EncodeVarint(x uint64) []byte { 12 | var buf [maxVarintBytes]byte 13 | var n int 14 | for n = 0; x > 127; n++ { 15 | buf[n] = 0x80 | uint8(x&0x7F) 16 | x >>= 7 17 | } 18 | buf[n] = uint8(x) 19 | n++ 20 | return buf[0:n] 21 | } 22 | 23 | func DecodeVarint(buf []byte) (x uint64, n int) { 24 | // x, n already 0 25 | for shift := uint(0); shift < 64; shift += 7 { 26 | if n >= len(buf) { 27 | return 0, 0 28 | } 29 | b := uint64(buf[n]) 30 | n++ 31 | x |= (b & 0x7F) << shift 32 | if (b & 0x80) == 0 { 33 | return x, n 34 | } 35 | } 36 | 37 | // The number is too large to represent in a 64-bit value. 38 | return 0, 0 39 | } 40 | 41 | func queryBMI2() bool 42 | 43 | var hasBMI2 = queryBMI2() 44 | 45 | func decodeVarintAsmLoop(buf []byte) (x uint64, n int) 46 | func decodeVarintAsmBMI2(buf []byte) (x uint64, n int) 47 | func decodeVarintAsm1(buf []byte) (x uint64, n int) 48 | func decodeVarintAsm2(buf []byte) (x uint64, n int) 49 | -------------------------------------------------------------------------------- /rtanalysis/directives/analysis.go: -------------------------------------------------------------------------------- 1 | package directives 2 | 3 | import ( 4 | "go/ast" 5 | "reflect" 6 | "strings" 7 | 8 | "golang.org/x/tools/go/analysis" 9 | ) 10 | 11 | var Analyzer = &analysis.Analyzer{ 12 | Name: "directives", 13 | Doc: "collect //go:* directives for function declarations", 14 | Run: run, 15 | ResultType: reflect.TypeOf(Result(nil)), 16 | } 17 | 18 | type Result map[*ast.FuncDecl][]string 19 | 20 | func run(pass *analysis.Pass) (interface{}, error) { 21 | res := Result{} 22 | for _, f := range pass.Files { 23 | cgs := f.Comments 24 | for _, decl := range f.Decls { 25 | // Process comments before decl. 26 | var directives []string 27 | for len(cgs) > 0 && cgs[0].Pos() < decl.Pos() { 28 | for _, c := range cgs[0].List { 29 | if strings.HasPrefix(c.Text, "//go:") { 30 | directives = append(directives, strings.TrimSpace(c.Text)) 31 | } 32 | } 33 | cgs = cgs[1:] 34 | } 35 | // Ignore comments in decl. 36 | for len(cgs) > 0 && cgs[0].Pos() < decl.End() { 37 | cgs = cgs[1:] 38 | } 39 | // Attach directives to decl. 40 | if len(directives) > 0 { 41 | switch decl := decl.(type) { 42 | case *ast.FuncDecl: 43 | res[decl] = directives 44 | } 45 | } 46 | } 47 | } 48 | return res, nil 49 | } 50 | -------------------------------------------------------------------------------- /go-weave/amb/rand.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package amb 6 | 7 | import "math/rand" 8 | 9 | // StrategyRandom explores the ambiguous value space randomly. It 10 | // makes no attempt to avoid repeatedly visiting the same point, nor 11 | // does it know when it has explored the entire space. 12 | type StrategyRandom struct { 13 | // MaxDepth specifies the maximum depth of the tree. If this 14 | // is 0, it defaults to DefaultMaxDepth. 15 | MaxDepth int 16 | 17 | // MaxPaths specifies the maximum number of paths to explore. 18 | // If this is 0, the number of paths is unbounded. 19 | MaxPaths int 20 | 21 | step, paths int 22 | } 23 | 24 | func (s *StrategyRandom) Reset() { 25 | s.step = 0 26 | s.paths = 0 27 | } 28 | 29 | func (s *StrategyRandom) maxDepth() int { 30 | if s.MaxDepth == 0 { 31 | return DefaultMaxDepth 32 | } 33 | return s.MaxDepth 34 | } 35 | 36 | func (s *StrategyRandom) Amb(n int) (int, bool) { 37 | if s.step == s.maxDepth() { 38 | return 0, false 39 | } 40 | s.step++ 41 | return rand.Intn(n), true 42 | } 43 | 44 | func (s *StrategyRandom) Next() bool { 45 | s.step = 0 46 | s.paths++ 47 | return s.MaxPaths == 0 || s.paths < s.MaxPaths 48 | } 49 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/generic/slice/select_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package slice 6 | 7 | import ( 8 | "reflect" 9 | "testing" 10 | ) 11 | 12 | func TestSelect(t *testing.T) { 13 | x1 := []int{1, 2, 3} 14 | got := Select(x1, []int{2, 1, 0}) 15 | if want := []int{3, 2, 1}; !reflect.DeepEqual(got, want) { 16 | t.Fatalf("expected %v, got %v", want, got) 17 | } 18 | got = Select(x1, []int{1, 1, 1, 1}) 19 | if want := []int{2, 2, 2, 2}; !reflect.DeepEqual(got, want) { 20 | t.Fatalf("expected %v, got %v", want, got) 21 | } 22 | 23 | type T struct{ x int } 24 | x2 := []T{{1}, {2}, {3}} 25 | got = Select(x2, []int{2, 1, 0}) 26 | if want := []T{{3}, {2}, {1}}; !reflect.DeepEqual(got, want) { 27 | t.Fatalf("expected %v, got %v", want, got) 28 | } 29 | } 30 | 31 | func TestSelectType(t *testing.T) { 32 | type T []float64 33 | x1 := T{1, 2, 3} 34 | y1 := Select(x1, []int{}) 35 | if _, ok := y1.(T); !ok { 36 | t.Fatalf("result has wrong type; expected T, got %T", y1) 37 | } 38 | 39 | type U int 40 | x2 := []U{1, 2, 3} 41 | y2 := Select(x2, []int{}) 42 | if _, ok := y2.([]U); !ok { 43 | t.Fatalf("result has wrong type; expected []U, got %T", y2) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /benchcmd/main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Command benchcmd times a shell command using Go benchmark format. 6 | package main 7 | 8 | import ( 9 | "flag" 10 | "fmt" 11 | "os" 12 | "os/exec" 13 | "time" 14 | ) 15 | 16 | func main() { 17 | flag.Usage = func() { 18 | fmt.Fprintf(os.Stderr, "Usage: %s [-n iters] benchname cmd...\n", os.Args[0]) 19 | flag.PrintDefaults() 20 | } 21 | n := flag.Int("n", 5, "iterations") 22 | flag.Parse() 23 | if flag.NArg() < 2 { 24 | flag.Usage() 25 | os.Exit(2) 26 | } 27 | benchname := flag.Arg(0) 28 | args := flag.Args()[1:] 29 | 30 | for i := 0; i < *n; i++ { 31 | cmd := exec.Command(args[0], args[1:]...) 32 | cmd.Stdout = os.Stdout 33 | cmd.Stderr = os.Stderr 34 | before := time.Now() 35 | if err := cmd.Run(); err != nil { 36 | fmt.Println(err) 37 | os.Exit(1) 38 | } 39 | after := time.Now() 40 | fmt.Printf("Benchmark%s\t", benchname) 41 | fmt.Printf("%d\t%d ns/op", 1, after.Sub(before)) 42 | fmt.Printf("\t%d user-ns/op\t%d sys-ns/op", cmd.ProcessState.UserTime(), cmd.ProcessState.SystemTime()) 43 | if maxrss, ok := getMaxRSS(cmd.ProcessState); ok { 44 | fmt.Printf("\t%d peak-RSS-bytes", maxrss) 45 | } 46 | fmt.Printf("\n") 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/stats/deltadist.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package stats 6 | 7 | // DeltaDist is the Dirac delta function, centered at T, with total 8 | // area 1. 9 | // 10 | // The CDF of the Dirac delta function is the Heaviside step function, 11 | // centered at T. Specifically, f(T) == 1. 12 | type DeltaDist struct { 13 | T float64 14 | } 15 | 16 | func (d DeltaDist) PDF(x float64) float64 { 17 | if x == d.T { 18 | return inf 19 | } 20 | return 0 21 | } 22 | 23 | func (d DeltaDist) pdfEach(xs []float64) []float64 { 24 | res := make([]float64, len(xs)) 25 | for i, x := range xs { 26 | if x == d.T { 27 | res[i] = inf 28 | } 29 | } 30 | return res 31 | } 32 | 33 | func (d DeltaDist) CDF(x float64) float64 { 34 | if x >= d.T { 35 | return 1 36 | } 37 | return 0 38 | } 39 | 40 | func (d DeltaDist) cdfEach(xs []float64) []float64 { 41 | res := make([]float64, len(xs)) 42 | for i, x := range xs { 43 | res[i] = d.CDF(x) 44 | } 45 | return res 46 | } 47 | 48 | func (d DeltaDist) InvCDF(y float64) float64 { 49 | if y < 0 || y > 1 { 50 | return nan 51 | } 52 | return d.T 53 | } 54 | 55 | func (d DeltaDist) Bounds() (float64, float64) { 56 | return d.T - 1, d.T + 1 57 | } 58 | -------------------------------------------------------------------------------- /memmodel/hbacqrel.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | // HBAcqRel is an HBGenerator that implements acquire/release. 8 | type HBAcqRel struct{} 9 | 10 | func (HBAcqRel) HappensBefore(p *Prog, i, j PC) HBType { 11 | op1, op2 := p.OpAt(i), p.OpAt(j) 12 | //sameThread := i.TID == j.TID 13 | 14 | // TODO: Is this right? 15 | 16 | switch { 17 | case op1.Type == OpStore && op2.Type == OpStore && op1.Var == op2.Var: 18 | // Stores to the same location are totally ordered. 19 | return HBHappensBefore 20 | 21 | // case sameThread && op1.Type == OpSyncLoad && (op2.Type == OpSyncLoad || op2.Type == OpRegLoad): 22 | // // Loads are not allowed to move above a sync load. 23 | // return HBHappensBefore 24 | 25 | // case sameThread && (op1.Type == OpSyncStore || op1.Type == OpRegStore) && op2.Type == OpSyncStore: 26 | // // Stores are not allowed to move below a sync store. 27 | // return HBHappensBefore 28 | 29 | case op1.Type == OpStore && op2.Type == OpLoad && op1.Var == op2.Var: 30 | // If the load observes the store, then the store 31 | // happened before the load. 32 | return HBConditional 33 | } 34 | 35 | return HBConcurrent 36 | } 37 | 38 | func (HBAcqRel) String() string { 39 | return "AcqRel" 40 | } 41 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/generic/slice/cycle.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package slice 6 | 7 | import "reflect" 8 | 9 | // Cycle constructs a slice of length length by repeatedly 10 | // concatenating s to itself. If len(s) >= length, it returns 11 | // s[:length]. Otherwise, it allocates a new slice. If len(s) == 0 and 12 | // length != 0, Cycle panics. 13 | func Cycle(s T, length int) T { 14 | rv := reflectSlice(s) 15 | if rv.Len() >= length { 16 | return rv.Slice(0, length).Interface() 17 | } 18 | 19 | if rv.Len() == 0 { 20 | panic("empty slice") 21 | } 22 | 23 | // Allocate a new slice of the appropriate length. 24 | out := reflect.MakeSlice(rv.Type(), length, length) 25 | 26 | // Copy elements to out. 27 | for pos := 0; pos < length; { 28 | pos += reflect.Copy(out.Slice(pos, length), rv) 29 | } 30 | 31 | return out.Interface() 32 | } 33 | 34 | // Repeat returns a slice consisting of length copies of v. 35 | func Repeat(v interface{}, length int) T { 36 | if length < 0 { 37 | length = 0 38 | } 39 | rv := reflect.ValueOf(v) 40 | out := reflect.MakeSlice(reflect.SliceOf(rv.Type()), length, length) 41 | for i := 0; i < length; i++ { 42 | out.Index(i).Set(rv) 43 | } 44 | return out.Interface() 45 | } 46 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/gg/example_scale_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package gg 6 | 7 | import ( 8 | "fmt" 9 | "math/rand" 10 | "os" 11 | "time" 12 | 13 | "github.com/aclements/go-gg/table" 14 | ) 15 | 16 | func ExampleNewTimeScaler() { 17 | var x []time.Time 18 | var y []float64 19 | var steps []time.Duration 20 | for _, step := range []time.Duration{ 21 | 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 22 | time.Minute, time.Hour, 24 * time.Hour, 7 * 24 * time.Hour, 23 | } { 24 | t := time.Now() 25 | for i := 0; i < 100; i++ { 26 | x = append(x, t) 27 | y = append(y, rand.Float64()-.5) 28 | steps = append(steps, 100*step) 29 | t = t.Add(-step) 30 | } 31 | } 32 | 33 | tb := table.NewBuilder(nil) 34 | tb.Add("x", x).Add("y", y).Add("steps", steps) 35 | 36 | plot := NewPlot(tb.Done()) 37 | 38 | plot.SetScale("x", NewTimeScaler()) 39 | 40 | plot.Add(FacetY{ 41 | Col: "steps", 42 | SplitXScales: true, 43 | }) 44 | 45 | plot.Add(LayerLines{ 46 | X: "x", 47 | Y: "y", 48 | }) 49 | 50 | f, err := os.Create("scale_time.svg") 51 | if err != nil { 52 | panic("unable to create scale_time.svg") 53 | } 54 | defer f.Close() 55 | plot.WriteSVG(f, 800, 1000) 56 | fmt.Println("ok") 57 | // output: 58 | // ok 59 | } 60 | -------------------------------------------------------------------------------- /benchplot/kza_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "math/rand" 9 | "testing" 10 | ) 11 | 12 | // Aeq returns true if expect and got are equal to 8 significant 13 | // figures (1 part in 100 million). 14 | func Aeq(expect, got float64) bool { 15 | if expect < 0 && got < 0 { 16 | expect, got = -expect, -got 17 | } 18 | return expect*0.99999999 <= got && got*0.99999999 <= expect 19 | } 20 | 21 | func TestMovingAverage(t *testing.T) { 22 | // Test MovingAverage against the obvious (but slow) 23 | // implementation. 24 | xs := make([]float64, 100) 25 | for iter := 0; iter < 10; iter++ { 26 | for i := range xs { 27 | xs[i] = rand.Float64() 28 | } 29 | m := 1 + 2*rand.Intn(100) 30 | ys1, ys2 := MovingAverage(xs, m), slowMovingAverage(xs, m) 31 | 32 | // TODO: Use stuff from mathtest. 33 | for i, y1 := range ys1 { 34 | if !Aeq(y1, ys2[i]) { 35 | t.Fatalf("want %v, got %v", ys2, ys1) 36 | } 37 | } 38 | } 39 | } 40 | 41 | func slowMovingAverage(xs []float64, m int) []float64 { 42 | ys := make([]float64, len(xs)) 43 | for i := range ys { 44 | psum, n := 0.0, 0 45 | for j := i - (m-1)/2; j <= i+(m-1)/2; j++ { 46 | if 0 <= j && j < len(xs) { 47 | psum += xs[j] 48 | n++ 49 | } 50 | } 51 | ys[i] = psum / float64(n) 52 | } 53 | return ys 54 | } 55 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/palette/brewer/package.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2002 Cynthia Brewer, Mark Harrower, and The 2 | // Pennsylvania State University. 3 | // Please see license at http://colorbrewer.org/export/LICENSE.txt. 4 | 5 | // Package brewer provides color specifications and designs developed 6 | // by Cynthia Brewer (http://colorbrewer.org/). 7 | // 8 | // Please see license at http://colorbrewer.org/export/LICENSE.txt. 9 | // 10 | // This package provides three different types of color palettes. 11 | // Sequential palettes are for ordered data that progresses from low 12 | // to high. Diverging palettes are like sequential palettes, but have 13 | // a defined middle and two extremes. Finally, qualitative palettes 14 | // are for unordered or nominal data. See "Brewer, Cynthia A. 1994. 15 | // Color use guidelines for mapping and visualization. Chapter 7 (pp. 16 | // 123–147) in Visualization in Modern Cartography" for more details. 17 | // 18 | // All palettes provided by this package are discrete, but each comes 19 | // in several variants with different numbers of discrete levels. 20 | // These variants are named _ where n is the number of 21 | // levels. 22 | // 23 | // Each palette also provides a variable named that is a map 24 | // from the number of levels to the specific variants. 25 | // 26 | // Finally, the global ByName map from string name to palette. 27 | package brewer 28 | 29 | //go:generate go run genbrewer.go colorbrewer.json 30 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/generic/slice/nub.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package slice 6 | 7 | import "reflect" 8 | 9 | var trueVal = reflect.ValueOf(true) 10 | 11 | // Nub returns v with duplicates removed. It keeps the first instance 12 | // of each distinct value and preserves their order. 13 | func Nub(v T) T { 14 | rv := reflectSlice(v) 15 | indexes := make([]int, 0) 16 | set := reflect.MakeMap(reflect.MapOf(rv.Type().Elem(), trueVal.Type())) 17 | for i, l := 0, rv.Len(); i < l; i++ { 18 | x := rv.Index(i) 19 | if set.MapIndex(x).IsValid() { 20 | continue 21 | } 22 | set.SetMapIndex(x, trueVal) 23 | indexes = append(indexes, i) 24 | } 25 | return Select(v, indexes) 26 | } 27 | 28 | // NubAppend is equivalent to appending all of the slices in vs and 29 | // then calling Nub on the result, but more efficient. 30 | func NubAppend(vs ...T) T { 31 | if len(vs) == 0 { 32 | return nil 33 | } 34 | 35 | rv := reflectSlice(vs[0]) 36 | set := reflect.MakeMap(reflect.MapOf(rv.Type().Elem(), trueVal.Type())) 37 | out := reflect.MakeSlice(rv.Type(), 0, 0) 38 | 39 | for _, v := range vs { 40 | rv := reflectSlice(v) 41 | for i, l := 0, rv.Len(); i < l; i++ { 42 | x := rv.Index(i) 43 | if set.MapIndex(x).IsValid() { 44 | continue 45 | } 46 | set.SetMapIndex(x, trueVal) 47 | out = reflect.Append(out, x) 48 | } 49 | } 50 | 51 | return out.Interface() 52 | } 53 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/gg/group.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package gg 6 | 7 | import "github.com/aclements/go-gg/table" 8 | 9 | // TODO: GroupByKey? Would the key function only work on one binding? 10 | // With a first-class row representation we could pass that. 11 | 12 | // GroupBy sub-divides all groups such that all of the rows in each 13 | // group have equal values for all of the named columns. 14 | func (p *Plot) GroupBy(cols ...string) *Plot { 15 | // TODO: Should this accept column expressions, like layers? 16 | return p.SetData(table.GroupBy(p.Data(), cols...)) 17 | } 18 | 19 | // GroupAuto groups p's data table on all columns that are comparable 20 | // but are not numeric (that is, all categorical columns). 21 | // 22 | // TODO: Maybe there should be a CategoricalBindings that returns the 23 | // set of categorical bindings, which callers could just pass to 24 | // GroupBy, possibly after manipulating. 25 | // 26 | // TODO: Does implementing sort.Interface make an otherwise cardinal 27 | // column ordinal? 28 | func (p *Plot) GroupAuto() *Plot { 29 | // Find the categorical columns. 30 | categorical := []string{} 31 | g := p.Data() 32 | for _, col := range g.Columns() { 33 | et := table.ColType(g, col).Elem() 34 | if et.Comparable() && !isCardinal(et.Kind()) { 35 | categorical = append(categorical, col) 36 | } 37 | } 38 | 39 | return p.GroupBy(categorical...) 40 | } 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | -------------------------------------------------------------------------------- /minutes3/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/aclements/go-misc/minutes3 2 | 3 | go 1.23 4 | 5 | require ( 6 | golang.org/x/oauth2 v0.21.0 7 | google.golang.org/api v0.189.0 8 | rsc.io/github v0.5.1-0.20250216154006-6eda34706df1 9 | ) 10 | 11 | require ( 12 | cloud.google.com/go/auth v0.7.2 // indirect 13 | cloud.google.com/go/auth/oauth2adapt v0.2.3 // indirect 14 | cloud.google.com/go/compute/metadata v0.5.0 // indirect 15 | github.com/felixge/httpsnoop v1.0.4 // indirect 16 | github.com/go-logr/logr v1.4.2 // indirect 17 | github.com/go-logr/stdr v1.2.2 // indirect 18 | github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect 19 | github.com/golang/protobuf v1.5.4 // indirect 20 | github.com/google/s2a-go v0.1.7 // indirect 21 | github.com/google/uuid v1.6.0 // indirect 22 | github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect 23 | github.com/googleapis/gax-go/v2 v2.12.5 // indirect 24 | go.opencensus.io v0.24.0 // indirect 25 | go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect 26 | go.opentelemetry.io/otel v1.24.0 // indirect 27 | go.opentelemetry.io/otel/metric v1.24.0 // indirect 28 | go.opentelemetry.io/otel/trace v1.24.0 // indirect 29 | golang.org/x/crypto v0.25.0 // indirect 30 | golang.org/x/net v0.27.0 // indirect 31 | golang.org/x/sys v0.22.0 // indirect 32 | golang.org/x/text v0.16.0 // indirect 33 | google.golang.org/genproto/googleapis/rpc v0.0.0-20240722135656-d784300faade // indirect 34 | google.golang.org/grpc v1.64.1 // indirect 35 | google.golang.org/protobuf v1.34.2 // indirect 36 | ) 37 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/generic/slice/find.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package slice 6 | 7 | import ( 8 | "reflect" 9 | 10 | "github.com/aclements/go-gg/generic" 11 | ) 12 | 13 | // Index returns the index of the first instance of val in s, or -1 if 14 | // val is not present in s. val's type must be s's element type. 15 | func Index(s T, val interface{}) int { 16 | rs := reflectSlice(s) 17 | if vt := reflect.TypeOf(val); rs.Type().Elem() != vt { 18 | // TODO: Better " is not a sequence of ". 19 | panic(&generic.TypeError{rs.Type(), vt, "cannot find"}) 20 | } 21 | 22 | for i, l := 0, rs.Len(); i < l; i++ { 23 | if rs.Index(i).Interface() == val { 24 | return i 25 | } 26 | } 27 | return -1 28 | } 29 | 30 | // LastIndex returns the index of the last instance of val in s, or -1 31 | // if val is not present in s. val's type must be s's element type. 32 | func LastIndex(s T, val interface{}) int { 33 | rs := reflectSlice(s) 34 | if vt := reflect.TypeOf(val); rs.Type().Elem() != vt { 35 | // TODO: Better " is not a sequence of ". 36 | panic(&generic.TypeError{rs.Type(), vt, "cannot find"}) 37 | } 38 | 39 | for i := rs.Len() - 1; i >= 0; i-- { 40 | if rs.Index(i).Interface() == val { 41 | return i 42 | } 43 | } 44 | return -1 45 | } 46 | 47 | // Contains reports whether val is within s. val's type must be s's 48 | // element type. 49 | func Contains(s T, val interface{}) bool { 50 | return Index(s, val) >= 0 51 | } 52 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/gg/testmain.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build ignore 6 | 7 | package main 8 | 9 | import ( 10 | "math" 11 | "math/rand" 12 | "os" 13 | 14 | "github.com/aclements/go-gg/gg" 15 | "github.com/aclements/go-gg/ggstat" 16 | "github.com/aclements/go-gg/table" 17 | "github.com/aclements/go-moremath/vec" 18 | ) 19 | 20 | func main() { 21 | xs1 := vec.Linspace(-10, 10, 100) 22 | for i := range xs1 { 23 | xs1[i] = rand.Float64()*20 - 10 24 | } 25 | ys1 := vec.Map(math.Sin, xs1) 26 | 27 | xs2 := vec.Linspace(-10, 10, 100) 28 | ys2 := vec.Map(math.Cos, xs2) 29 | 30 | which := []string{} 31 | for range xs1 { 32 | which = append(which, "sin") 33 | } 34 | for range xs2 { 35 | which = append(which, "cos") 36 | } 37 | 38 | xs := vec.Concat(xs1, xs2) 39 | ys := vec.Concat(ys1, ys2) 40 | 41 | tab := table.NewBuilder(nil).Add("x", xs).Add("y", ys).Add("which", which).Done() 42 | 43 | plot := gg.NewPlot(tab) 44 | plot.GroupAuto() 45 | plot.Add(gg.FacetX{Col: "which"}) 46 | plot.Add(gg.FacetY{Col: "which"}) 47 | plot.Add(gg.LayerLines{X: "x", Y: "y"}) 48 | 49 | plot.Save() 50 | plot.SetData(ggstat.ECDF{X: "x"}.F(plot.Data())) 51 | plot.Add(gg.LayerSteps{Step: gg.StepHV}) 52 | //plot.Add(gg.LayerSteps{Step:gg.StepHMid}) 53 | plot.Restore() 54 | 55 | plot.Save() 56 | plot.SetData(ggstat.Density{X: "x"}.F(plot.Data())) 57 | plot.Add(gg.LayerPaths{}) 58 | plot.Restore() 59 | 60 | plot.WriteSVG(os.Stdout, 400, 300) 61 | } 62 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/internal/mathtest/mathtest.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package mathtest 6 | 7 | import ( 8 | "fmt" 9 | "math" 10 | "sort" 11 | "strings" 12 | "testing" 13 | ) 14 | 15 | var ( 16 | aeqDigits int 17 | aeqFactor float64 18 | ) 19 | 20 | func SetAeqDigits(digits int) int { 21 | old := aeqDigits 22 | aeqDigits = digits 23 | aeqFactor = 1 - math.Pow(10, float64(-digits+1)) 24 | return old 25 | } 26 | 27 | func init() { 28 | SetAeqDigits(8) 29 | } 30 | 31 | // Aeq returns true if expect and got are equal up to the current 32 | // number of aeq digits set by SetAeqDigits. By default, this is 8 33 | // significant figures (1 part in 100 million). 34 | func Aeq(expect, got float64) bool { 35 | if expect < 0 && got < 0 { 36 | expect, got = -expect, -got 37 | } 38 | return expect*aeqFactor <= got && got*aeqFactor <= expect 39 | } 40 | 41 | func WantFunc(t *testing.T, name string, f func(float64) float64, vals map[float64]float64) { 42 | xs := make([]float64, 0, len(vals)) 43 | for x := range vals { 44 | xs = append(xs, x) 45 | } 46 | sort.Float64s(xs) 47 | 48 | for _, x := range xs { 49 | want, got := vals[x], f(x) 50 | if math.IsNaN(want) && math.IsNaN(got) || Aeq(want, got) { 51 | continue 52 | } 53 | var label string 54 | if strings.Contains(name, "%v") { 55 | label = fmt.Sprintf(name, x) 56 | } else { 57 | label = fmt.Sprintf("%s(%v)", name, x) 58 | } 59 | t.Errorf("want %s=%v, got %v", label, want, got) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/mathx/gamma_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package mathx 6 | 7 | import ( 8 | "testing" 9 | 10 | . "github.com/aclements/go-moremath/internal/mathtest" 11 | ) 12 | 13 | func TestGammaInc(t *testing.T) { 14 | WantFunc(t, "GammaInc(1, %v)", 15 | func(x float64) float64 { return GammaInc(1, x) }, 16 | map[float64]float64{ 17 | 0.1: 0.095162581964040441, 18 | 0.2: 0.18126924692201815, 19 | 0.3: 0.25918177931828207, 20 | 0.4: 0.32967995396436056, 21 | 0.5: 0.39346934028736652, 22 | 0.6: 0.45118836390597361, 23 | 0.7: 0.50341469620859047, 24 | 0.8: 0.55067103588277833, 25 | 0.9: 0.59343034025940089, 26 | 1: 0.63212055882855778, 27 | 2: 0.86466471676338730, 28 | 3: 0.95021293163213605, 29 | 4: 0.98168436111126578, 30 | 5: 0.99326205300091452, 31 | 6: 0.99752124782333362, 32 | 7: 0.99908811803444553, 33 | 8: 0.99966453737209748, 34 | 9: 0.99987659019591335, 35 | 10: 0.99995460007023750, 36 | }) 37 | WantFunc(t, "GammaInc(2, %v)", 38 | func(x float64) float64 { return GammaInc(2, x) }, 39 | map[float64]float64{ 40 | 1: 0.26424111765711528, 41 | 2: 0.59399415029016167, 42 | 3: 0.80085172652854419, 43 | 4: 0.90842180555632912, 44 | 5: 0.95957231800548726, 45 | 6: 0.98264873476333547, 46 | 7: 0.99270494427556388, 47 | 8: 0.99698083634887735, 48 | 9: 0.99876590195913317, 49 | 10: 0.99950060077261271, 50 | }) 51 | 52 | // TODO: Test strange values. 53 | } 54 | -------------------------------------------------------------------------------- /memmodel/sc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | // SCModel models all loads and stores as sequentially consistent. 8 | // That is, there is a total order over all loads and stores. It 9 | // implements sequential consistency using a direct operational 10 | // semantics. 11 | type SCModel struct{} 12 | 13 | func (SCModel) String() string { 14 | return "SC" 15 | } 16 | 17 | func (SCModel) Eval(p *Prog, outcomes *OutcomeSet) { 18 | // Run the program in all possible ways, gather the results of 19 | // each load instruction, and at the end of each execution 20 | // record the outcome. 21 | outcomes.Reset(p) 22 | (&scGlobal{p, outcomes}).rec(scState{}) 23 | } 24 | 25 | // scGlobal stores state that is global to an SC evaluation. 26 | type scGlobal struct { 27 | p *Prog 28 | outcomes *OutcomeSet 29 | } 30 | 31 | // scState stores the state of a program at a single point during 32 | // execution. 33 | type scState struct { 34 | mem MemState 35 | pcs [MaxThreads]int 36 | outcome Outcome 37 | } 38 | 39 | func (g *scGlobal) rec(s scState) { 40 | var opres int 41 | // Pick an op to execute next. 42 | any := false 43 | for tid := range g.p.Threads { 44 | op := g.p.Threads[tid].Ops[s.pcs[tid]] 45 | if op.Type != OpExit { 46 | any = true 47 | ns := s 48 | ns.mem, opres = op.Exec(ns.mem) 49 | if op.Type == OpLoad { 50 | ns.outcome |= Outcome(opres) << op.ID 51 | } 52 | ns.pcs[tid]++ 53 | g.rec(ns) 54 | } 55 | } 56 | if !any { 57 | // This execution is done. 58 | g.outcomes.Add(s.outcome) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/generic/slice/convert.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package slice 6 | 7 | import ( 8 | "reflect" 9 | 10 | "github.com/aclements/go-gg/generic" 11 | ) 12 | 13 | // Convert converts each element in from and assigns it to *to. to 14 | // must be a pointer to a slice. Convert slices or extends *to to 15 | // len(from) and then assigns to[i] = T(from[i]) where T is the type 16 | // of *to's elements. If from and *to have the same element type, it 17 | // simply assigns *to = from. 18 | func Convert(to interface{}, from T) { 19 | fv := reflectSlice(from) 20 | tv := reflect.ValueOf(to) 21 | if tv.Kind() != reflect.Ptr { 22 | panic(&generic.TypeError{tv.Type(), nil, "is not a *[]T"}) 23 | } 24 | tst := tv.Type().Elem() 25 | if tst.Kind() != reflect.Slice { 26 | panic(&generic.TypeError{tv.Type(), nil, "is not a *[]T"}) 27 | } 28 | 29 | if fv.Type().AssignableTo(tst) { 30 | tv.Elem().Set(fv) 31 | return 32 | } 33 | 34 | eltt := tst.Elem() 35 | if !fv.Type().Elem().ConvertibleTo(eltt) { 36 | panic(&generic.TypeError{fv.Type(), tst, "cannot be converted"}) 37 | } 38 | 39 | switch to := to.(type) { 40 | case *[]float64: 41 | // This is extremely common. 42 | *to = (*to)[:0] 43 | for i, len := 0, fv.Len(); i < len; i++ { 44 | *to = append(*to, fv.Index(i).Convert(eltt).Float()) 45 | } 46 | 47 | default: 48 | tsv := tv.Elem() 49 | tsv.SetLen(0) 50 | for i, len := 0, fv.Len(); i < len; i++ { 51 | tsv = reflect.Append(tsv, fv.Index(i).Convert(eltt)) 52 | } 53 | tv.Elem().Set(tsv) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/mathx/choose.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package mathx 6 | 7 | import "math" 8 | 9 | const smallFactLimit = 20 // 20! => 62 bits 10 | var smallFact [smallFactLimit + 1]int64 11 | 12 | func init() { 13 | smallFact[0] = 1 14 | fact := int64(1) 15 | for n := int64(1); n <= smallFactLimit; n++ { 16 | fact *= n 17 | smallFact[n] = fact 18 | } 19 | } 20 | 21 | // Choose returns the binomial coefficient of n and k. 22 | func Choose(n, k int) float64 { 23 | if k == 0 || k == n { 24 | return 1 25 | } 26 | if k < 0 || n < k { 27 | return 0 28 | } 29 | if n <= smallFactLimit { // Implies k <= smallFactLimit 30 | // It's faster to do several integer multiplications 31 | // than it is to do an extra integer division. 32 | // Remarkably, this is also faster than pre-computing 33 | // Pascal's triangle (presumably because this is very 34 | // cache efficient). 35 | numer := int64(1) 36 | for n1 := int64(n - (k - 1)); n1 <= int64(n); n1++ { 37 | numer *= n1 38 | } 39 | denom := smallFact[k] 40 | return float64(numer / denom) 41 | } 42 | 43 | return math.Exp(lchoose(n, k)) 44 | } 45 | 46 | // Lchoose returns math.Log(Choose(n, k)). 47 | func Lchoose(n, k int) float64 { 48 | if k == 0 || k == n { 49 | return 0 50 | } 51 | if k < 0 || n < k { 52 | return math.NaN() 53 | } 54 | return lchoose(n, k) 55 | } 56 | 57 | func lchoose(n, k int) float64 { 58 | a, _ := math.Lgamma(float64(n + 1)) 59 | b, _ := math.Lgamma(float64(k + 1)) 60 | c, _ := math.Lgamma(float64(n - k + 1)) 61 | return a - b - c 62 | } 63 | -------------------------------------------------------------------------------- /pcvaluetab/alt_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "fmt" 9 | "math/rand" 10 | "strings" 11 | "testing" 12 | ) 13 | 14 | var sinkInt int 15 | 16 | func TestCount0124(t *testing.T) { 17 | var src strings.Builder 18 | fmt.Fprintf(&src, "var count0124Tab = [...]uint8{\n") 19 | 20 | for x := 0; x < 256; x++ { 21 | want := count0124Slow(uint8(x)) 22 | gotFormula := count0124Formula(uint8(x)) 23 | gotTable := count0124(uint8(x)) 24 | 25 | t.Logf("%#08b => %d %d %d", x, want, gotFormula, gotTable) 26 | if want != gotFormula || want != gotTable { 27 | t.Errorf("count implementations differ for x=%#08b", x) 28 | } 29 | 30 | fmt.Fprintf(&src, "%d,", want) 31 | if x%16 == 15 { 32 | fmt.Fprintf(&src, "\n") 33 | } 34 | } 35 | 36 | src.WriteByte('}') 37 | t.Log(src.String()) 38 | } 39 | 40 | func BenchmarkCount0124(b *testing.B) { 41 | // Generate test data. 42 | var data [1024]byte // Must be a power of 2 for optimal codegen 43 | rand.Read(data[:]) 44 | 45 | b.Run("formula", func(b *testing.B) { 46 | var sink uint 47 | for i := 0; i < b.N; i++ { 48 | sink = count0124Formula(data[i&(len(data)-1)]) 49 | } 50 | sinkInt = int(sink) 51 | }) 52 | b.Run("slow", func(b *testing.B) { 53 | var sink uint 54 | for i := 0; i < b.N; i++ { 55 | sink = count0124Slow(data[i&(len(data)-1)]) 56 | } 57 | sinkInt = int(sink) 58 | }) 59 | b.Run("table", func(b *testing.B) { 60 | var sink uint 61 | for i := 0; i < b.N; i++ { 62 | sink = count0124(data[i&(len(data)-1)]) 63 | } 64 | sinkInt = int(sink) 65 | }) 66 | } 67 | -------------------------------------------------------------------------------- /findflakes/geodist.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "math" 9 | "math/rand" 10 | ) 11 | 12 | // GeometricDist is a geometric distribution with success probability 13 | // P. 14 | type GeometricDist struct { 15 | P float64 16 | 17 | // Start is the start of the distribution's support. There are 18 | // two conventional definitions of the geometric distribution: 19 | // 20 | // For Start=0, the distribution gives the number of failures 21 | // before the first success in a Bernoulli process with 22 | // success probability P. 23 | // 24 | // For Start=1, the distribution gives the number of trials 25 | // needed to get one success. This is often called the 26 | // "shifted geometric distribution." 27 | // 28 | // Other values of Start are allowed, but have no conventional 29 | // meaning. 30 | Start int 31 | } 32 | 33 | func (d *GeometricDist) PMF(k int) float64 { 34 | if k < d.Start { 35 | return 0 36 | } 37 | return math.Pow(1-d.P, float64(k-d.Start)) * d.P 38 | } 39 | 40 | func (d *GeometricDist) CDF(k int) float64 { 41 | if k < d.Start { 42 | return 0 43 | } 44 | return 1 - math.Pow(1-d.P, float64(k-d.Start+1)) 45 | } 46 | 47 | func (d *GeometricDist) SF(k int) float64 { 48 | if k < d.Start { 49 | return 1 50 | } 51 | return math.Pow(1-d.P, float64(k-d.Start+1)) 52 | } 53 | 54 | func (d *GeometricDist) InvCDF(y float64) int { 55 | return int(math.Ceil(math.Log(1-y)/math.Log(1-d.P)-1)) + d.Start 56 | } 57 | 58 | func (d *GeometricDist) Rand() int { 59 | u := 1 - rand.Float64() 60 | return int(math.Log(u)/math.Log(1-d.P)) + d.Start 61 | } 62 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/scale/ticks_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package scale 6 | 7 | import "testing" 8 | 9 | type testTicker struct{} 10 | 11 | func (testTicker) CountTicks(level int) int { 12 | c := 10 - level 13 | if c < 1 { 14 | c = 1 15 | } 16 | return c 17 | } 18 | 19 | func (t testTicker) TicksAtLevel(level int) interface{} { 20 | m := make([]float64, t.CountTicks(level)) 21 | for i := 0; i < len(m); i++ { 22 | m[i] = float64(i) 23 | } 24 | return m 25 | } 26 | 27 | func TestTicks(t *testing.T) { 28 | check := func(o TickOptions, want int) { 29 | wantL, wantOK := want, true 30 | if want == -999 { 31 | wantL, wantOK = 0, false 32 | } 33 | for _, guess := range []int{0, -50, 50} { 34 | l, ok := o.FindLevel(testTicker{}, guess) 35 | if l != wantL || ok != wantOK { 36 | t.Errorf("%+v.FindLevel with guess %v returned %v, %v; wanted %v, %v", o, guess, l, ok, wantL, wantOK) 37 | } 38 | } 39 | } 40 | 41 | // Argument sanity checking. 42 | check(TickOptions{}, -999) 43 | check(TickOptions{MinLevel: 10, MaxLevel: 9}, -999) 44 | 45 | // Just max constraint. 46 | check(TickOptions{Max: 1}, 9) 47 | check(TickOptions{Max: 6}, 4) 48 | check(TickOptions{Max: 20}, -10) 49 | 50 | // Max and level constraints. 51 | check(TickOptions{Max: 1, MaxLevel: 9}, 9) 52 | check(TickOptions{Max: 1, MaxLevel: 8}, -999) 53 | check(TickOptions{Max: 1, MinLevel: 9, MaxLevel: 1000}, 9) 54 | check(TickOptions{Max: 1, MinLevel: 10, MaxLevel: 1000}, 10) 55 | 56 | check(TickOptions{Max: 6, MaxLevel: 9}, 4) 57 | check(TickOptions{Max: 6, MaxLevel: 3}, -999) 58 | check(TickOptions{Max: 6, MinLevel: 10, MaxLevel: 11}, 10) 59 | } 60 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/table/head.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package table 6 | 7 | import "reflect" 8 | 9 | // Head returns the first n rows in each Table of g. 10 | func Head(g Grouping, n int) Grouping { 11 | return headTail(g, n, false) 12 | } 13 | 14 | // Tail returns the last n rows in each Table of g. 15 | func Tail(g Grouping, n int) Grouping { 16 | return headTail(g, n, true) 17 | } 18 | 19 | func headTail(g Grouping, n int, tail bool) Grouping { 20 | return MapTables(g, func(_ GroupID, t *Table) *Table { 21 | if t.Len() <= n { 22 | return t 23 | } 24 | 25 | var nt Builder 26 | for _, col := range t.Columns() { 27 | if cv, ok := t.Const(col); ok { 28 | nt.AddConst(col, cv) 29 | continue 30 | } 31 | 32 | cv := reflect.ValueOf(t.Column(col)) 33 | if tail { 34 | cv = cv.Slice(t.Len()-n, t.Len()) 35 | } else { 36 | cv = cv.Slice(0, n) 37 | } 38 | nt.Add(col, cv.Interface()) 39 | } 40 | return nt.Done() 41 | }) 42 | } 43 | 44 | // HeadTables returns the first n tables in g. 45 | func HeadTables(g Grouping, n int) Grouping { 46 | return headTailTables(g, n, false) 47 | } 48 | 49 | // TailTables returns the first n tables in g. 50 | func TailTables(g Grouping, n int) Grouping { 51 | return headTailTables(g, n, true) 52 | } 53 | 54 | func headTailTables(g Grouping, n int, tail bool) Grouping { 55 | tables := g.Tables() 56 | if len(tables) <= n { 57 | return g 58 | } else if tail { 59 | tables = tables[len(tables)-n:] 60 | } else { 61 | tables = tables[:n] 62 | } 63 | 64 | var ng GroupingBuilder 65 | for _, gid := range tables { 66 | ng.Add(gid, g.Table(gid)) 67 | } 68 | return ng.Done() 69 | } 70 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/table/print_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package table 6 | 7 | import ( 8 | "bytes" 9 | "os" 10 | "testing" 11 | ) 12 | 13 | func groupString(g Grouping) string { 14 | var b bytes.Buffer 15 | Fprint(&b, g, "%#v", "%#v", "%#v", "%#v") 16 | return b.String() 17 | } 18 | 19 | func ExampleFprint() { 20 | tab := new(Builder). 21 | Add("name", []string{"Washington", "Adams", "Jefferson"}). 22 | Add("terms", []int{2, 1, 2}). 23 | Done() 24 | Fprint(os.Stdout, tab) 25 | // Output: 26 | // name terms 27 | // Washington 2 28 | // Adams 1 29 | // Jefferson 2 30 | } 31 | 32 | func ExampleFprint_Formats() { 33 | tab := new(Builder). 34 | Add("name", []string{"Washington", "Adams", "Jefferson"}). 35 | Add("terms", []int{2, 1, 2}). 36 | Done() 37 | Fprint(os.Stdout, tab, "President %s", "%#x") 38 | // Output: 39 | // name terms 40 | // President Washington 0x2 41 | // President Adams 0x1 42 | // President Jefferson 0x2 43 | } 44 | 45 | func ExampleFprint_Groups() { 46 | tab := new(Builder). 47 | Add("name", []string{"Washington", "Adams", "Jefferson"}). 48 | Add("terms", []int{2, 1, 2}). 49 | Add("state", []string{"Virginia", "Massachusetts", "Virginia"}). 50 | Done() 51 | g := GroupBy(tab, "state") 52 | Fprint(os.Stdout, g) 53 | // Output: 54 | // name terms state 55 | // -- /Virginia 56 | // Washington 2 Virginia 57 | // Jefferson 2 Virginia 58 | // -- /Massachusetts 59 | // Adams 1 Massachusetts 60 | } 61 | 62 | func TestFprintEmpty(t *testing.T) { 63 | var b bytes.Buffer 64 | Fprint(&b, new(Table)) 65 | if b.String() != "" { 66 | t.Fatalf("want %q; got %q", "", b.String()) 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/table/pivot_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package table 6 | 7 | import ( 8 | "fmt" 9 | "testing" 10 | ) 11 | 12 | var stateTemp = TableFromStrings( 13 | []string{"state", "high", "low"}, 14 | [][]string{ 15 | {"Alabama", "122", "-27"}, 16 | {"Alaska", "100", "-80"}, 17 | }, true) 18 | 19 | func ExampleUnpivot() { 20 | fmt.Println("Original table") 21 | Print(stateTemp) 22 | fmt.Println() 23 | fmt.Println("Unpivoted table") 24 | Print(Unpivot(stateTemp, "kind", "temperature", "high", "low")) 25 | // Output: 26 | // 27 | // Original table 28 | // state high low 29 | // Alabama 122 -27 30 | // Alaska 100 -80 31 | // 32 | // Unpivoted table 33 | // state kind temperature 34 | // Alabama high 122 35 | // Alabama low -27 36 | // Alaska high 100 37 | // Alaska low -80 38 | } 39 | 40 | var stateTempByKind = Unpivot(stateTemp, "kind", "temperature", "high", "low") 41 | 42 | func ExamplePivot() { 43 | fmt.Println("Original table") 44 | Print(stateTempByKind) 45 | fmt.Println() 46 | fmt.Println("Pivoted table") 47 | Print(Pivot(stateTempByKind, "kind", "temperature")) 48 | // Output: 49 | // 50 | // Original table 51 | // state kind temperature 52 | // Alabama high 122 53 | // Alabama low -27 54 | // Alaska high 100 55 | // Alaska low -80 56 | // 57 | // Pivoted table 58 | // state high low 59 | // Alabama 122 -27 60 | // Alaska 100 -80 61 | } 62 | 63 | func TestUnpivot(t *testing.T) { 64 | tab := new(Builder).Add("x", []int{}).Add("y", []float64{}).Done() 65 | shouldPanic(t, "at least 1 column", func() { 66 | Unpivot(tab, "a", "b") 67 | }) 68 | shouldPanic(t, "different types", func() { 69 | Unpivot(tab, "a", "b", "x", "y") 70 | }) 71 | } 72 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/fit/loess_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package fit 6 | 7 | import ( 8 | "testing" 9 | 10 | "github.com/aclements/go-moremath/internal/mathtest" 11 | ) 12 | 13 | func TestLOESS_NIST(t *testing.T) { 14 | // LOWESS example from the NIST handbook. 15 | xs := []float64{0.5578196, 16 | 2.0217271, 17 | 2.5773252, 18 | 3.4140288, 19 | 4.3014084, 20 | 4.7448394, 21 | 5.1073781, 22 | 6.5411662, 23 | 6.7216176, 24 | 7.2600583, 25 | 8.1335874, 26 | 9.1224379, 27 | 11.9296663, 28 | 12.3797674, 29 | 13.2728619, 30 | 14.2767453, 31 | 15.3731026, 32 | 15.6476637, 33 | 18.5605355, 34 | 18.5866354, 35 | 18.7572812, 36 | } 37 | ys := []float64{18.63654, 38 | 103.49646, 39 | 150.35391, 40 | 190.51031, 41 | 208.70115, 42 | 213.71135, 43 | 228.49353, 44 | 233.55387, 45 | 234.55054, 46 | 223.89225, 47 | 227.68339, 48 | 223.91982, 49 | 168.01999, 50 | 164.95750, 51 | 152.61107, 52 | 160.78742, 53 | 168.55567, 54 | 152.42658, 55 | 221.70702, 56 | 222.69040, 57 | 243.18828, 58 | } 59 | 60 | defer mathtest.SetAeqDigits(mathtest.SetAeqDigits(7)) 61 | mathtest.WantFunc(t, "LOESS", LOESS(xs, ys, 1, 0.33), 62 | map[float64]float64{ 63 | 0.5578196: 20.59302, 64 | 2.0217271: 107.1603, 65 | 2.5773252: 139.7674, 66 | 3.4140288: 174.2630, 67 | 4.301408: 207.2334, 68 | 4.744839: 216.6616, 69 | 5.107378: 220.5445, 70 | 6.541166: 229.8607, 71 | 6.721618: 229.8347, 72 | 7.260058: 229.4301, 73 | 8.133587: 226.6045, 74 | 9.122438: 220.3904, 75 | 11.929666: 172.3480, 76 | 12.379767: 163.8417, 77 | 13.272862: 161.8490, 78 | 14.27675: 160.3351, 79 | 15.37310: 160.1920, 80 | 15.64766: 161.0556, 81 | 18.56054: 227.3400, 82 | 18.58664: 227.8985, 83 | 18.75728: 231.5586, 84 | }) 85 | } 86 | -------------------------------------------------------------------------------- /benchscripts/bench-many: -------------------------------------------------------------------------------- 1 | #!/bin/zsh 2 | 3 | set -e 4 | 5 | if [[ $# != 3 ]]; then 6 | echo "usage: bench-many rev-file out-dir iterations" >&2 7 | exit 1 8 | fi 9 | 10 | revFile=$(realpath $1) 11 | outDir=$2 12 | iterations=$3 13 | mkdir -p $outDir/by-rev 14 | mkdir -p $outDir/by-date 15 | outDir=$(realpath $outDir) 16 | GOROOT=$(go env GOROOT) 17 | GOTOOLDIR=$(go env GOTOOLDIR) 18 | 19 | # Build benchmarks 20 | cat $revFile | while read rev; do 21 | cd $GOROOT 22 | rev=$(git rev-parse $rev) 23 | revOut=$outDir/by-rev/$rev 24 | if [[ -x $revOut/go1.test && -x $revOut/6g && -x $revOut/xbench ]]; then 25 | continue 26 | fi 27 | 28 | echo "Building $rev" 29 | git checkout -q $rev > $outDir/log 30 | (cd $GOROOT/src && ./make.bash) >> $outDir/log 2>&1 31 | 32 | if [[ ! -x $revOut/6g ]]; then 33 | cp $GOTOOLDIR/6g $revOut/6g 34 | fi 35 | 36 | if [[ ! -x $revOut/go1.test ]]; then 37 | cd $GOROOT/test/bench/go1 38 | go test -c >> $outDir/log 39 | mkdir -p $revOut 40 | mv go1.test $revOut/go1.test 41 | fi 42 | 43 | if [[ ! -x $revOut/xbench ]]; then 44 | go build -o $revOut/xbench golang.org/x/benchmarks/bench 45 | fi 46 | done 47 | 48 | # Make date symlinks 49 | cat $revFile | while read rev; do 50 | rev=$(git rev-parse $rev) 51 | date=$(git log -n1 --format='%cI' $rev | sed 's/+00:00$//') 52 | ln -snf ../by-rev/$rev $outDir/by-date/$date 53 | done 54 | 55 | # Run benchmarks 56 | for i in {1..$iterations}; do 57 | cat $revFile | while read rev; do 58 | cd $GOROOT 59 | rev=$(git rev-parse $rev) 60 | cd $outDir/by-rev/$rev 61 | logName=go1.out.$(printf %03d $i) 62 | if [[ -f $logName ]]; then 63 | continue 64 | fi 65 | echo "$rev ($i)" 66 | ./go1.test -test.bench . > go1.out.tmp 67 | mv go1.out.tmp $logName 68 | done 69 | done 70 | 71 | # TODO: Run 6g "benchmark" (with gctrace=1) 72 | # TODO: Run x/bench benchmarks (with gctrace=1) 73 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/stats/util_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package stats 6 | 7 | import ( 8 | "fmt" 9 | "testing" 10 | 11 | "github.com/aclements/go-moremath/internal/mathtest" 12 | "github.com/aclements/go-moremath/vec" 13 | ) 14 | 15 | var aeq = mathtest.Aeq 16 | var testFunc = mathtest.WantFunc 17 | 18 | func testDiscreteCDF(t *testing.T, name string, dist DiscreteDist) { 19 | // Build the expected CDF out of the PMF. 20 | l, h := dist.Bounds() 21 | s := dist.Step() 22 | want := map[float64]float64{l - 0.1: 0, h: 1} 23 | sum := 0.0 24 | for x := l; x < h; x += s { 25 | sum += dist.PMF(x) 26 | want[x] = sum 27 | want[x+s/2] = sum 28 | } 29 | 30 | testFunc(t, name, dist.CDF, want) 31 | } 32 | 33 | func testInvCDF(t *testing.T, dist Dist, bounded bool) { 34 | inv := InvCDF(dist) 35 | name := fmt.Sprintf("InvCDF(%+v)", dist) 36 | cdfName := fmt.Sprintf("CDF(%+v)", dist) 37 | 38 | // Test bounds. 39 | vals := map[float64]float64{-0.01: nan, 1.01: nan} 40 | if !bounded { 41 | vals[0] = -inf 42 | vals[1] = inf 43 | } 44 | testFunc(t, name, inv, vals) 45 | 46 | if bounded { 47 | lo, hi := inv(0), inv(1) 48 | vals := map[float64]float64{ 49 | lo - 0.01: 0, lo: 0, 50 | hi: 1, hi + 0.01: 1, 51 | } 52 | testFunc(t, cdfName, dist.CDF, vals) 53 | if got := dist.CDF(lo + 0.01); !(got > 0) { 54 | t.Errorf("%s(0)=%v, but %s(%v)=0", name, lo, cdfName, lo+0.01) 55 | } 56 | if got := dist.CDF(hi - 0.01); !(got < 1) { 57 | t.Errorf("%s(1)=%v, but %s(%v)=1", name, hi, cdfName, hi-0.01) 58 | } 59 | } 60 | 61 | // Test points between. 62 | vals = map[float64]float64{} 63 | for _, p := range vec.Linspace(0, 1, 11) { 64 | if p == 0 || p == 1 { 65 | continue 66 | } 67 | x := inv(p) 68 | vals[x] = x 69 | } 70 | testFunc(t, fmt.Sprintf("InvCDF(CDF(%+v))", dist), 71 | func(x float64) float64 { 72 | return inv(dist.CDF(x)) 73 | }, 74 | vals) 75 | } 76 | -------------------------------------------------------------------------------- /split/bench_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package split 6 | 7 | import ( 8 | "runtime" 9 | "sync" 10 | "sync/atomic" 11 | "testing" 12 | ) 13 | 14 | func BenchmarkCounterSplitAtomic(b *testing.B) { 15 | // Benchmark a simple split counter updating using atomics. 16 | counter := New(func(*uint64) {}) 17 | 18 | b.RunParallel(func(pb *testing.PB) { 19 | for pb.Next() { 20 | atomic.AddUint64(counter.Get().(*uint64), 1) 21 | } 22 | }) 23 | } 24 | 25 | func BenchmarkCounterSplitLocked(b *testing.B) { 26 | // Benchmark a simple split counter using locking instead of atomics. 27 | type shard struct { 28 | sync.Mutex 29 | val uint64 30 | } 31 | counter := New(func(*shard) {}) 32 | 33 | b.RunParallel(func(pb *testing.PB) { 34 | for pb.Next() { 35 | s := counter.Get().(*shard) 36 | s.Lock() 37 | s.val++ 38 | s.Unlock() 39 | } 40 | }) 41 | } 42 | 43 | func BenchmarkCounterShared(b *testing.B) { 44 | // Non-sharded version of BenchmarkCounter. 45 | var counter uint64 46 | 47 | b.RunParallel(func(pb *testing.PB) { 48 | for pb.Next() { 49 | atomic.AddUint64(&counter, 1) 50 | } 51 | }) 52 | } 53 | 54 | var seqCounter uint64 55 | 56 | func BenchmarkCounterSequential(b *testing.B) { 57 | // Sequential version of BenchmarkCounter without atomics. For 58 | // fair comparison with the cost of uncontended atomics, this 59 | // only runs at -test.cpu=1 and uses the RunParallel mechanics 60 | // so the overheads are the same (pb.Next gets inlined and has 61 | // no atomic ops in the fast path, so this is pretty small). 62 | if runtime.GOMAXPROCS(-1) != 1 { 63 | b.Skip("requires -test.cpu=1") 64 | } 65 | b.RunParallel(func(pb *testing.PB) { 66 | for pb.Next() { 67 | seqCounter++ 68 | } 69 | }) 70 | } 71 | 72 | func BenchmarkRWMutex(b *testing.B) { 73 | var m RWMutex 74 | 75 | b.RunParallel(func(pb *testing.PB) { 76 | for pb.Next() { 77 | m.RLock().RUnlock() 78 | } 79 | }) 80 | } 81 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/palette/palette.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package palette provides palettes and ways to define palettes. 6 | package palette 7 | 8 | import ( 9 | "image/color" 10 | "math" 11 | "sort" 12 | ) 13 | 14 | // TODO: Unify continuous and discrete palettes so functions can 15 | // operate on both? Perhaps treat a continuous like a discrete with a 16 | // large number of levels (and a "type" function indicating that it's 17 | // okay to blend between neighboring colors.) 18 | 19 | // A Continuous palette is a function from [0, 1] to colors. It may be 20 | // sequential, diverging, or circular. 21 | type Continuous interface { 22 | Map(x float64) color.Color 23 | } 24 | 25 | // RGBGradient is a Continuous palette that interpolates between a 26 | // sequence of colors. 27 | type RGBGradient struct { 28 | // Colors is the sequence of colors to interpolate between. 29 | // Interpolation assumes the colors are sRGB values. 30 | Colors []color.RGBA 31 | 32 | // Stops is an optional sequence of stop positions. It may be 33 | // nil, in which case Colors are evenly spaced on the interval 34 | // [0, 1]. Otherwise, it must be a slice with the same length 35 | // as Colors and must be in ascending order. 36 | Stops []float64 37 | } 38 | 39 | func (g RGBGradient) Map(x float64) color.Color { 40 | if g.Stops == nil { 41 | n := x * float64(len(g.Colors)-1) 42 | ip, fr := math.Modf(n) 43 | i := int(ip) 44 | if i <= 0 { 45 | return g.Colors[0] 46 | } else if i >= len(g.Colors)-1 { 47 | return g.Colors[len(g.Colors)-1] 48 | } 49 | a, b := g.Colors[i], g.Colors[i+1] 50 | return blendRGBA(a, b, fr) 51 | } 52 | 53 | i := sort.SearchFloat64s(g.Stops, x) 54 | if i == 0 { 55 | return g.Colors[0] 56 | } else if i >= len(g.Colors)-1 { 57 | return g.Colors[len(g.Colors)-1] 58 | } 59 | fr := (g.Stops[i] - x) / (g.Stops[i+1] - g.Stops[i]) 60 | a, b := g.Colors[i], g.Colors[i+1] 61 | return blendRGBA(a, b, fr) 62 | } 63 | -------------------------------------------------------------------------------- /minutes3/README.md: -------------------------------------------------------------------------------- 1 | # Generate Google Sheets token 2 | 3 | Go to https://console.developers.google.com/. 4 | 5 | Create a new GCP project. I called mine `proposal-minutes`. 6 | 7 | Configure the OAuth consent screen: Go to APIs & Services > OAuth consent 8 | screen. Select "Internal" and click "Create". Enter an app name. I called it 9 | `proposal-minutes`. Fill in other required fields, though most can be left 10 | blank. Click "Save and continue". You don't need to add any scopes. Click "Save 11 | and continue". 12 | 13 | Enable Google Sheets: Go to APIs & Services > Enabled APIs and Services. Click 14 | "Enable APIs and Services". Search for the "Google Sheets API" and enable it. 15 | 16 | Create OAuth credentials: Go to APIs & Services > Credentials. Click Create 17 | Credentials > OAuth client ID. Select "Desktop app", give it a name (I used 18 | `proposal-minutes`, again), and click Create. On the next screen, click 19 | "Download JSON" and save this file as `~/.config/proposal-minutes/gdoc.json`. 20 | 21 | Enable write scope for spreadsheets: Go to APIs & Services > OAuth consent 22 | screen > Data Access and click "Add or remove scopes". Add the 23 | `https://www.googleapis.com/auth/spreadsheets` scope, either by finding it in 24 | the table of known scopes or by manually entering it. Click "Update". Finally, 25 | click "Save" on the Data Access page. (Note: If you already had a cached OAuth 26 | token, you'll have to delete it.) 27 | 28 | # Generate GitHub token 29 | 30 | Go to GitHub, then Account Settings > Developer Options > Personal Access 31 | Tokens > Fine-grained Tokens. 32 | 33 | Click "Generate new token" 34 | 35 | The name of the token can be anything. I used `proposal-minutes`. The expiration 36 | can be set up to one year out. 37 | 38 | Set the "Resource owner" to "golang", then select "Only select repositories" and 39 | add the "golang/go" repository. 40 | 41 | Under "Repository permissions", set "Issues" to "Read and write". 42 | 43 | Under "Organization permissions", set "Projects" to "Read and write". 44 | 45 | Save the token. 46 | 47 | Copy the access token and save it to `~/.config/proposal-minutes/github.tok`. 48 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/generic/slice/index.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package slice 6 | 7 | import ( 8 | "reflect" 9 | 10 | "github.com/aclements/go-gg/generic" 11 | ) 12 | 13 | // Select returns a slice w such that w[i] = v[indexes[i]]. 14 | func Select(v T, indexes []int) T { 15 | switch v := v.(type) { 16 | case []int: 17 | res := make([]int, len(indexes)) 18 | for i, x := range indexes { 19 | res[i] = v[x] 20 | } 21 | return res 22 | 23 | case []float64: 24 | res := make([]float64, len(indexes)) 25 | for i, x := range indexes { 26 | res[i] = v[x] 27 | } 28 | return res 29 | 30 | case []string: 31 | res := make([]string, len(indexes)) 32 | for i, x := range indexes { 33 | res[i] = v[x] 34 | } 35 | return res 36 | } 37 | 38 | rv := reflectSlice(v) 39 | res := reflect.MakeSlice(rv.Type(), len(indexes), len(indexes)) 40 | for i, x := range indexes { 41 | res.Index(i).Set(rv.Index(x)) 42 | } 43 | return res.Interface() 44 | } 45 | 46 | // SelectInto assigns out[i] = in[indexes[i]]. in and out must have 47 | // the same types and len(out) must be >= len(indexes). If in and out 48 | // overlap, the results are undefined. 49 | func SelectInto(out, in T, indexes []int) { 50 | // TODO: Maybe they should only have to be assignable? 51 | if it, ot := reflect.TypeOf(in), reflect.TypeOf(out); it != ot { 52 | panic(&generic.TypeError{it, ot, "must be the same type"}) 53 | } 54 | 55 | switch in := in.(type) { 56 | case []int: 57 | out := out.([]int) 58 | for i, x := range indexes { 59 | out[i] = in[x] 60 | } 61 | return 62 | 63 | case []float64: 64 | out := out.([]float64) 65 | for i, x := range indexes { 66 | out[i] = in[x] 67 | } 68 | return 69 | 70 | case []string: 71 | out := out.([]string) 72 | for i, x := range indexes { 73 | out[i] = in[x] 74 | } 75 | return 76 | } 77 | 78 | inv, outv := reflectSlice(in), reflectSlice(out) 79 | for i, x := range indexes { 80 | outv.Index(i).Set(inv.Index(x)) 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/vec/vec.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package vec 6 | 7 | import "math" 8 | 9 | // Vectorize returns a function g(xs) that applies f to each x in xs. 10 | // 11 | // f may be evaluated in parallel and in any order. 12 | func Vectorize(f func(float64) float64) func(xs []float64) []float64 { 13 | return func(xs []float64) []float64 { 14 | return Map(f, xs) 15 | } 16 | } 17 | 18 | // Map returns f(x) for each x in xs. 19 | // 20 | // f may be evaluated in parallel and in any order. 21 | func Map(f func(float64) float64, xs []float64) []float64 { 22 | // TODO(austin) Parallelize 23 | res := make([]float64, len(xs)) 24 | for i, x := range xs { 25 | res[i] = f(x) 26 | } 27 | return res 28 | } 29 | 30 | // Linspace returns num values spaced evenly between lo and hi, 31 | // inclusive. If num is 1, this returns an array consisting of lo. 32 | func Linspace(lo, hi float64, num int) []float64 { 33 | res := make([]float64, num) 34 | if num == 1 { 35 | res[0] = lo 36 | return res 37 | } 38 | for i := 0; i < num; i++ { 39 | res[i] = lo + float64(i)*(hi-lo)/float64(num-1) 40 | } 41 | return res 42 | } 43 | 44 | // Logspace returns num values spaced evenly on a logarithmic scale 45 | // between base**lo and base**hi, inclusive. 46 | func Logspace(lo, hi float64, num int, base float64) []float64 { 47 | res := Linspace(lo, hi, num) 48 | for i, x := range res { 49 | res[i] = math.Pow(base, x) 50 | } 51 | return res 52 | } 53 | 54 | // Sum returns the sum of xs. 55 | func Sum(xs []float64) float64 { 56 | sum := 0.0 57 | for _, x := range xs { 58 | sum += x 59 | } 60 | return sum 61 | } 62 | 63 | // Concat returns the concatenation of its arguments. It does not 64 | // modify its inputs. 65 | func Concat(xss ...[]float64) []float64 { 66 | total := 0 67 | for _, xs := range xss { 68 | total += len(xs) 69 | } 70 | out := make([]float64, total) 71 | pos := 0 72 | for _, xs := range xss { 73 | pos += copy(out[pos:], xs) 74 | } 75 | return out 76 | } 77 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/ggstat/lsquares.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ggstat 6 | 7 | import ( 8 | "github.com/aclements/go-gg/generic/slice" 9 | "github.com/aclements/go-gg/table" 10 | "github.com/aclements/go-moremath/fit" 11 | "github.com/aclements/go-moremath/vec" 12 | ) 13 | 14 | // LeastSquares constructs a least squares polynomial regression for 15 | // the data (X, Y). 16 | // 17 | // X and Y are required. All other fields have reasonable default zero 18 | // values. 19 | // 20 | // The result of LeastSquares has two columns in addition to constant 21 | // columns from the input: 22 | // 23 | // - Column X is the points at which the fit function is sampled. 24 | // 25 | // - Column Y is the result of the fit function. 26 | // 27 | // TODO: Confidence internals/bootstrap distributions? 28 | type LeastSquares struct { 29 | // X and Y are the names of the columns to use for X and Y 30 | // values of data points, respectively. 31 | X, Y string 32 | 33 | // N is the number of points to sample the regression at. If N 34 | // is 0, a reasonable default is used. 35 | N int 36 | 37 | // Domain specifies the domain at which to sample this function. 38 | // If Domain is nil, it defaults to DomainData{}. 39 | Domain FunctionDomainer 40 | 41 | // Degree specifies the degree of the fit polynomial. If it is 42 | // 0, it is treated as 1. 43 | Degree int 44 | } 45 | 46 | func (s LeastSquares) F(g table.Grouping) table.Grouping { 47 | if s.Degree <= 0 { 48 | s.Degree = 1 49 | } 50 | 51 | var xs, ys []float64 52 | return Function{ 53 | X: s.X, N: s.N, Domain: s.Domain, 54 | Fn: func(gid table.GroupID, in *table.Table, sampleAt []float64, out *table.Builder) { 55 | if len(sampleAt) == 0 { 56 | out.Add(s.Y, []float64{}) 57 | return 58 | } 59 | 60 | slice.Convert(&xs, in.MustColumn(s.X)) 61 | slice.Convert(&ys, in.MustColumn(s.Y)) 62 | 63 | r := fit.PolynomialRegression(xs, ys, nil, s.Degree) 64 | out.Add(s.Y, vec.Map(r.F, sampleAt)) 65 | }, 66 | }.F(g) 67 | } 68 | -------------------------------------------------------------------------------- /pcvaluetab/enc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | // Raw file encodings of symbol table types from Go 1.21. 8 | 9 | type rawPCHeader1 struct { 10 | Magic uint32 // 0xFFFFFFF1 11 | Pad1, Pad2 uint8 // 0,0 12 | MinLC uint8 // min instruction size 13 | PtrSize uint8 // size of a ptr in bytes 14 | } 15 | 16 | type rawPCHeader struct { 17 | rawPCHeader1 18 | Nfunc int // number of functions in the module 19 | Nfiles uint // number of entries in the file tab 20 | TextStart uintptr // base for function entry PC offsets in this module, equal to moduledata.text 21 | FuncnameOffset uintptr // offset to the funcnametab variable from pcHeader 22 | CuOffset uintptr // offset to the cutab variable from pcHeader 23 | FiletabOffset uintptr // offset to the filetab variable from pcHeader 24 | PctabOffset uintptr // offset to the pctab variable from pcHeader 25 | PclnOffset uintptr // offset to the pclntab variable from pcHeader 26 | } 27 | 28 | type rawFunc struct { 29 | EntryOff uint32 // start pc, as offset from moduledata.text/pcHeader.textStart 30 | NameOff int32 // function name, as index into moduledata.funcnametab. 31 | 32 | Args int32 // in/out args size 33 | Deferreturn uint32 // offset of start of a deferreturn call instruction from entry, if any. 34 | 35 | Pcsp uint32 36 | Pcfile uint32 37 | Pcln uint32 38 | Npcdata uint32 39 | CuOffset uint32 // runtime.cutab offset of this function's CU 40 | StartLine int32 // line number of start of function (func keyword/TEXT directive) 41 | FuncID rawABIFuncID // set for certain special runtime functions 42 | Flag rawABIFuncFlag 43 | Pad [1]byte // pad 44 | Nfuncdata uint8 // must be last, must end on a uint32-aligned boundary 45 | 46 | // Followed by Npcdata 4-byte offsets into pctab, then 47 | // Nfuncdata 4-byte offsets into moduledata.gofunc. 48 | // Padded to PtrSize. 49 | } 50 | 51 | type rawABIFuncID uint8 52 | type rawABIFuncFlag uint8 53 | -------------------------------------------------------------------------------- /split/README.md: -------------------------------------------------------------------------------- 1 | This package is a prototype implementation of split (or "sharded") 2 | values for Go. This is a possible solution to 3 | https://github.com/golang/go/issues/18802. 4 | 5 | [![](https://godoc.org/github.com/aclements/go-misc/split?status.svg)](https://godoc.org/github.com/aclements/go-misc/split) 6 | 7 | This prototype is very dependent on Go runtime internals. As is, it 8 | does not depend on any *modifications* to the Go runtime; however, 9 | there is an optional runtime modification that shaves about 4ns off 10 | the cost of `Value.Get`. See that method for details. 11 | 12 | Benchmarks 13 | ---------- 14 | 15 | With the runtime modification, the single-core overhead of the split 16 | value compared to a single atomic counter is about 2 ns, and compared 17 | to a non-atomic counter is about 6 ns: 18 | 19 | ``` 20 | BenchmarkCounterSplit 200000000 8.15 ns/op 21 | BenchmarkCounterShared 300000000 5.96 ns/op 22 | BenchmarkCounterSequential 1000000000 2.14 ns/op 23 | BenchmarkLazyAggregationSplit 100000000 23.9 ns/op 24 | BenchmarkLazyAggregationShared 100000000 23.1 ns/op 25 | ``` 26 | 27 | The scaling of the split values to 24 cores is nearly perfect (real 28 | cores, no hyperthreads), while the shared values collapse as you'd 29 | expect: 30 | 31 | ``` 32 | BenchmarkCounterSplit-24 2000000000 0.35 ns/op 8.40 cpu-ns/op 33 | BenchmarkCounterShared-24 50000000 24.7 ns/op 593 cpu-ns/op 34 | BenchmarkLazyAggregationSplit-24 2000000000 1.03 ns/op 24.7 cpu-ns/op 35 | BenchmarkLazyAggregationShared-24 10000000 174 ns/op 4176 cpu-ns/op 36 | ``` 37 | 38 | Without the runtime modification, there's a little more overhead in 39 | the sequential case, but the scaling isn't affected: 40 | 41 | ``` 42 | BenchmarkCounterSplit 100000000 12.3 ns/op 43 | BenchmarkCounterShared 300000000 5.97 ns/op 44 | BenchmarkCounterSequential 1000000000 2.28 ns/op 45 | BenchmarkLazyAggregationSplit 50000000 25.2 ns/op 46 | BenchmarkLazyAggregationShared 100000000 23.5 ns/op 47 | ``` 48 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/scale/interface.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package scale 6 | 7 | // A Quantative scale is an invertible function from some continuous 8 | // input domain to an output range of [0, 1]. 9 | type Quantitative interface { 10 | // Map maps from a value x in the input domain to [0, 1]. If x 11 | // is outside the input domain and clamping is enabled, x will 12 | // first be clamped to the input domain. 13 | Map(x float64) float64 14 | 15 | // Unmap is the inverse of Map. That is, if x is in the input 16 | // domain or clamping is disabled, x = Unmap(Map(x)). If 17 | // clamping is enabled and y is outside [0,1], the results are 18 | // undefined. 19 | Unmap(y float64) float64 20 | 21 | // SetClamp sets the clamping mode of this scale. 22 | SetClamp(bool) 23 | 24 | // Ticks returns major and minor ticks that satisfy the 25 | // constraints given by o. These ticks will have "nice" values 26 | // within the input domain. Both arrays are sorted in 27 | // ascending order and minor includes ticks in major. 28 | Ticks(o TickOptions) (major, minor []float64) 29 | 30 | // Nice expands the input domain of this scale to "nice" 31 | // values for covering the input domain satisfying the 32 | // constraints given by o. After calling Nice(o), the first 33 | // and last major ticks returned by Ticks(o) will equal the 34 | // lower and upper bounds of the input domain. 35 | Nice(o TickOptions) 36 | 37 | // A Quantitative scale is also a Ticker. 38 | Ticker 39 | } 40 | 41 | // A QQ maps from a source Quantitative scale to a destination 42 | // Quantitative scale. 43 | type QQ struct { 44 | Src, Dest Quantitative 45 | } 46 | 47 | // Map maps from a value x in the source scale's input domain to a 48 | // value y in the destination scale's input domain. 49 | func (q QQ) Map(x float64) float64 { 50 | return q.Dest.Unmap(q.Src.Map(x)) 51 | } 52 | 53 | // Unmap maps from a value y in the destination scale's input domain to 54 | // a value x in the source scale's input domain. 55 | func (q QQ) Unmap(x float64) float64 { 56 | return q.Src.Unmap(q.Dest.Map(x)) 57 | } 58 | -------------------------------------------------------------------------------- /findflakes/text.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "fmt" 9 | "io" 10 | ) 11 | 12 | func round(x float64) int { 13 | return int(x + 0.5) 14 | } 15 | 16 | func pct(x float64) string { 17 | p := 100 * x 18 | if p >= 9.5 { 19 | return fmt.Sprintf("%.0f%%", p) 20 | } else if p > 0.95 { 21 | return fmt.Sprintf("%.1f%%", p) 22 | } else { 23 | return fmt.Sprintf("%.2f%%", p) 24 | } 25 | } 26 | 27 | func printTextReport(w io.Writer, classes []*failureClass) { 28 | for _, fc := range classes { 29 | fmt.Fprintf(w, "%s\n", fc.Class) 30 | printTextFlakeReport(w, fc) 31 | fmt.Fprintln(w) 32 | } 33 | } 34 | 35 | func printTextFlakeReport(w io.Writer, fc *failureClass) { 36 | // TODO: Report deterministic failures better. 37 | // 38 | // TODO: Report observed OSs/Arches 39 | 40 | fmt.Fprintf(w, "First observed %s (%d commits ago)\n", fc.Revs[fc.Latest.First], len(fc.Revs)-fc.Latest.First-1) 41 | fmt.Fprintf(w, "Last observed %s (%d commits ago)\n", fc.Revs[fc.Latest.Last], len(fc.Revs)-fc.Latest.Last-1) 42 | if fc.Latest.First == fc.Latest.Last { 43 | fmt.Fprintf(w, "Isolated failure\n") 44 | } else { 45 | fmt.Fprintf(w, "%s chance failure is still happening\n", pct(fc.Current)) 46 | fmt.Fprintf(w, "%s failure probability (%d of %d commits)\n", pct(fc.Latest.FailureProbability), fc.Latest.Failures, fc.Latest.Last-fc.Latest.First+1) 47 | fmt.Fprintf(w, "Likely culprits:\n") 48 | for _, c := range fc.Latest.Culprits(0.9, 10) { 49 | fmt.Fprintf(w, " %3d%% %s\n", round(100*c.P), fc.Revs[c.T].OneLine()) 50 | } 51 | } 52 | 53 | if len(fc.Test.All) > 1 { 54 | fmt.Fprintf(w, "Past failures:\n") 55 | for _, reg := range fc.Test.All[1:] { 56 | if reg.First == reg.Last { 57 | rev := fc.Revs[reg.First] 58 | fmt.Fprintf(w, " %s (isolated failure)\n", rev) 59 | } else { 60 | fmt.Fprintf(w, " %s to %s\n", fc.Revs[reg.First], fc.Revs[reg.Last]) 61 | fmt.Fprintf(w, " %s failure probability (%d of %d commits)\n", pct(reg.FailureProbability), reg.Failures, reg.Last-reg.First+1) 62 | } 63 | } 64 | } else { 65 | fmt.Fprintf(w, "No known past failures\n") 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/stats/hist.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package stats 6 | 7 | import "math" 8 | 9 | // TODO: Implement histograms on top of scales. 10 | 11 | type Histogram interface { 12 | // Add adds a sample with value x to histogram h. 13 | Add(x float64) 14 | 15 | // Counts returns the number of samples less than the lowest 16 | // bin, a slice of the number of samples in each bin, 17 | // and the number of samples greater than the highest bin. 18 | Counts() (under uint, counts []uint, over uint) 19 | 20 | // BinToValue returns the value that would appear at the given 21 | // bin index. 22 | // 23 | // For integral values of bin, BinToValue returns the lower 24 | // bound of bin. That is, a sample value x will be in bin if 25 | // bin is integral and 26 | // 27 | // BinToValue(bin) <= x < BinToValue(bin + 1) 28 | // 29 | // For non-integral values of bin, BinToValue interpolates 30 | // between the lower and upper bounds of math.Floor(bin). 31 | // 32 | // BinToValue is undefined if bin > 1 + the number of bins. 33 | BinToValue(bin float64) float64 34 | } 35 | 36 | // HistogramQuantile returns the x such that n*q samples in hist are 37 | // <= x, assuming values are distibuted within each bin according to 38 | // hist's distribution. 39 | // 40 | // If the q'th sample falls below the lowest bin or above the highest 41 | // bin, returns NaN. 42 | func HistogramQuantile(hist Histogram, q float64) float64 { 43 | under, counts, over := hist.Counts() 44 | total := under + over 45 | for _, count := range counts { 46 | total += count 47 | } 48 | 49 | goal := uint(float64(total) * q) 50 | if goal <= under || goal > total-over { 51 | return math.NaN() 52 | } 53 | for bin, count := range counts { 54 | if count > goal { 55 | return hist.BinToValue(float64(bin) + float64(goal)/float64(count)) 56 | } 57 | goal -= count 58 | } 59 | panic("goal count not reached") 60 | } 61 | 62 | // HistogramIQR returns the interquartile range of the samples in 63 | // hist. 64 | func HistogramIQR(hist Histogram) float64 { 65 | return HistogramQuantile(hist, 0.75) - HistogramQuantile(hist, 0.25) 66 | } 67 | -------------------------------------------------------------------------------- /abi/go.sum: -------------------------------------------------------------------------------- 1 | github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 2 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 3 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 4 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 5 | golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= 6 | golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 7 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 8 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 9 | golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= 10 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 11 | golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 12 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 13 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 14 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 15 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 16 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 17 | golang.org/x/tools v0.0.0-20200815165600-90abf76919f3 h1:0aScV/0rLmANzEYIhjCOi2pTvDyhZNduBUMD2q3iqs4= 18 | golang.org/x/tools v0.0.0-20200815165600-90abf76919f3/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= 19 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 20 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 21 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= 22 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 23 | -------------------------------------------------------------------------------- /git-p/pager.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "fmt" 9 | "os" 10 | "os/exec" 11 | "syscall" 12 | 13 | "golang.org/x/term" 14 | ) 15 | 16 | // setupPager restarts this process under the git pager. If the 17 | // process is already under a pager or doesn't want a pager, it 18 | // returns. 19 | // 20 | // setupPager returns true if this process is running in a smart 21 | // terminal (which includes running under a pager started by 22 | // setupPager). 23 | func setupPager() (inTerm bool) { 24 | // This is roughly based on pager.c:setup_pager in git, but 25 | // this starts ourselves as a subprocess instead of the pager. 26 | // Doing it this way around means we don't have to babysit the 27 | // pager: signals/panics kill us like normal and leave the 28 | // pager running and the shell waiting on the pager. 29 | 30 | if os.Getenv("GIT_P_PAGER_IN_USE") != "" { 31 | return true 32 | } 33 | if !term.IsTerminal(1) { 34 | return false 35 | } 36 | switch os.Getenv("TERM") { 37 | case "", "dumb": 38 | return false 39 | } 40 | 41 | pagerCmd := git("var", "GIT_PAGER") 42 | if pagerCmd == "" { 43 | return true 44 | } 45 | 46 | // Start ourselves as a subprocess. 47 | me, err := os.Executable() 48 | if err != nil { 49 | return true 50 | } 51 | os.Setenv("GIT_P_PAGER_IN_USE", "true") 52 | cmd := exec.Command(me, os.Args[1:]...) 53 | r, w, err := os.Pipe() 54 | if err != nil { 55 | return true 56 | } 57 | cmd.Stdin = nil 58 | cmd.Stdout = w 59 | cmd.Stderr = w 60 | cmd.Start() 61 | 62 | // Replace this process with the pager. 63 | w.Close() 64 | syscall.Dup2(int(r.Fd()), 0) 65 | r.Close() 66 | // We need -R at least to interpret color codes. 67 | // Add -F so single-screen output doesn't invoke paging. 68 | os.Setenv("LESS", "-FR "+os.Getenv("LESS")) 69 | if os.Getenv("LV") == "" { 70 | os.Setenv("LV", "-c") 71 | } 72 | err = syscall.Exec("/bin/sh", []string{"sh", "-c", pagerCmd}, os.Environ()) 73 | 74 | // Didn't work, but there's not much we can do now. Try cat. 75 | syscall.Exec("/bin/cat", []string{"cat"}, os.Environ()) 76 | 77 | // Still didn't work. Bail. 78 | panic(fmt.Sprintf("failed to start pager: %s", err)) 79 | } 80 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/table/join.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package table 6 | 7 | import ( 8 | "reflect" 9 | 10 | "github.com/aclements/go-gg/generic/slice" 11 | ) 12 | 13 | // Join joins g1 and g2 on tables with identical group IDs where col1 14 | // in g1 equals col2 in g2. It maintains the group order of g1, except 15 | // that groups that aren't in g2 are removed, and maintains the row 16 | // order of g1, followed by the row order of g2. 17 | // 18 | // TODO: Support join on more than one column. 19 | func Join(g1 Grouping, col1 string, g2 Grouping, col2 string) Grouping { 20 | var ng GroupingBuilder 21 | for _, gid := range g1.Tables() { 22 | t1, t2 := g1.Table(gid), g2.Table(gid) 23 | if t2 == nil { 24 | continue 25 | } 26 | 27 | // TODO: Optimize for cases where col1 and/or col2 are 28 | // constant. 29 | 30 | // Index col2 in t2. 31 | ridx := make(map[interface{}][]int) 32 | rv := reflect.ValueOf(t2.MustColumn(col2)) 33 | for i, l := 0, rv.Len(); i < l; i++ { 34 | v := rv.Index(i).Interface() 35 | ridx[v] = append(ridx[v], i) 36 | } 37 | 38 | // For each row in t1, find the matching rows in col2 39 | // and build up the row indexes for t1 and t2. 40 | idx1, idx2 := []int{}, []int{} 41 | lv := reflect.ValueOf(t1.MustColumn(col1)) 42 | for i, l := 0, lv.Len(); i < l; i++ { 43 | r := ridx[lv.Index(i).Interface()] 44 | for range r { 45 | idx1 = append(idx1, i) 46 | } 47 | idx2 = append(idx2, r...) 48 | } 49 | 50 | // Build the joined table. 51 | var nt Builder 52 | for _, col := range t1.Columns() { 53 | if cv, ok := t1.Const(col); ok { 54 | nt.Add(col, cv) 55 | continue 56 | } 57 | nt.Add(col, slice.Select(t1.Column(col), idx1)) 58 | } 59 | for _, col := range t2.Columns() { 60 | // Often the join column is the same in both 61 | // and we can skip it because we added it from 62 | // the first table. 63 | if col == col1 && col == col2 { 64 | continue 65 | } 66 | 67 | if cv, ok := t2.Const(col); ok { 68 | nt.Add(col, cv) 69 | continue 70 | } 71 | nt.Add(col, slice.Select(t2.Column(col), idx2)) 72 | } 73 | 74 | ng.Add(gid, nt.Done()) 75 | } 76 | return ng.Done() 77 | } 78 | -------------------------------------------------------------------------------- /go-weave/amb/det.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package amb 6 | 7 | import "fmt" 8 | 9 | // StrategyDFS explores the ambiguous value space in depth-first order 10 | // up to MaxDepth. It is deterministic and (given enough time) will 11 | // explore the entire space. 12 | type StrategyDFS struct { 13 | // MaxDepth specifies the maximum depth of the tree. If this 14 | // is 0, it defaults to DefaultMaxDepth. 15 | MaxDepth int 16 | 17 | branchWidths []int 18 | curPath []int 19 | step int 20 | } 21 | 22 | func (s *StrategyDFS) Reset() { 23 | s.branchWidths = nil 24 | s.curPath = nil 25 | s.step = 0 26 | } 27 | 28 | func (s *StrategyDFS) maxDepth() int { 29 | if s.MaxDepth == 0 { 30 | return DefaultMaxDepth 31 | } 32 | return s.MaxDepth 33 | } 34 | 35 | func (s *StrategyDFS) Amb(n int) (int, bool) { 36 | if s.step < len(s.curPath) { 37 | // We're in replay mode. 38 | if n != s.branchWidths[s.step] { 39 | panic(&ErrNondeterminism{fmt.Sprintf("Amb(%d) during replay, but previous call was Amb(%d)", n, s.branchWidths[s.step])}) 40 | } 41 | res := s.curPath[s.step] 42 | s.step++ 43 | return res, true 44 | } 45 | 46 | if len(s.curPath) == s.maxDepth() { 47 | return 0, false 48 | } 49 | 50 | // We're in exploration mode. 51 | s.branchWidths = append(s.branchWidths, n) 52 | s.curPath = append(s.curPath, 0) 53 | s.step++ 54 | return 0, true 55 | } 56 | 57 | func (s *StrategyDFS) Next() bool { 58 | s.step = 0 59 | 60 | // Construct the next path prefix to explore. 61 | for i := len(s.curPath) - 1; i >= 0; i-- { 62 | s.curPath[i]++ 63 | if s.curPath[i] < s.branchWidths[i] { 64 | break 65 | } 66 | s.curPath = s.curPath[:len(s.curPath)-1] 67 | } 68 | s.branchWidths = s.branchWidths[:len(s.curPath)] 69 | if len(s.branchWidths) == 0 { 70 | // We're out of paths. 71 | return false 72 | } 73 | return true 74 | } 75 | 76 | // ErrNondeterminism is the error used by deterministic strategies to 77 | // indicate that the strategy detected that the application behaved 78 | // non-deterministically. 79 | type ErrNondeterminism struct { 80 | Detail string 81 | } 82 | 83 | func (e *ErrNondeterminism) Error() string { 84 | return "non-determinism detected: " + e.Detail 85 | } 86 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/stats/loghist.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package stats 6 | 7 | import "math" 8 | 9 | // LogHist is a Histogram with logarithmically-spaced bins. 10 | type LogHist struct { 11 | b int 12 | m float64 13 | mOverLogb float64 14 | low, high uint 15 | bins []uint 16 | } 17 | 18 | // NewLogHist returns an empty logarithmic histogram with bins for 19 | // integral values of m * log_b(x) up to x = max. 20 | func NewLogHist(b int, m float64, max float64) *LogHist { 21 | // TODO(austin) Minimum value as well? If the samples are 22 | // actually integral, having fractional bin boundaries can 23 | // mess up smoothing. 24 | mOverLogb := m / math.Log(float64(b)) 25 | nbins := int(math.Ceil(mOverLogb * math.Log(max))) 26 | return &LogHist{b: b, m: m, mOverLogb: mOverLogb, low: 0, high: 0, bins: make([]uint, nbins)} 27 | } 28 | 29 | func (h *LogHist) bin(x float64) int { 30 | return int(h.mOverLogb * math.Log(x)) 31 | } 32 | 33 | func (h *LogHist) Add(x float64) { 34 | bin := h.bin(x) 35 | if bin < 0 { 36 | h.low++ 37 | } else if bin >= len(h.bins) { 38 | h.high++ 39 | } else { 40 | h.bins[bin]++ 41 | } 42 | } 43 | 44 | func (h *LogHist) Counts() (uint, []uint, uint) { 45 | return h.low, h.bins, h.high 46 | } 47 | 48 | func (h *LogHist) BinToValue(bin float64) float64 { 49 | return math.Pow(float64(h.b), bin/h.m) 50 | } 51 | 52 | func (h *LogHist) At(x float64) float64 { 53 | bin := h.bin(x) 54 | if bin < 0 || bin >= len(h.bins) { 55 | return 0 56 | } 57 | return float64(h.bins[bin]) 58 | } 59 | 60 | func (h *LogHist) Bounds() (float64, float64) { 61 | // XXX Plot will plot this on a linear axis. Maybe this 62 | // should be able to return the natural axis? 63 | // Maybe then we could also give it the bins for the tics. 64 | lowbin := 0 65 | if h.low == 0 { 66 | for bin, count := range h.bins { 67 | if count > 0 { 68 | lowbin = bin 69 | break 70 | } 71 | } 72 | } 73 | highbin := len(h.bins) 74 | if h.high == 0 { 75 | for bin := range h.bins { 76 | if h.bins[len(h.bins)-bin-1] > 0 { 77 | highbin = len(h.bins) - bin 78 | break 79 | } 80 | } 81 | } 82 | return h.BinToValue(float64(lowbin)), h.BinToValue(float64(highbin)) 83 | } 84 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/cmd/dist/dist.go: -------------------------------------------------------------------------------- 1 | // dist reads newline-separated numbers and describes their distribution. 2 | // 3 | // For example, 4 | // 5 | // $ seq 1 20 | grep -v 1 | dist 6 | // N 9 sum 64 mean 7.11111 gmean 5.78509 std dev 5.34894 variance 28.6111 7 | // 8 | // min 2 9 | // 1%ile 2 10 | // 5%ile 2 11 | // 25%ile 3.66667 12 | // median 6 13 | // 75%ile 8.33333 14 | // 95%ile 20 15 | // 99%ile 20 16 | // max 20 17 | // 18 | // ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣠⠖⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠒⠦⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡖ 0.1 19 | // ⠀⠀⠀⠀⠀⠀⠀⢀⣠⠴⠊⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠲⢤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇ 20 | // ⠠⠤⠤⠤⠤⠴⠒⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠑⠲⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠴⠒⠋⠉⠉⠀⠀⠉⠉⠙⠒⠦⠤⠤⠤⠤⠄⠧ 0.0 21 | // ⠈⠉⠉⠉⠉⠙⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠋⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠉⠋⠉⠉⠉⠉⠉⠉⠉⠉⠉⠁ 22 | // 0 10 20 23 | package main 24 | 25 | import ( 26 | "bufio" 27 | "fmt" 28 | "io" 29 | "math" 30 | "os" 31 | "strconv" 32 | "strings" 33 | 34 | "github.com/aclements/go-moremath/stats" 35 | ) 36 | 37 | func main() { 38 | s := readInput(os.Stdin) 39 | if len(s.Xs) == 0 { 40 | fmt.Fprintln(os.Stderr, "no input") 41 | return 42 | } 43 | s.Sort() 44 | 45 | fmt.Printf("N %d sum %.6g mean %.6g", len(s.Xs), s.Sum(), s.Mean()) 46 | gmean := s.GeoMean() 47 | if !math.IsNaN(gmean) { 48 | fmt.Printf(" gmean %.6g", gmean) 49 | } 50 | fmt.Printf(" std dev %.6g variance %.6g\n", s.StdDev(), s.Variance()) 51 | fmt.Println() 52 | 53 | // Quartiles and tails. 54 | labels := map[int]string{0: "min", 50: "median", 100: "max"} 55 | for _, p := range []int{0, 1, 5, 25, 50, 75, 95, 99, 100} { 56 | label, ok := labels[p] 57 | if !ok { 58 | label = fmt.Sprintf("%d%%ile", p) 59 | } 60 | fmt.Printf("%8s %.6g\n", label, s.Quantile(float64(p)/100)) 61 | } 62 | fmt.Println() 63 | 64 | // Kernel density estimate. 65 | kde := &stats.KDE{Sample: s} 66 | FprintPDF(os.Stdout, kde) 67 | } 68 | 69 | func readInput(r io.Reader) (sample stats.Sample) { 70 | scanner := bufio.NewScanner(r) 71 | for scanner.Scan() { 72 | l := scanner.Text() 73 | l = strings.TrimSpace(l) 74 | if l == "" { 75 | continue 76 | } 77 | value, err := strconv.ParseFloat(l, 64) 78 | if err != nil { 79 | fmt.Fprintln(os.Stderr, err) 80 | os.Exit(1) 81 | } 82 | 83 | sample.Xs = append(sample.Xs, value) 84 | } 85 | if err := scanner.Err(); err != nil { 86 | fmt.Fprintln(os.Stderr, err) 87 | os.Exit(1) 88 | } 89 | 90 | return 91 | } 92 | -------------------------------------------------------------------------------- /go-weave/weave/mutex.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package weave 6 | 7 | import "fmt" 8 | 9 | type Mutex struct { 10 | locked bool 11 | waiters []*thread 12 | } 13 | 14 | func (m *Mutex) Lock() { 15 | if !m.locked { 16 | m.locked = true 17 | return 18 | } 19 | this := globalSched.curThread 20 | m.waiters = append(m.waiters, this) 21 | this.block(m.reset) 22 | } 23 | 24 | func (m *Mutex) Unlock() { 25 | if !m.locked { 26 | panic("attempt to Unlock unlocked Mutex") 27 | } 28 | if len(m.waiters) == 0 { 29 | m.locked = false 30 | } else { 31 | // Pick an arbitrary thread to wake up. 32 | next := globalSched.Amb(len(m.waiters)) 33 | t := m.waiters[next] 34 | m.waiters[next] = m.waiters[len(m.waiters)-1] 35 | m.waiters = m.waiters[:len(m.waiters)-1] 36 | t.unblock() 37 | } 38 | globalSched.Sched() 39 | } 40 | 41 | func (m *Mutex) reset() { 42 | *m = Mutex{} 43 | } 44 | 45 | type RWMutex struct { 46 | r, w int 47 | readers, writers []*thread 48 | } 49 | 50 | func (rw *RWMutex) Lock() { 51 | if rw.r == 0 && rw.w == 0 { 52 | rw.w++ 53 | return 54 | } 55 | this := globalSched.curThread 56 | rw.writers = append(rw.writers, this) 57 | this.block(rw.reset) 58 | } 59 | 60 | func (rw *RWMutex) RLock() { 61 | if rw.w == 0 { 62 | rw.r++ 63 | return 64 | } 65 | this := globalSched.curThread 66 | rw.readers = append(rw.readers, this) 67 | this.block(rw.reset) 68 | } 69 | 70 | func (rw *RWMutex) reset() { 71 | *rw = RWMutex{} 72 | } 73 | 74 | func (rw *RWMutex) Unlock() { 75 | rw.w-- 76 | rw.release() 77 | } 78 | 79 | func (rw *RWMutex) RUnlock() { 80 | rw.r-- 81 | rw.release() 82 | } 83 | 84 | func (rw *RWMutex) release() { 85 | if rw.w != 0 { 86 | panic(fmt.Sprintf("bad RWMutex writer count: %d", rw.w)) 87 | } 88 | if len(rw.readers) > 0 { 89 | // Wake all readers. 90 | rw.r += len(rw.readers) 91 | for _, t := range rw.readers { 92 | t.unblock() 93 | } 94 | rw.readers = rw.readers[:0] 95 | } else if rw.r == 0 && len(rw.writers) > 0 { 96 | // Wake one writer. 97 | rw.w++ 98 | next := globalSched.Amb(len(rw.writers)) 99 | t := rw.writers[next] 100 | rw.writers[next] = rw.writers[len(rw.writers)-1] 101 | rw.writers = rw.writers[:len(rw.writers)-1] 102 | t.unblock() 103 | } 104 | globalSched.Sched() 105 | } 106 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/mathx/gamma.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package mathx 6 | 7 | import "math" 8 | 9 | // GammaInc returns the value of the incomplete gamma function (also 10 | // known as the regularized gamma function): 11 | // 12 | // P(a, x) = 1 / Γ(a) * ∫₀ˣ exp(-t) t**(a-1) dt 13 | func GammaInc(a, x float64) float64 { 14 | // Based on Numerical Recipes in C, section 6.2. 15 | 16 | if a <= 0 || x < 0 || math.IsNaN(a) || math.IsNaN(x) { 17 | return math.NaN() 18 | } 19 | 20 | if x < a+1 { 21 | // Use the series representation, which converges more 22 | // rapidly in this range. 23 | return gammaIncSeries(a, x) 24 | } else { 25 | // Use the continued fraction representation. 26 | return 1 - gammaIncCF(a, x) 27 | } 28 | } 29 | 30 | // GammaIncComp returns the complement of the incomplete gamma 31 | // function 1 - GammaInc(a, x). This is more numerically stable for 32 | // values near 0. 33 | func GammaIncComp(a, x float64) float64 { 34 | if a <= 0 || x < 0 || math.IsNaN(a) || math.IsNaN(x) { 35 | return math.NaN() 36 | } 37 | 38 | if x < a+1 { 39 | return 1 - gammaIncSeries(a, x) 40 | } else { 41 | return gammaIncCF(a, x) 42 | } 43 | } 44 | 45 | func gammaIncSeries(a, x float64) float64 { 46 | const maxIterations = 200 47 | const epsilon = 3e-14 48 | 49 | if x == 0 { 50 | return 0 51 | } 52 | 53 | ap := a 54 | del := 1 / a 55 | sum := del 56 | for n := 0; n < maxIterations; n++ { 57 | ap++ 58 | del *= x / ap 59 | sum += del 60 | if math.Abs(del) < math.Abs(sum)*epsilon { 61 | return sum * math.Exp(-x+a*math.Log(x)-lgamma(a)) 62 | } 63 | } 64 | panic("a too large; failed to converge") 65 | } 66 | 67 | func gammaIncCF(a, x float64) float64 { 68 | const maxIterations = 200 69 | const epsilon = 3e-14 70 | 71 | raiseZero := func(z float64) float64 { 72 | if math.Abs(z) < math.SmallestNonzeroFloat64 { 73 | return math.SmallestNonzeroFloat64 74 | } 75 | return z 76 | } 77 | 78 | b := x + 1 - a 79 | c := math.MaxFloat64 80 | d := 1 / b 81 | h := d 82 | 83 | for i := 1; i <= maxIterations; i++ { 84 | an := -float64(i) * (float64(i) - a) 85 | b += 2 86 | d = raiseZero(an*d + b) 87 | c = raiseZero(b + an/c) 88 | d = 1 / d 89 | del := d * c 90 | h *= del 91 | if math.Abs(del-1) < epsilon { 92 | return math.Exp(-x+a*math.Log(x)-lgamma(a)) * h 93 | } 94 | } 95 | panic("a too large; failed to converge") 96 | } 97 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/stats/kde_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package stats 6 | 7 | import ( 8 | "fmt" 9 | "testing" 10 | ) 11 | 12 | func TestKDEOneSample(t *testing.T) { 13 | x := float64(5) 14 | 15 | // Unweighted, fixed bandwidth 16 | kde := KDE{ 17 | Sample: Sample{Xs: []float64{x}}, 18 | Kernel: GaussianKernel, 19 | Bandwidth: 1, 20 | } 21 | if e, g := StdNormal.PDF(0), kde.PDF(x); !aeq(e, g) { 22 | t.Errorf("bad PDF value at sample: expected %g, got %g", e, g) 23 | } 24 | if e, g := 0.0, kde.PDF(-10000); !aeq(e, g) { 25 | t.Errorf("bad PDF value at low tail: expected %g, got %g", e, g) 26 | } 27 | if e, g := 0.0, kde.PDF(10000); !aeq(e, g) { 28 | t.Errorf("bad PDF value at high tail: expected %g, got %g", e, g) 29 | } 30 | 31 | if e, g := 0.5, kde.CDF(x); !aeq(e, g) { 32 | t.Errorf("bad CDF value at sample: expected %g, got %g", e, g) 33 | } 34 | if e, g := 0.0, kde.CDF(-10000); !aeq(e, g) { 35 | t.Errorf("bad CDF value at low tail: expected %g, got %g", e, g) 36 | } 37 | if e, g := 1.0, kde.CDF(10000); !aeq(e, g) { 38 | t.Errorf("bad CDF value at high tail: expected %g, got %g", e, g) 39 | } 40 | 41 | low, high := kde.Bounds() 42 | if e, g := x-2, low; e < g { 43 | t.Errorf("bad low bound: expected %g, got %g", e, g) 44 | } 45 | if e, g := x+2, high; e > g { 46 | t.Errorf("bad high bound: expected %g, got %g", e, g) 47 | } 48 | 49 | kde = KDE{ 50 | Sample: Sample{Xs: []float64{x}}, 51 | Kernel: EpanechnikovKernel, 52 | Bandwidth: 2, 53 | } 54 | testFunc(t, fmt.Sprintf("%+v.PDF", kde), kde.PDF, map[float64]float64{ 55 | x - 2: 0, 56 | x - 1: 0.5625 / 2, 57 | x: 0.75 / 2, 58 | x + 1: 0.5625 / 2, 59 | x + 2: 0, 60 | }) 61 | testFunc(t, fmt.Sprintf("%+v.CDF", kde), kde.CDF, map[float64]float64{ 62 | x - 2: 0, 63 | x - 1: 0.15625, 64 | x: 0.5, 65 | x + 1: 0.84375, 66 | x + 2: 1, 67 | }) 68 | } 69 | 70 | func TestKDETwoSamples(t *testing.T) { 71 | kde := KDE{ 72 | Sample: Sample{Xs: []float64{1, 3}}, 73 | Kernel: GaussianKernel, 74 | Bandwidth: 2, 75 | } 76 | testFunc(t, "PDF", kde.PDF, map[float64]float64{ 77 | 0: 0.120395730, 78 | 1: 0.160228251, 79 | 2: 0.176032663, 80 | 3: 0.160228251, 81 | 4: 0.120395730}) 82 | 83 | testFunc(t, "CDF", kde.CDF, map[float64]float64{ 84 | 0: 0.187672369, 85 | 1: 0.329327626, 86 | 2: 0.5, 87 | 3: 0.670672373, 88 | 4: 0.812327630}) 89 | } 90 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/ggstat/loess.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ggstat 6 | 7 | import ( 8 | "github.com/aclements/go-gg/generic/slice" 9 | "github.com/aclements/go-gg/table" 10 | "github.com/aclements/go-moremath/fit" 11 | "github.com/aclements/go-moremath/vec" 12 | ) 13 | 14 | // LOESS constructs a locally-weighted least squares polynomial 15 | // regression for the data (X, Y). 16 | // 17 | // X and Y are required. All other fields have reasonable default zero 18 | // values. 19 | // 20 | // The result of LOESS has two columns in addition to constant columns 21 | // from the input: 22 | // 23 | // - Column X is the points at which the LOESS function is sampled. 24 | // 25 | // - Column Y is the result of the LEOSS function. 26 | // 27 | // TODO: Confidence internals/bootstrap distributions? 28 | // 29 | // TODO: Robust LOESS? See https://www.mathworks.com/help/curvefit/smoothing-data.html#bq_6ys3-3 30 | type LOESS struct { 31 | // X and Y are the names of the columns to use for X and Y 32 | // values of data points, respectively. 33 | X, Y string 34 | 35 | // N is the number of points to sample the regression at. If N 36 | // is 0, a reasonable default is used. 37 | N int 38 | 39 | // Domain specifies the domain at which to sample this function. 40 | // If Domain is nil, it defaults to DomainData{}. 41 | Domain FunctionDomainer 42 | 43 | // Degree specifies the degree of the local fit function. If 44 | // it is 0, it is treated as 2. 45 | Degree int 46 | 47 | // Span controls the smoothness of the fit. If it is 0, it is 48 | // treated as 0.5. The span must be between 0 and 1, where 49 | // smaller values fit the data more tightly. 50 | Span float64 51 | } 52 | 53 | func (s LOESS) F(g table.Grouping) table.Grouping { 54 | if s.Degree <= 0 { 55 | s.Degree = 2 56 | } 57 | if s.Span <= 0 { 58 | s.Span = 0.5 59 | } 60 | 61 | var xs, ys []float64 62 | return Function{ 63 | X: s.X, N: s.N, Domain: s.Domain, 64 | Fn: func(gid table.GroupID, in *table.Table, sampleAt []float64, out *table.Builder) { 65 | if len(sampleAt) == 0 { 66 | out.Add(s.Y, []float64{}) 67 | return 68 | } 69 | 70 | // TODO: We potentially convert each X column 71 | // twice, since Function also has to convert 72 | // them. 73 | slice.Convert(&xs, in.MustColumn(s.X)) 74 | slice.Convert(&ys, in.MustColumn(s.Y)) 75 | 76 | loess := fit.LOESS(xs, ys, s.Degree, s.Span) 77 | out.Add(s.Y, vec.Map(loess, sampleAt)) 78 | }, 79 | }.F(g) 80 | } 81 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/stats/ttest_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package stats 6 | 7 | import "testing" 8 | 9 | func TestTTest(t *testing.T) { 10 | s1 := Sample{Xs: []float64{2, 1, 3, 4}} 11 | s2 := Sample{Xs: []float64{6, 5, 7, 9}} 12 | 13 | check := func(want, got *TTestResult) { 14 | if want.N1 != got.N1 || want.N2 != got.N2 || 15 | !aeq(want.T, got.T) || !aeq(want.DoF, got.DoF) || 16 | want.AltHypothesis != got.AltHypothesis || 17 | !aeq(want.P, got.P) { 18 | t.Errorf("want %+v, got %+v", want, got) 19 | } 20 | } 21 | check3 := func(test func(alt LocationHypothesis) (*TTestResult, error), n1, n2 int, t, dof float64, pless, pdiff, pgreater float64) { 22 | want := &TTestResult{N1: n1, N2: n2, T: t, DoF: dof} 23 | 24 | want.AltHypothesis = LocationLess 25 | want.P = pless 26 | got, _ := test(want.AltHypothesis) 27 | check(want, got) 28 | 29 | want.AltHypothesis = LocationDiffers 30 | want.P = pdiff 31 | got, _ = test(want.AltHypothesis) 32 | check(want, got) 33 | 34 | want.AltHypothesis = LocationGreater 35 | want.P = pgreater 36 | got, _ = test(want.AltHypothesis) 37 | check(want, got) 38 | } 39 | 40 | check3(func(alt LocationHypothesis) (*TTestResult, error) { 41 | return TwoSampleTTest(s1, s1, alt) 42 | }, 4, 4, 0, 6, 43 | 0.5, 1, 0.5) 44 | check3(func(alt LocationHypothesis) (*TTestResult, error) { 45 | return TwoSampleWelchTTest(s1, s1, alt) 46 | }, 4, 4, 0, 6, 47 | 0.5, 1, 0.5) 48 | 49 | check3(func(alt LocationHypothesis) (*TTestResult, error) { 50 | return TwoSampleTTest(s1, s2, alt) 51 | }, 4, 4, -3.9703446152237674, 6, 52 | 0.0036820296121056195, 0.0073640592242113214, 0.9963179703878944) 53 | check3(func(alt LocationHypothesis) (*TTestResult, error) { 54 | return TwoSampleWelchTTest(s1, s2, alt) 55 | }, 4, 4, -3.9703446152237674, 5.584615384615385, 56 | 0.004256431565689112, 0.0085128631313781695, 0.9957435684343109) 57 | 58 | check3(func(alt LocationHypothesis) (*TTestResult, error) { 59 | return PairedTTest(s1.Xs, s2.Xs, 0, alt) 60 | }, 4, 4, -17, 3, 61 | 0.0002216717691559955, 0.00044334353831207749, 0.999778328230844) 62 | 63 | check3(func(alt LocationHypothesis) (*TTestResult, error) { 64 | return OneSampleTTest(s1, 0, alt) 65 | }, 4, 0, 3.872983346207417, 3, 66 | 0.9847668541689145, 0.030466291662170977, 0.015233145831085482) 67 | check3(func(alt LocationHypothesis) (*TTestResult, error) { 68 | return OneSampleTTest(s1, 2.5, alt) 69 | }, 4, 0, 0, 3, 70 | 0.5, 1, 0.5) 71 | } 72 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/gg/layout/layout.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package layout provides helpers for laying out hierarchies of 6 | // rectangular elements in two dimensional space. 7 | package layout 8 | 9 | // TODO: If I want to handle wrapped text, this API is insufficient. 10 | // In that case, I may need something more like Android where the 11 | // parent can pass in Unspecified, (Exactly x), or (AtMost x) for both 12 | // dimensions and make multiple calls. I would probably start out with 13 | // AtMost the allocated dimension for everything and if the total came 14 | // back too large, I would cut back space (possibly causing the other 15 | // dimension to grow if text wraps). 16 | 17 | // An Element is a rectangular feature in a layout. 18 | type Element interface { 19 | // SizeHint returns this Element's desired size and whether it 20 | // can expand from that size in either direction. 21 | SizeHint() (w, h float64, flexw, flexh bool) 22 | 23 | // SetLayout sets this Element's layout relative to its parent 24 | // and, if this Element is a container, recursively lays out 25 | // this Element's children. 26 | // 27 | // w and h may be smaller than SizeHint() if the space is 28 | // constrained. They may also be larger, even if the element 29 | // isn't flexible, in which case the Element will position 30 | // itself within the assigned size using some gravity. 31 | // 32 | // TODO: Or should the parent be responsible for gravity if it 33 | // allocates too much space to a fixed element? 34 | // 35 | // TODO: Since an Element doesn't know its parent, it's 36 | // difficult to turn local coordinates into absolute 37 | // coordinates. These should either be absolute coordinates, 38 | // or Element should have a parent and it should be easy to 39 | // get absolute coordinates. 40 | SetLayout(x, y, w, h float64) 41 | 42 | // Layout returns this Element's layout. 43 | Layout() (x, y, w, h float64) 44 | } 45 | 46 | // A Group is an Element that manages the layout of child Elements. 47 | type Group interface { 48 | Element 49 | 50 | // Children returns the child Elements laid out by this Group. 51 | Children() []Element 52 | } 53 | 54 | // Leaf is a leaf in a layout hierarchy. It is meant for embedding: it 55 | // partially implements Element, leaving SizeHint to the embedding 56 | // type. 57 | type Leaf struct { 58 | x, y, w, h float64 59 | } 60 | 61 | func (l *Leaf) SetLayout(x, y, w, h float64) { 62 | l.x, l.y, l.w, l.h = x, y, w, h 63 | } 64 | 65 | func (l *Leaf) Layout() (x, y, w, h float64) { 66 | return l.x, l.y, l.w, l.h 67 | } 68 | -------------------------------------------------------------------------------- /go-weave/models/issue16083.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build ignore 6 | 7 | // issue16083 is a model for finding how mark can complete when stack 8 | // scans are still in progress. 9 | // 10 | // XXX Move gcMarkRootCheck to after forEachP to force final workers 11 | // out? 12 | package main 13 | 14 | import ( 15 | "fmt" 16 | 17 | "github.com/aclements/go-misc/go-weave/amb" 18 | "github.com/aclements/go-misc/go-weave/weave" 19 | ) 20 | 21 | var sched = weave.Scheduler{Strategy: &amb.StrategyRandom{}} 22 | 23 | type State struct { 24 | workers weave.AtomicInt32 25 | markrootNext weave.AtomicInt32 26 | markrootJobs int32 27 | scanned [2]weave.AtomicInt32 28 | 29 | markDoneSema weave.Mutex 30 | 31 | done bool 32 | } 33 | 34 | func main() { 35 | sched.Run(func() { 36 | var s State 37 | s.markrootJobs = int32(len(s.scanned)) 38 | 39 | for i := 0; i < 4; i++ { 40 | sched.Go(s.worker) 41 | } 42 | }) 43 | } 44 | 45 | func (s *State) worker() { 46 | // This has a liveness problem, so limit it to 4 iterations. 47 | for i := 0; i < 3 && !s.done; i++ { 48 | sched.Trace("s.workers++") 49 | n := s.workers.Add(+1) 50 | // XXX This trace appears in the wrong place since Add 51 | // did a Sched after the modification. Perhaps we 52 | // should pre-Sched? Or I could put this in an atomic block. 53 | sched.Tracef(" => %d", n) 54 | 55 | s.gcDrain() 56 | 57 | sched.Trace("s.workers--") 58 | n = s.workers.Add(-1) 59 | sched.Tracef(" => %d", n) 60 | 61 | if n == 0 { 62 | sched.Tracef("s.workers == 0") 63 | if !s.gcMarkWorkAvailable() { 64 | sched.Tracef("!gcMarkWorkAvailable()") 65 | s.gcMarkDone() 66 | } 67 | } 68 | } 69 | sched.Trace("exit") 70 | } 71 | 72 | func (s *State) gcDrain() { 73 | job := s.markrootNext.Add(1) - 1 74 | if job < s.markrootJobs { 75 | sched.Tracef("scanning %d", job) 76 | s.scanned[job].Store(1) 77 | } 78 | } 79 | 80 | func (s *State) gcMarkWorkAvailable() bool { 81 | return s.markrootNext.Load() < s.markrootJobs 82 | } 83 | 84 | func (s *State) gcMarkDone() { 85 | s.markDoneSema.Lock() 86 | defer s.markDoneSema.Unlock() 87 | 88 | if !(s.workers.Load() == 0 && !s.gcMarkWorkAvailable()) { 89 | sched.Tracef("gcMarkDone retry") 90 | return 91 | } 92 | 93 | s.gcMarkRootCheck() 94 | 95 | s.done = true 96 | } 97 | 98 | func (s *State) gcMarkRootCheck() { 99 | for i := range s.scanned { 100 | if s.scanned[i].Load() == 0 { 101 | panic(fmt.Sprintf("missed %d", i)) 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/generic/order.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package generic 6 | 7 | import "reflect" 8 | 9 | // CanOrder returns whether the values a and b are orderable according 10 | // to the Go language specification. 11 | func CanOrder(a, b interface{}) bool { 12 | ak, bk := reflect.ValueOf(a).Kind(), reflect.ValueOf(b).Kind() 13 | if ak != bk { 14 | return false 15 | } 16 | return CanOrderR(ak) 17 | } 18 | 19 | var orderable = map[reflect.Kind]bool{ 20 | reflect.Int: true, 21 | reflect.Int8: true, 22 | reflect.Int16: true, 23 | reflect.Int32: true, 24 | reflect.Int64: true, 25 | reflect.Uint: true, 26 | reflect.Uintptr: true, 27 | reflect.Uint8: true, 28 | reflect.Uint16: true, 29 | reflect.Uint32: true, 30 | reflect.Uint64: true, 31 | reflect.Float32: true, 32 | reflect.Float64: true, 33 | reflect.String: true, 34 | } 35 | 36 | // CanOrderR returns whether two values of kind k are orderable 37 | // according to the Go language specification. 38 | func CanOrderR(k reflect.Kind) bool { 39 | return orderable[k] 40 | } 41 | 42 | // Order returns the order of values a and b: -1 if a < b, 0 if a == 43 | // b, 1 if a > b. The results are undefined if either a or b is NaN. 44 | // 45 | // Order panics if a and b are not orderable according to the Go 46 | // language specification. 47 | func Order(a, b interface{}) int { 48 | return OrderR(reflect.ValueOf(a), reflect.ValueOf(b)) 49 | } 50 | 51 | // OrderR is equivalent to Order, but operates on reflect.Values. 52 | func OrderR(a, b reflect.Value) int { 53 | if a.Kind() != b.Kind() { 54 | panic(&TypeError{a.Type(), b.Type(), "are not orderable because they are different kinds"}) 55 | } 56 | 57 | switch a.Kind() { 58 | case reflect.Float32, reflect.Float64: 59 | a, b := a.Float(), b.Float() 60 | if a < b { 61 | return -1 62 | } else if a > b { 63 | return 1 64 | } 65 | return 0 66 | 67 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: 68 | a, b := a.Int(), b.Int() 69 | if a < b { 70 | return -1 71 | } else if a > b { 72 | return 1 73 | } 74 | return 0 75 | 76 | case reflect.Uint, reflect.Uintptr, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: 77 | a, b := a.Uint(), b.Uint() 78 | if a < b { 79 | return -1 80 | } else if a > b { 81 | return 1 82 | } 83 | return 0 84 | 85 | case reflect.String: 86 | a, b := a.String(), b.String() 87 | if a < b { 88 | return -1 89 | } else if a > b { 90 | return 1 91 | } 92 | return 0 93 | } 94 | 95 | panic(&TypeError{a.Type(), nil, "is not orderable"}) 96 | } 97 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/table/sort.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package table 6 | 7 | import ( 8 | "sort" 9 | 10 | "github.com/aclements/go-gg/generic/slice" 11 | ) 12 | 13 | // SortBy sorts each group of g by the named columns. If a column's 14 | // type implements sort.Interface, rows will be sorted according to 15 | // that order. Otherwise, the values in the column must be naturally 16 | // ordered (their types must be orderable by the Go specification). If 17 | // neither is true, SortBy panics with a *generic.TypeError. If more 18 | // than one column is given, SortBy sorts by the tuple of the columns; 19 | // that is, if two values in the first column are equal, they are 20 | // sorted by the second column, and so on. 21 | func SortBy(g Grouping, cols ...string) Grouping { 22 | // Sort each group. 23 | sorters := make([]sort.Interface, len(cols)) 24 | return MapTables(g, func(_ GroupID, t *Table) *Table { 25 | // Create sorters for each column. 26 | sorters = sorters[:0] 27 | for _, col := range cols { 28 | if _, ok := t.Const(col); ok { 29 | continue 30 | } 31 | seq := t.MustColumn(col) 32 | sorter := slice.Sorter(seq) 33 | if sort.IsSorted(sorter) { 34 | continue 35 | } 36 | sorters = append(sorters, sorter) 37 | } 38 | 39 | if len(sorters) == 0 { 40 | // Avoid shuffling everything by the identity 41 | // permutation. 42 | return t 43 | } 44 | 45 | // Generate an initial permutation sequence. 46 | perm := make([]int, t.Len()) 47 | for i := range perm { 48 | perm[i] = i 49 | } 50 | 51 | // Sort the permutation sequence. 52 | sort.Stable(&permSort{perm, sorters}) 53 | 54 | // Permute all columns. 55 | var nt Builder 56 | for _, name := range t.Columns() { 57 | if cv, ok := t.Const(name); ok { 58 | nt.AddConst(name, cv) 59 | continue 60 | } 61 | seq := t.Column(name) 62 | seq = slice.Select(seq, perm) 63 | nt.Add(name, seq) 64 | } 65 | return nt.Done() 66 | }) 67 | } 68 | 69 | type permSort struct { 70 | perm []int 71 | keys []sort.Interface 72 | } 73 | 74 | func (s *permSort) Len() int { 75 | return len(s.perm) 76 | } 77 | 78 | func (s *permSort) Less(i, j int) bool { 79 | // Since there's no way to ask about equality, we have to do 80 | // extra work for all of the keys except the last. 81 | for _, key := range s.keys[:len(s.keys)-1] { 82 | if key.Less(s.perm[i], s.perm[j]) { 83 | return true 84 | } else if key.Less(s.perm[j], s.perm[i]) { 85 | return false 86 | } 87 | } 88 | return s.keys[len(s.keys)-1].Less(s.perm[i], s.perm[j]) 89 | } 90 | 91 | func (s *permSort) Swap(i, j int) { 92 | s.perm[i], s.perm[j] = s.perm[j], s.perm[i] 93 | } 94 | -------------------------------------------------------------------------------- /go-weave/models/markterm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build ignore 6 | 7 | // markterm is a model for finding when mark termination can start 8 | // before all work is drained in Go 1.7. This model is expected to 9 | // fail. 10 | package main 11 | 12 | import ( 13 | "fmt" 14 | 15 | "github.com/aclements/go-misc/go-weave/amb" 16 | "github.com/aclements/go-misc/go-weave/weave" 17 | ) 18 | 19 | var sched = weave.Scheduler{Strategy: &amb.StrategyRandom{}} 20 | 21 | type State struct { 22 | workers int 23 | grey int 24 | done bool 25 | } 26 | 27 | func main() { 28 | sched.Run(func() { 29 | var s State 30 | s.grey = 3 31 | 32 | for i := 0; i < 2; i++ { 33 | sched.Go(s.worker) 34 | } 35 | }) 36 | } 37 | 38 | func (s *State) worker() { 39 | // TODO: This has a liveness problem: if a worker takes the 40 | // last work and then doesn't get scheduled again, the other 41 | // worker will spin. Curiously, duplicate state detection 42 | // would cut off that path, which means if we see a duplicate 43 | // with an earlier state in the same path (versus a different 44 | // path), it's a livelock and perhaps should be reported. 45 | for { 46 | s.workers++ 47 | sched.Tracef("s.workers++ (%d)", s.workers) 48 | sched.Sched() 49 | 50 | s.check() 51 | 52 | switch { 53 | case s.grey <= 0: 54 | // Do nothing 55 | case s.grey == 1: 56 | // Pull one pointer, put none. 57 | s.grey-- 58 | sched.Tracef("s.grey-- (%d)", s.grey) 59 | sched.Sched() 60 | default: 61 | // Remove two pointers, then add one to simulate 62 | // pulling a buffer off full and then putting one back 63 | // one full. 64 | s.grey -= 2 65 | sched.Tracef("s.grey -= 2 (%d)", s.grey) 66 | sched.Sched() 67 | s.grey++ 68 | sched.Tracef("s.grey++ (%d)", s.grey) 69 | s.check() 70 | sched.Sched() 71 | } 72 | 73 | var grey int 74 | if true { // Read full list ("grey") before dec(&workers) 75 | grey = s.grey 76 | sched.Tracef("grey := s.grey (%d)", s.grey) 77 | sched.Sched() 78 | } 79 | 80 | s.workers-- 81 | n := s.workers 82 | sched.Tracef("s.workers-- (%d)", s.workers) 83 | sched.Sched() 84 | 85 | if false { 86 | grey = s.grey 87 | sched.Tracef("grey := s.grey (%d)", s.grey) 88 | sched.Sched() 89 | } 90 | 91 | if n == 0 && grey == 0 { 92 | s.done = true 93 | sched.Trace("s.done = true") 94 | sched.Sched() 95 | s.check() 96 | break 97 | } 98 | } 99 | sched.Trace("exit") 100 | } 101 | 102 | func (s *State) check() { 103 | if s.done && s.grey > 0 { 104 | panic(fmt.Sprintf("done, but grey==%d", s.grey)) 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/table/concat.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package table 6 | 7 | import ( 8 | "fmt" 9 | 10 | "github.com/aclements/go-gg/generic/slice" 11 | ) 12 | 13 | // Concat returns the concatenation of the rows in each matching group 14 | // across gs. All Groupings in gs must have the same set of columns 15 | // (though they need not be in the same order; the column order from 16 | // gs[0] will be used). The GroupIDs in the returned Grouping will be 17 | // the union of the GroupIDs in gs. 18 | func Concat(gs ...Grouping) Grouping { 19 | if len(gs) == 0 { 20 | return new(Table) 21 | } 22 | 23 | // Check that all Groupings have the same set of columns. They 24 | // can be in different orders. 25 | colSet := map[string]bool{} 26 | for _, col := range gs[0].Columns() { 27 | colSet[col] = true 28 | } 29 | for i, g2 := range gs[1:] { 30 | diff := len(g2.Columns()) != len(colSet) 31 | if !diff { 32 | for _, col := range g2.Columns() { 33 | if !colSet[col] { 34 | diff = true 35 | break 36 | } 37 | } 38 | } 39 | if diff { 40 | panic(fmt.Sprintf("columns in Groupings 0 and %d differ: %q vs %q", i+1, gs[0].Columns(), g2.Columns())) 41 | } 42 | } 43 | 44 | // Collect group IDs. 45 | haveGID := map[GroupID]bool{} 46 | gids := []GroupID{} 47 | for _, g := range gs { 48 | for _, gid := range g.Tables() { 49 | if haveGID[gid] { 50 | continue 51 | } 52 | haveGID[gid] = true 53 | gids = append(gids, gid) 54 | } 55 | } 56 | 57 | // Build output groups. 58 | var ng GroupingBuilder 59 | for _, gid := range gids { 60 | // Build output table. 61 | var nt Builder 62 | var cols []slice.T 63 | for _, col := range gs[0].Columns() { 64 | // Is it constant? 65 | isConst := false 66 | var cv interface{} 67 | for _, g := range gs { 68 | t := g.Table(gid) 69 | if t == nil { 70 | continue 71 | } 72 | if cv1, ok := t.Const(col); ok { 73 | if !isConst { 74 | isConst = true 75 | cv = cv1 76 | } else if cv != cv1 { 77 | isConst = false 78 | break 79 | } 80 | } else { 81 | isConst = false 82 | break 83 | } 84 | } 85 | if isConst { 86 | nt.AddConst(col, cv) 87 | continue 88 | } 89 | 90 | // Not a constant. Collect slices. 91 | for _, g := range gs { 92 | t := g.Table(gid) 93 | if t == nil { 94 | continue 95 | } 96 | cols = append(cols, t.Column(col)) 97 | } 98 | nt.Add(col, slice.Concat(cols...)) 99 | cols = cols[:0] 100 | } 101 | ng.Add(gid, nt.Done()) 102 | } 103 | return ng.Done() 104 | } 105 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/mathx/beta.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package mathx 6 | 7 | import "math" 8 | 9 | func lgamma(x float64) float64 { 10 | y, _ := math.Lgamma(x) 11 | return y 12 | } 13 | 14 | // Beta returns the value of the complete beta function B(a, b). 15 | func Beta(a, b float64) float64 { 16 | // B(x,y) = Γ(x)Γ(y) / Γ(x+y) 17 | return math.Exp(lgamma(a) + lgamma(b) - lgamma(a+b)) 18 | } 19 | 20 | // BetaInc returns the value of the regularized incomplete beta 21 | // function Iₓ(a, b). 22 | // 23 | // This is not to be confused with the "incomplete beta function", 24 | // which can be computed as BetaInc(x, a, b)*Beta(a, b). 25 | // 26 | // If x < 0 or x > 1, returns NaN. 27 | func BetaInc(x, a, b float64) float64 { 28 | // Based on Numerical Recipes in C, section 6.4. This uses the 29 | // continued fraction definition of I: 30 | // 31 | // (xᵃ*(1-x)ᵇ)/(a*B(a,b)) * (1/(1+(d₁/(1+(d₂/(1+...)))))) 32 | // 33 | // where B(a,b) is the beta function and 34 | // 35 | // d_{2m+1} = -(a+m)(a+b+m)x/((a+2m)(a+2m+1)) 36 | // d_{2m} = m(b-m)x/((a+2m-1)(a+2m)) 37 | if x < 0 || x > 1 { 38 | return math.NaN() 39 | } 40 | bt := 0.0 41 | if 0 < x && x < 1 { 42 | // Compute the coefficient before the continued 43 | // fraction. 44 | bt = math.Exp(lgamma(a+b) - lgamma(a) - lgamma(b) + 45 | a*math.Log(x) + b*math.Log(1-x)) 46 | } 47 | if x < (a+1)/(a+b+2) { 48 | // Compute continued fraction directly. 49 | return bt * betacf(x, a, b) / a 50 | } else { 51 | // Compute continued fraction after symmetry transform. 52 | return 1 - bt*betacf(1-x, b, a)/b 53 | } 54 | } 55 | 56 | // betacf is the continued fraction component of the regularized 57 | // incomplete beta function Iₓ(a, b). 58 | func betacf(x, a, b float64) float64 { 59 | const maxIterations = 200 60 | const epsilon = 3e-14 61 | 62 | raiseZero := func(z float64) float64 { 63 | if math.Abs(z) < math.SmallestNonzeroFloat64 { 64 | return math.SmallestNonzeroFloat64 65 | } 66 | return z 67 | } 68 | 69 | c := 1.0 70 | d := 1 / raiseZero(1-(a+b)*x/(a+1)) 71 | h := d 72 | for m := 1; m <= maxIterations; m++ { 73 | mf := float64(m) 74 | 75 | // Even step of the recurrence. 76 | numer := mf * (b - mf) * x / ((a + 2*mf - 1) * (a + 2*mf)) 77 | d = 1 / raiseZero(1+numer*d) 78 | c = raiseZero(1 + numer/c) 79 | h *= d * c 80 | 81 | // Odd step of the recurrence. 82 | numer = -(a + mf) * (a + b + mf) * x / ((a + 2*mf) * (a + 2*mf + 1)) 83 | d = 1 / raiseZero(1+numer*d) 84 | c = raiseZero(1 + numer/c) 85 | hfac := d * c 86 | h *= hfac 87 | 88 | if math.Abs(hfac-1) < epsilon { 89 | return h 90 | } 91 | } 92 | panic("betainc: a or b too big; failed to converge") 93 | } 94 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/stats/utest_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package stats 6 | 7 | import "testing" 8 | 9 | func TestMannWhitneyUTest(t *testing.T) { 10 | check := func(want, got *MannWhitneyUTestResult) { 11 | if want.N1 != got.N1 || want.N2 != got.N2 || 12 | !aeq(want.U, got.U) || 13 | want.AltHypothesis != got.AltHypothesis || 14 | !aeq(want.P, got.P) { 15 | t.Errorf("want %+v, got %+v", want, got) 16 | } 17 | } 18 | check3 := func(x1, x2 []float64, U float64, pless, pdiff, pgreater float64) { 19 | want := &MannWhitneyUTestResult{N1: len(x1), N2: len(x2), U: U} 20 | 21 | want.AltHypothesis = LocationLess 22 | want.P = pless 23 | got, _ := MannWhitneyUTest(x1, x2, want.AltHypothesis) 24 | check(want, got) 25 | 26 | want.AltHypothesis = LocationDiffers 27 | want.P = pdiff 28 | got, _ = MannWhitneyUTest(x1, x2, want.AltHypothesis) 29 | check(want, got) 30 | 31 | want.AltHypothesis = LocationGreater 32 | want.P = pgreater 33 | got, _ = MannWhitneyUTest(x1, x2, want.AltHypothesis) 34 | check(want, got) 35 | } 36 | 37 | s1 := []float64{2, 1, 3, 5} 38 | s2 := []float64{12, 11, 13, 15} 39 | s3 := []float64{0, 4, 6, 7} // Interleaved with s1, but no ties 40 | s4 := []float64{2, 2, 2, 2} 41 | s5 := []float64{1, 1, 1, 1, 1} 42 | 43 | // Small sample, no ties 44 | check3(s1, s2, 0, 0.014285714285714289, 0.028571428571428577, 1) 45 | check3(s2, s1, 16, 1, 0.028571428571428577, 0.014285714285714289) 46 | check3(s1, s3, 5, 0.24285714285714288, 0.485714285714285770, 0.8285714285714285) 47 | 48 | // Small sample, ties 49 | // TODO: Check these against some other implementation. 50 | check3(s1, s1, 8, 0.6285714285714286, 1, 0.6285714285714286) 51 | check3(s1, s4, 10, 0.8571428571428571, 0.7142857142857143, 0.3571428571428571) 52 | check3(s1, s5, 17.5, 1, 0, 0.04761904761904767) 53 | 54 | r, err := MannWhitneyUTest(s4, s4, LocationDiffers) 55 | if err != ErrSamplesEqual { 56 | t.Errorf("want ErrSamplesEqual, got %+v, %+v", r, err) 57 | } 58 | 59 | // Large samples. 60 | l1 := make([]float64, 500) 61 | for i := range l1 { 62 | l1[i] = float64(i * 2) 63 | } 64 | l2 := make([]float64, 600) 65 | for i := range l2 { 66 | l2[i] = float64(i*2 - 41) 67 | } 68 | l3 := append([]float64{}, l2...) 69 | for i := 0; i < 30; i++ { 70 | l3[i] = l1[i] 71 | } 72 | // For comparing with R's wilcox.test: 73 | // l1 <- seq(0, 499)*2 74 | // l2 <- seq(0,599)*2-41 75 | // l3 <- l2; for (i in 1:30) { l3[i] = l1[i] } 76 | 77 | check3(l1, l2, 135250, 0.0024667680407086112, 0.0049335360814172224, 0.9975346930458906) 78 | check3(l1, l1, 125000, 0.5000436801680628, 1, 0.5000436801680628) 79 | check3(l1, l3, 134845, 0.0019351907119808942, 0.0038703814239617884, 0.9980659818257166) 80 | } 81 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/generic/slice/min_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package slice 6 | 7 | import ( 8 | "math" 9 | "testing" 10 | "time" 11 | ) 12 | 13 | func TestMin(t *testing.T) { 14 | shouldPanic(t, "no min", func() { Min([]float64{}) }) 15 | shouldPanic(t, "no min", func() { ArgMin([]float64{}) }) 16 | shouldPanic(t, "no max", func() { Max([]float64{}) }) 17 | shouldPanic(t, "no max", func() { ArgMax([]float64{}) }) 18 | 19 | xs := []float64{5, 1, 8, 1, 8, 3} 20 | if x := Min(xs); x != 1.0 { 21 | t.Errorf("Min should be 1, got %v", x) 22 | } 23 | if x := ArgMin(xs); x != 1 { 24 | t.Errorf("ArgMin should be 1, got %v", x) 25 | } 26 | if x := Max(xs); x != 8.0 { 27 | t.Errorf("Max should be 8, got %v", x) 28 | } 29 | if x := ArgMax(xs); x != 2 { 30 | t.Errorf("ArgMax should be 2, got %v", x) 31 | } 32 | 33 | xs = []float64{1, 5, math.NaN()} 34 | if x := Min(xs); x != 1.0 { 35 | t.Errorf("Min should be 1, got %v", x) 36 | } 37 | if x := Max(xs); x != 5.0 { 38 | t.Errorf("Max should be 5, got %v", x) 39 | } 40 | } 41 | 42 | type fakeSortInterface struct { 43 | len int 44 | } 45 | 46 | func (f fakeSortInterface) Len() int { 47 | return f.len 48 | } 49 | 50 | func (f fakeSortInterface) Swap(i, j int) { 51 | panic("can't") 52 | } 53 | 54 | func (f fakeSortInterface) Less(i, j int) bool { 55 | return i < j 56 | } 57 | 58 | type timeSlice []time.Time 59 | 60 | func (s timeSlice) Len() int { 61 | return len(s) 62 | } 63 | 64 | func (s timeSlice) Less(i, j int) bool { 65 | return s[i].Before(s[j]) 66 | } 67 | 68 | func (s timeSlice) Swap(i, j int) { 69 | s[i], s[j] = s[j], s[i] 70 | } 71 | 72 | func TestMinSort(t *testing.T) { 73 | shouldPanic(t, "no min", func() { Min(fakeSortInterface{0}) }) 74 | shouldPanic(t, "no min", func() { ArgMin(fakeSortInterface{0}) }) 75 | shouldPanic(t, "no max", func() { Max(fakeSortInterface{0}) }) 76 | shouldPanic(t, "no max", func() { ArgMax(fakeSortInterface{0}) }) 77 | 78 | f := fakeSortInterface{5} 79 | if x := ArgMin(f); x != 0 { 80 | t.Errorf("ArgMin should be 0, got %v", x) 81 | } 82 | if x := ArgMax(f); x != 4 { 83 | t.Errorf("ArgMax should be 4, got %v", x) 84 | } 85 | 86 | z := time.Unix(0, 0) 87 | ts := timeSlice{z.Add(time.Hour), z, z.Add(2 * time.Hour), z.Add(time.Hour)} 88 | if x := Min(ts); x != ts[1] { 89 | t.Errorf("Min should be %v, got %v", ts[1], x) 90 | } 91 | if x := ArgMin(ts); x != 1 { 92 | t.Errorf("ArgMin should be 1, got %v", x) 93 | } 94 | if x := Max(ts); x != ts[2] { 95 | t.Errorf("Max should be %v, got %v", ts[2], x) 96 | } 97 | if x := ArgMax(ts); x != 2 { 98 | t.Errorf("ArgMax should be 2, got %v", x) 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/stats/stream.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package stats 6 | 7 | import ( 8 | "fmt" 9 | "math" 10 | ) 11 | 12 | // TODO(austin) Unify more with Sample interface 13 | 14 | // StreamStats tracks basic statistics for a stream of data in O(1) 15 | // space. 16 | // 17 | // StreamStats should be initialized to its zero value. 18 | type StreamStats struct { 19 | Count uint 20 | Total, Min, Max float64 21 | 22 | // Numerically stable online mean 23 | mean float64 24 | meanOfSquares float64 25 | 26 | // Online variance 27 | vM2 float64 28 | } 29 | 30 | // Add updates s's statistics with sample value x. 31 | func (s *StreamStats) Add(x float64) { 32 | s.Total += x 33 | if s.Count == 0 { 34 | s.Min, s.Max = x, x 35 | } else { 36 | if x < s.Min { 37 | s.Min = x 38 | } 39 | if x > s.Max { 40 | s.Max = x 41 | } 42 | } 43 | s.Count++ 44 | 45 | // Update online mean, mean of squares, and variance. Online 46 | // variance based on Wikipedia's presentation ("Algorithms for 47 | // calculating variance") of Knuth's formulation of Welford 48 | // 1962. 49 | delta := x - s.mean 50 | s.mean += delta / float64(s.Count) 51 | s.meanOfSquares += (x*x - s.meanOfSquares) / float64(s.Count) 52 | s.vM2 += delta * (x - s.mean) 53 | } 54 | 55 | func (s *StreamStats) Weight() float64 { 56 | return float64(s.Count) 57 | } 58 | 59 | func (s *StreamStats) Mean() float64 { 60 | return s.mean 61 | } 62 | 63 | func (s *StreamStats) Variance() float64 { 64 | return s.vM2 / float64(s.Count-1) 65 | } 66 | 67 | func (s *StreamStats) StdDev() float64 { 68 | return math.Sqrt(s.Variance()) 69 | } 70 | 71 | func (s *StreamStats) RMS() float64 { 72 | return math.Sqrt(s.meanOfSquares) 73 | } 74 | 75 | // Combine updates s's statistics as if all samples added to o were 76 | // added to s. 77 | func (s *StreamStats) Combine(o *StreamStats) { 78 | count := s.Count + o.Count 79 | 80 | // Compute combined online variance statistics 81 | delta := o.mean - s.mean 82 | mean := s.mean + delta*float64(o.Count)/float64(count) 83 | vM2 := s.vM2 + o.vM2 + delta*delta*float64(s.Count)*float64(o.Count)/float64(count) 84 | 85 | s.Count = count 86 | s.Total += o.Total 87 | if o.Min < s.Min { 88 | s.Min = o.Min 89 | } 90 | if o.Max > s.Max { 91 | s.Max = o.Max 92 | } 93 | s.mean = mean 94 | s.meanOfSquares += (o.meanOfSquares - s.meanOfSquares) * float64(o.Count) / float64(count) 95 | s.vM2 = vM2 96 | } 97 | 98 | func (s *StreamStats) String() string { 99 | return fmt.Sprintf("Count=%d Total=%g Min=%g Mean=%g RMS=%g Max=%g StdDev=%g", s.Count, s.Total, s.Min, s.Mean(), s.RMS(), s.Max, s.StdDev()) 100 | } 101 | -------------------------------------------------------------------------------- /go-weave/amb/progress.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package amb 6 | 7 | import ( 8 | "bytes" 9 | "fmt" 10 | "log" 11 | "os" 12 | "sync" 13 | "sync/atomic" 14 | "time" 15 | ) 16 | 17 | var count int64 18 | 19 | var progress struct { 20 | printLock sync.Mutex 21 | stop chan struct{} 22 | done chan struct{} 23 | } 24 | 25 | const resetLine = "\r\x1b[2K" 26 | 27 | func startProgress() { 28 | progress.stop = make(chan struct{}) 29 | progress.done = make(chan struct{}) 30 | 31 | go func() { 32 | // Redirect process stdout and stderr. 33 | // 34 | // Alternatively, we could dup our pipes over stdout 35 | // and stderr, but then we're in the way of any 36 | // runtime debug output. 37 | origStdout, origStderr := os.Stdout, os.Stderr 38 | newStdoutR, newStdoutW, err := os.Pipe() 39 | if err != nil { 40 | log.Fatalf("failed to create stdout self-pipe: %v", err) 41 | } 42 | newStderrR, newStderrW, err := os.Pipe() 43 | if err != nil { 44 | log.Fatalf("failed to create stderr self-pipe: %v", err) 45 | } 46 | 47 | defer func() { 48 | os.Stdout, os.Stderr = origStdout, origStderr 49 | // Stop the feeder. It will close the write sides. 50 | newStdoutR.Close() 51 | newStderrR.Close() 52 | }() 53 | os.Stdout, os.Stderr = newStdoutW, newStderrW 54 | go pipeFeeder(newStdoutR, origStdout, origStdout) 55 | go pipeFeeder(newStderrR, origStderr, origStderr) 56 | 57 | report := func(final bool) { 58 | progress.printLock.Lock() 59 | fmt.Fprintf(origStderr, "%s%d done", resetLine, atomic.LoadInt64(&count)) 60 | if final { 61 | fmt.Fprintf(origStderr, "\n") 62 | } 63 | progress.printLock.Unlock() 64 | } 65 | ticker := time.NewTicker(100 * time.Millisecond) 66 | loop: 67 | for { 68 | report(false) 69 | 70 | select { 71 | case <-ticker.C: 72 | case <-progress.stop: 73 | report(true) 74 | break loop 75 | } 76 | } 77 | ticker.Stop() 78 | close(progress.done) 79 | }() 80 | } 81 | 82 | func pipeFeeder(r, w, pstream *os.File) { 83 | var buf [256]byte 84 | bol := true 85 | for { 86 | n, err := r.Read(buf[:]) 87 | if n == 0 { 88 | break 89 | } 90 | if bol { 91 | bol = false 92 | // Stop progress printing. 93 | progress.printLock.Lock() 94 | // Clear the progress line. 95 | pstream.WriteString(resetLine) 96 | } 97 | // Print this message. 98 | if n, err = w.Write(buf[:n]); err != nil { 99 | panic(err) 100 | } 101 | if bytes.HasSuffix(buf[:n], []byte("\n")) { 102 | // Resume progress printing. 103 | progress.printLock.Unlock() 104 | bol = true 105 | } 106 | } 107 | w.Close() 108 | } 109 | 110 | func stopProgress() { 111 | close(progress.stop) 112 | <-progress.done 113 | } 114 | -------------------------------------------------------------------------------- /rtcheck/static/tmpl-order.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Lock order 5 | 46 | 47 | 48 |
49 |
50 |

51 | The graph to the right shows the lock order. Cycles 52 | are highlighed in red and represent potential 53 | deadlocks. 54 |

55 |

56 | Click an edge in the lock graph to show code paths 57 | demonstrating that edge. Drag or wheel on the graph to 58 | pan or zoom. 59 |

60 |

61 | Cycle edges are annotated with the number of code 62 | paths demonstating that edge. Typically the "buggy" 63 | edge will have fewer code paths. 64 |

65 |

66 | For details and limitations of this analysis, see 67 | go doc rtcheck. 68 |

69 |
70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/palette/blend.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package palette 6 | 7 | import "image/color" 8 | 9 | // blendRGBA returns the interpolation between two sRGB colors with 10 | // pre-multiplied alpha. 11 | func blendRGBA(a, b color.RGBA, x float64) color.RGBA { 12 | const linThresh = 5 13 | diff8 := func(a, b uint8) uint8 { 14 | if a < b { 15 | return b - a 16 | } 17 | return a - b 18 | } 19 | if a.A == 255 && b.A == 255 && diff8(a.R, b.R) <= linThresh && diff8(a.G, b.G) <= linThresh && diff8(a.B, b.B) <= linThresh { 20 | // Perform a quick linear interpolation. 21 | blend8 := func(a, b uint8, x float64) uint8 { 22 | c := float64(a)*(1-x) + float64(b)*x 23 | if c <= 0 { 24 | return 0 25 | } else if c >= 255 { 26 | return 255 27 | } 28 | return uint8(c) 29 | } 30 | return color.RGBA{ 31 | blend8(a.R, b.R, x), 32 | blend8(a.G, b.G, x), 33 | blend8(a.B, b.B, x), 34 | 255, 35 | } 36 | } 37 | 38 | blend := func(a, b uint8, x float64, lim uint8) uint8 { 39 | // Map to linear RGB, blend in linear RGB, and map 40 | // back to sRGB. 41 | al, bl := sRGB8ToLinear(a), sRGB8ToLinear(b) 42 | cl := float64(al)*(1-x) + float64(bl)*x 43 | if cl < 0 { 44 | return 0 45 | } else if cl >= 1<<16-1 { 46 | return 255 47 | } 48 | out := linearTosRGB8(uint16(cl)) 49 | if out > lim { 50 | out = lim 51 | } 52 | return out 53 | } 54 | linear := func(a, b uint8, x float64) uint8 { 55 | c := int(float64(a)*(1-x) + float64(b)*x) 56 | if c <= 0 { 57 | return 0 58 | } else if c >= 255 { 59 | return 255 60 | } 61 | return uint8(c) 62 | } 63 | 64 | if a.A == b.A { 65 | // No need to undo the alpha pre-multiplication. 66 | return color.RGBA{ 67 | blend(a.R, b.R, x, a.A), 68 | blend(a.G, b.G, x, a.A), 69 | blend(a.B, b.B, x, a.A), 70 | a.A, 71 | } 72 | } 73 | 74 | // Un-premultiply the alpha, map to linear RGB, blend in 75 | // linear RGB, map back to sRGB, and re-premultiply the alpha. 76 | if a.A == 0 { 77 | return color.RGBA{b.R, b.G, b.B, linear(a.A, b.A, x)} 78 | } else if b.A == 0 { 79 | return color.RGBA{a.R, a.G, a.B, linear(a.A, b.A, x)} 80 | } 81 | // TODO: This loses precision. Maybe use 16 bit sRGB? 82 | a.R = uint8(uint16(a.R) * 255 / uint16(a.A)) 83 | a.G = uint8(uint16(a.G) * 255 / uint16(a.A)) 84 | a.B = uint8(uint16(a.B) * 255 / uint16(a.A)) 85 | b.R = uint8(uint16(b.R) * 255 / uint16(b.A)) 86 | b.G = uint8(uint16(b.G) * 255 / uint16(b.A)) 87 | b.B = uint8(uint16(b.B) * 255 / uint16(b.A)) 88 | c := color.RGBA{ 89 | blend(a.R, b.R, x, 255), 90 | blend(a.G, b.G, x, 255), 91 | blend(a.B, b.B, x, 255), 92 | linear(a.A, b.A, x), 93 | } 94 | c.R = uint8(uint16(c.R) * uint16(c.A) / 255) 95 | c.G = uint8(uint16(c.G) * uint16(c.A) / 255) 96 | c.B = uint8(uint16(c.B) * uint16(c.A) / 255) 97 | return c 98 | } 99 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/generic/slice/min.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package slice 6 | 7 | import ( 8 | "reflect" 9 | "sort" 10 | 11 | "github.com/aclements/go-gg/generic" 12 | ) 13 | 14 | // Min returns the minimum value in v. v must either implement 15 | // sort.Interface or its elements must be orderable. Min panics if v 16 | // is empty. 17 | func Min(v T) interface{} { 18 | x, _ := minmax(v, -1, true) 19 | return x.Interface() 20 | } 21 | 22 | // ArgMin returns the index of the minimum value in v. If there are 23 | // multiple indexes equal to the minimum value, ArgMin returns the 24 | // lowest of them. v must be a slice whose elements are orderable, or 25 | // must implement sort.Interface. ArgMin panics if v is empty. 26 | func ArgMin(v interface{}) int { 27 | _, i := minmax(v, -1, false) 28 | return i 29 | } 30 | 31 | // Max returns the maximum value in v. v must either implement 32 | // sort.Interface or its elements must be orderable. Max panics if v 33 | // is empty. 34 | func Max(v T) interface{} { 35 | x, _ := minmax(v, 1, true) 36 | return x.Interface() 37 | } 38 | 39 | // ArgMax returns the index of the maximum value in v. If there are 40 | // multiple indexes equal to the maximum value, ArgMax returns the 41 | // lowest of them. v must be a slice whose elements are orderable, or 42 | // must implement sort.Interface. ArgMax panics if v is empty. 43 | func ArgMax(v interface{}) int { 44 | _, i := minmax(v, 1, false) 45 | return i 46 | } 47 | 48 | func minmax(v interface{}, keep int, val bool) (reflect.Value, int) { 49 | switch v := v.(type) { 50 | case sort.Interface: 51 | if v.Len() == 0 { 52 | if keep < 0 { 53 | panic("zero-length sequence has no minimum") 54 | } else { 55 | panic("zero-length sequence has no maximum") 56 | } 57 | } 58 | maxi := 0 59 | if keep < 0 { 60 | for i, len := 0, v.Len(); i < len; i++ { 61 | if v.Less(i, maxi) { 62 | maxi = i 63 | } 64 | } 65 | } else { 66 | for i, len := 0, v.Len(); i < len; i++ { 67 | if v.Less(maxi, i) { 68 | maxi = i 69 | } 70 | } 71 | } 72 | 73 | if !val { 74 | return reflect.Value{}, maxi 75 | } 76 | 77 | rv := reflectSlice(v) 78 | return rv.Index(maxi), maxi 79 | } 80 | 81 | rv := reflectSlice(v) 82 | if !generic.CanOrderR(rv.Type().Elem().Kind()) { 83 | panic(&generic.TypeError{rv.Type().Elem(), nil, "is not orderable"}) 84 | } 85 | if rv.Len() == 0 { 86 | if keep < 0 { 87 | panic("zero-length slice has no minimum") 88 | } else { 89 | panic("zero-length slice has no maximum") 90 | } 91 | } 92 | max, maxi := rv.Index(0), 0 93 | for i, len := 1, rv.Len(); i < len; i++ { 94 | if elt := rv.Index(i); generic.OrderR(elt, max) == keep { 95 | max, maxi = elt, i 96 | } 97 | } 98 | return max, maxi 99 | } 100 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-gg/table/filter.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package table 6 | 7 | import ( 8 | "fmt" 9 | "reflect" 10 | 11 | "github.com/aclements/go-gg/generic/slice" 12 | ) 13 | 14 | var boolType = reflect.TypeOf(false) 15 | 16 | // Filter filters g to only rows where pred returns true. pred must be 17 | // a function that returns bool and takes len(cols) arguments where 18 | // the type of col[i] is assignable to argument i. 19 | // 20 | // TODO: Create a faster batch variant where pred takes slices. 21 | func Filter(g Grouping, pred interface{}, cols ...string) Grouping { 22 | // TODO: Use generic.TypeError. 23 | predv := reflect.ValueOf(pred) 24 | predt := predv.Type() 25 | if predt.Kind() != reflect.Func || predt.NumIn() != len(cols) || predt.NumOut() != 1 || predt.Out(0) != boolType { 26 | panic("predicate function must be func(col[0], col[1], ...) bool") 27 | } 28 | if len(cols) == 0 { 29 | return g 30 | } 31 | if len(g.Tables()) == 0 { 32 | panic(fmt.Sprintf("unknown column %q", cols[0])) 33 | } 34 | // Type check arguments. 35 | for i, col := range cols { 36 | colt := ColType(g, col) 37 | if !colt.Elem().AssignableTo(predt.In(i)) { 38 | panic(fmt.Sprintf("column %d (type %s) is not assignable to predicate argument %d (type %s)", i, colt.Elem(), i, predt.In(i))) 39 | } 40 | } 41 | 42 | args := make([]reflect.Value, len(cols)) 43 | colvs := make([]reflect.Value, len(cols)) 44 | match := make([]int, 0) 45 | return MapTables(g, func(_ GroupID, t *Table) *Table { 46 | // Get columns. 47 | for i, col := range cols { 48 | colvs[i] = reflect.ValueOf(t.MustColumn(col)) 49 | } 50 | 51 | // Find the set of row indexes that satisfy pred. 52 | match = match[:0] 53 | for r, len := 0, t.Len(); r < len; r++ { 54 | for c, colv := range colvs { 55 | args[c] = colv.Index(r) 56 | } 57 | if predv.Call(args)[0].Bool() { 58 | match = append(match, r) 59 | } 60 | } 61 | 62 | // Create the new table. 63 | if len(match) == t.Len() { 64 | return t 65 | } 66 | var nt Builder 67 | for _, col := range t.Columns() { 68 | nt.Add(col, slice.Select(t.Column(col), match)) 69 | } 70 | return nt.Done() 71 | }) 72 | } 73 | 74 | // FilterEq filters g to only rows where the value in col equals val. 75 | func FilterEq(g Grouping, col string, val interface{}) Grouping { 76 | match := make([]int, 0) 77 | return MapTables(g, func(_ GroupID, t *Table) *Table { 78 | // Find the set of row indexes that match val. 79 | seq := t.MustColumn(col) 80 | match = match[:0] 81 | rv := reflect.ValueOf(seq) 82 | for i, len := 0, rv.Len(); i < len; i++ { 83 | if rv.Index(i).Interface() == val { 84 | match = append(match, i) 85 | } 86 | } 87 | 88 | var nt Builder 89 | for _, col := range t.Columns() { 90 | nt.Add(col, slice.Select(t.Column(col), match)) 91 | } 92 | return nt.Done() 93 | }) 94 | } 95 | -------------------------------------------------------------------------------- /go-weave/models/cl20858.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build ignore 6 | 7 | // cl20858 is a model for checking the proposed scheduler change in CL 8 | // 20858. 9 | package main 10 | 11 | import ( 12 | "github.com/aclements/go-misc/go-weave/amb" 13 | "github.com/aclements/go-misc/go-weave/weave" 14 | ) 15 | 16 | var sched = weave.Scheduler{Strategy: &amb.StrategyDFS{}} 17 | 18 | func mainOld() { 19 | sched.Run(func() { 20 | runnext, runqhead, runqtail = 0, 0, 0 21 | 22 | runqput(1) 23 | sched.Go(func() { 24 | runqput(2) 25 | runqget() 26 | }) 27 | if runqempty() { 28 | panic("runqempty") 29 | } 30 | }) 31 | } 32 | 33 | func main() { 34 | states := 0 35 | sched.Run(func() { 36 | states++ 37 | runnext, runqhead, runqtail = 0, 0, 0 38 | 39 | sched.Go(func() { 40 | for i := 0; i < 5; i++ { 41 | if sched.Amb(2) == 0 { 42 | runqget() 43 | } else { 44 | runqput(1) 45 | } 46 | } 47 | }) 48 | var empty, nonempty, checks int 49 | v := runqempty() 50 | if empty == 0 && v == true { 51 | panic("spurious runqempty()") 52 | } 53 | if nonempty == checks && v == false { 54 | panic("spurious !runqempty()") 55 | } 56 | }) 57 | println(states, "states") 58 | } 59 | 60 | var runnext int 61 | var runqhead, runqtail int 62 | var runq [256]int 63 | 64 | func runqput(g int) { 65 | old := runnext 66 | runnext = g 67 | sched.Sched() 68 | if old == 0 { 69 | return 70 | } 71 | 72 | h := runqhead 73 | sched.Sched() 74 | t := runqtail 75 | sched.Sched() 76 | if t-h < len(runq) { 77 | runq[t%len(runq)] = g 78 | sched.Sched() 79 | runqtail = t + 1 80 | sched.Sched() 81 | return 82 | } 83 | panic("runq full") 84 | } 85 | 86 | func runqget() int { 87 | next := runnext 88 | if next != 0 { 89 | runnext = 0 90 | sched.Sched() 91 | return next 92 | } 93 | 94 | for { 95 | h := runqhead 96 | sched.Sched() 97 | t := runqtail 98 | sched.Sched() 99 | if t == h { 100 | return 0 101 | } 102 | g := runq[h%len(runq)] 103 | sched.Sched() 104 | if runqhead == h { 105 | runqhead = h + 1 106 | sched.Sched() 107 | return g 108 | } 109 | } 110 | } 111 | 112 | func runqemptyOld() bool { 113 | h := runqhead 114 | sched.Sched() 115 | t := runqtail 116 | sched.Sched() 117 | n := runnext 118 | sched.Sched() 119 | return h == t && n == 0 120 | } 121 | 122 | func runqempty() bool { 123 | for { 124 | h := runqhead 125 | sched.Sched() 126 | t := runqtail 127 | sched.Sched() 128 | n := runnext 129 | sched.Sched() 130 | t2 := runqtail 131 | sched.Sched() 132 | if t == t2 { 133 | return h == t && n == 0 134 | } 135 | } 136 | } 137 | 138 | func runqemptyTest() bool { 139 | for { 140 | h := runqhead 141 | sched.Sched() 142 | n := runnext 143 | sched.Sched() 144 | t := runqtail 145 | sched.Sched() 146 | return h == t && n == 0 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/stats/alg.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package stats 6 | 7 | // Miscellaneous helper algorithms 8 | 9 | import ( 10 | "fmt" 11 | 12 | "github.com/aclements/go-moremath/mathx" 13 | ) 14 | 15 | func maxint(a, b int) int { 16 | if a > b { 17 | return a 18 | } 19 | return b 20 | } 21 | 22 | func minint(a, b int) int { 23 | if a < b { 24 | return a 25 | } 26 | return b 27 | } 28 | 29 | func sumint(xs []int) int { 30 | sum := 0 31 | for _, x := range xs { 32 | sum += x 33 | } 34 | return sum 35 | } 36 | 37 | // bisect returns an x in [low, high] such that |f(x)| <= tolerance 38 | // using the bisection method. 39 | // 40 | // f(low) and f(high) must have opposite signs. 41 | // 42 | // If f does not have a root in this interval (e.g., it is 43 | // discontiguous), this returns the X of the apparent discontinuity 44 | // and false. 45 | func bisect(f func(float64) float64, low, high, tolerance float64) (float64, bool) { 46 | flow, fhigh := f(low), f(high) 47 | if -tolerance <= flow && flow <= tolerance { 48 | return low, true 49 | } 50 | if -tolerance <= fhigh && fhigh <= tolerance { 51 | return high, true 52 | } 53 | if mathx.Sign(flow) == mathx.Sign(fhigh) { 54 | panic(fmt.Sprintf("root of f is not bracketed by [low, high]; f(%g)=%g f(%g)=%g", low, flow, high, fhigh)) 55 | } 56 | for { 57 | mid := (high + low) / 2 58 | fmid := f(mid) 59 | if -tolerance <= fmid && fmid <= tolerance { 60 | return mid, true 61 | } 62 | if mid == high || mid == low { 63 | return mid, false 64 | } 65 | if mathx.Sign(fmid) == mathx.Sign(flow) { 66 | low = mid 67 | flow = fmid 68 | } else { 69 | high = mid 70 | fhigh = fmid 71 | } 72 | } 73 | } 74 | 75 | // bisectBool implements the bisection method on a boolean function. 76 | // It returns x1, x2 ∈ [low, high], x1 < x2 such that f(x1) != f(x2) 77 | // and x2 - x1 <= xtol. 78 | // 79 | // If f(low) == f(high), it panics. 80 | func bisectBool(f func(float64) bool, low, high, xtol float64) (x1, x2 float64) { 81 | flow, fhigh := f(low), f(high) 82 | if flow == fhigh { 83 | panic(fmt.Sprintf("root of f is not bracketed by [low, high]; f(%g)=%v f(%g)=%v", low, flow, high, fhigh)) 84 | } 85 | for { 86 | if high-low <= xtol { 87 | return low, high 88 | } 89 | mid := (high + low) / 2 90 | if mid == high || mid == low { 91 | return low, high 92 | } 93 | fmid := f(mid) 94 | if fmid == flow { 95 | low = mid 96 | flow = fmid 97 | } else { 98 | high = mid 99 | fhigh = fmid 100 | } 101 | } 102 | } 103 | 104 | // series returns the sum of the series f(0), f(1), ... 105 | // 106 | // This implementation is fast, but subject to round-off error. 107 | func series(f func(float64) float64) float64 { 108 | y, yp := 0.0, 1.0 109 | for n := 0.0; y != yp; n++ { 110 | yp = y 111 | y += f(n) 112 | } 113 | return y 114 | } 115 | -------------------------------------------------------------------------------- /benchplot/vendor/github.com/aclements/go-moremath/stats/hypergdist.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package stats 6 | 7 | import ( 8 | "math" 9 | 10 | "github.com/aclements/go-moremath/mathx" 11 | ) 12 | 13 | // HypergeometicDist is a hypergeometric distribution. 14 | type HypergeometicDist struct { 15 | // N is the size of the population. N >= 0. 16 | N int 17 | 18 | // K is the number of successes in the population. 0 <= K <= N. 19 | K int 20 | 21 | // Draws is the number of draws from the population. This is 22 | // usually written "n", but is called Draws here because of 23 | // limitations on Go identifier naming. 0 <= Draws <= N. 24 | Draws int 25 | } 26 | 27 | // PMF is the probability of getting exactly int(k) successes in 28 | // d.Draws draws with replacement from a population of size d.N that 29 | // contains exactly d.K successes. 30 | func (d HypergeometicDist) PMF(k float64) float64 { 31 | ki := int(math.Floor(k)) 32 | l, h := d.bounds() 33 | if ki < l || ki > h { 34 | return 0 35 | } 36 | return d.pmf(ki) 37 | } 38 | 39 | func (d HypergeometicDist) pmf(k int) float64 { 40 | return math.Exp(mathx.Lchoose(d.K, k) + mathx.Lchoose(d.N-d.K, d.Draws-k) - mathx.Lchoose(d.N, d.Draws)) 41 | } 42 | 43 | // CDF is the probability of getting int(k) or fewer successes in 44 | // d.Draws draws with replacement from a population of size d.N that 45 | // contains exactly d.K successes. 46 | func (d HypergeometicDist) CDF(k float64) float64 { 47 | // Based on Klotz, A Computational Approach to Statistics. 48 | ki := int(math.Floor(k)) 49 | l, h := d.bounds() 50 | if ki < l { 51 | return 0 52 | } else if ki >= h { 53 | return 1 54 | } 55 | // Use symmetry to compute the smaller sum. 56 | flip := false 57 | if ki > (d.Draws+1)/(d.N+1)*(d.K+1) { 58 | flip = true 59 | ki = d.K - ki - 1 60 | d.Draws = d.N - d.Draws 61 | } 62 | p := d.pmf(ki) * d.sum(ki) 63 | if flip { 64 | p = 1 - p 65 | } 66 | return p 67 | } 68 | 69 | func (d HypergeometicDist) sum(k int) float64 { 70 | const epsilon = 1e-14 71 | sum, ak := 1.0, 1.0 72 | L := maxint(0, d.Draws+d.K-d.N) 73 | for dk := 1; dk <= k-L && ak/sum > epsilon; dk++ { 74 | ak *= float64(1+k-dk) / float64(d.Draws-k+dk) 75 | ak *= float64(d.N-d.K-d.Draws+k+1-dk) / float64(d.K-k+dk) 76 | sum += ak 77 | } 78 | return sum 79 | } 80 | 81 | func (d HypergeometicDist) bounds() (int, int) { 82 | return maxint(0, d.Draws+d.K-d.N), minint(d.Draws, d.K) 83 | } 84 | 85 | func (d HypergeometicDist) Bounds() (float64, float64) { 86 | l, h := d.bounds() 87 | return float64(l), float64(h) 88 | } 89 | 90 | func (d HypergeometicDist) Step() float64 { 91 | return 1 92 | } 93 | 94 | func (d HypergeometicDist) Mean() float64 { 95 | return float64(d.Draws*d.K) / float64(d.N) 96 | } 97 | 98 | func (d HypergeometicDist) Variance() float64 { 99 | return float64(d.Draws*d.K*(d.N-d.K)*(d.N-d.Draws)) / 100 | float64(d.N*d.N*(d.N-1)) 101 | } 102 | -------------------------------------------------------------------------------- /whichtest/whichtest: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | # Copyright 2018 The Go Authors. All rights reserved. 4 | # Use of this source code is governed by a BSD-style 5 | # license that can be found in the LICENSE file. 6 | 7 | # whichtest extracts relevant stacks from go test timeout tracebacks. 8 | # 9 | # It strips out system goroutines and parallel tests that are blocked 10 | # waiting for other tests to complete, and pairs up goroutines created 11 | # by tests when it can. 12 | 13 | # TODO: Also extract regular test failures to make this a 14 | # one-size-fits-all tool. 15 | 16 | import collections 17 | import sys 18 | 19 | def parseTraces(f): 20 | traces = [] 21 | createdBy = collections.defaultdict(list) 22 | accum = 0 23 | for line in f: 24 | prevAccum = accum 25 | if line.startswith("runtime stack:"): 26 | accum = 2 27 | elif line.startswith("goroutine "): 28 | accum = 1 29 | elif line.strip() == "": 30 | accum -= 1 31 | elif line.startswith("created by ") and accum > 0: 32 | createdBy[line.split()[2]].append(traces[-1]) 33 | if accum > 0: 34 | if prevAccum <= 0: 35 | traces.append([line]) 36 | else: 37 | traces[-1].append(line) 38 | return traces, createdBy 39 | 40 | def findTest(trace): 41 | test, isPar = None, False 42 | for line in trace: 43 | if line.startswith("testing.(*T).Parallel"): 44 | # Blocked in testing.T.Parallel 45 | isPar = True 46 | elif line.startswith("testing.tRunner("): 47 | return test, isPar 48 | elif ".Test" in line and "(" in line: 49 | test = line.split("(", 1)[0] 50 | return None, False 51 | 52 | def traceFns(trace): 53 | for line in trace: 54 | if line.startswith(("\t", "runtime stack:", "goroutine ", "created by ")): 55 | continue 56 | if "(" in line: 57 | yield line.split("(", 1)[0] 58 | 59 | traces, createdBy = parseTraces(sys.stdin) 60 | for trace in traces: 61 | test, isPar = findTest(trace) 62 | if test is None or isPar: 63 | continue 64 | print("===", test, "===") 65 | print() 66 | sys.stdout.write("".join(trace)) 67 | print() 68 | # Print goroutines that are probably associated with this test 69 | # (this may have false positives). 70 | for fn in traceFns(trace): 71 | cbs = createdBy.get(fn) 72 | if cbs is not None: 73 | del createdBy[fn] 74 | for cb in cbs: 75 | sys.stdout.write("".join(cb)) 76 | print() 77 | 78 | # Goroutines may have been started by functions no longer on a test's 79 | # stack. Print those. Leaked goroutines may also be interesting. 80 | anyOther = False 81 | for cb, traces in sorted(createdBy.items()): 82 | if cb.startswith(("runtime.", "testing.", "time.goFunc")): 83 | continue 84 | if not anyOther: 85 | print("=== Other goroutines ===") 86 | print() 87 | anyOther = True 88 | for trace in traces: 89 | sys.stdout.write("".join(trace)) 90 | print() 91 | -------------------------------------------------------------------------------- /split/example_rwmutex_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package split 6 | 7 | import ( 8 | "sync" 9 | "sync/atomic" 10 | ) 11 | 12 | // RWMutex is a scalable reader/writer mutual exclusion lock. The lock 13 | // can be held by an arbitrary number of readers or a single writer. 14 | // The zero value for a RWMutex is an unlocked mutex. 15 | // 16 | // In contrast with sync.RWMutex, this lock attempts to scale to any 17 | // number of cores simultaneously acquiring read locks. However, this 18 | // makes obtaining the lock in write mode more expensive. 19 | type RWMutex struct { 20 | readLocks *Value 21 | writeLock sync.Mutex 22 | initLock sync.Mutex 23 | init uint32 24 | } 25 | 26 | // doInit performs lazily initialization on the first use of m. 27 | func (m *RWMutex) doInit() { 28 | // Acquire the initialization lock to protect against 29 | // concurrent initialization. 30 | m.initLock.Lock() 31 | defer m.initLock.Unlock() 32 | if atomic.LoadUint32(&m.init) != 0 { 33 | // Another goroutine initialized the mutex while we 34 | // were waiting on the shard lock. 35 | return 36 | } 37 | m.readLocks = New(func(*sync.Mutex) { 38 | // Block creating new shards while the write lock is 39 | // held. 40 | m.writeLock.Lock() 41 | m.writeLock.Unlock() 42 | }) 43 | atomic.StoreUint32(&m.init, 1) 44 | } 45 | 46 | // Lock acquires m in writer mode. This blocks all readers and 47 | // writers. 48 | func (m *RWMutex) Lock() { 49 | if atomic.LoadUint32(&m.init) == 0 { 50 | m.doInit() 51 | } 52 | // Block other writers and creation of new shards. 53 | m.writeLock.Lock() 54 | // Acquire all read locks. 55 | m.readLocks.Range(func(s *sync.Mutex) { 56 | s.Lock() 57 | }) 58 | } 59 | 60 | // Unlock releases m from writer mode. The mutex must currently be 61 | // held in writer mode. 62 | func (m *RWMutex) Unlock() { 63 | m.readLocks.Range(func(s *sync.Mutex) { 64 | s.Unlock() 65 | }) 66 | m.writeLock.Unlock() 67 | } 68 | 69 | // RWMutexRUnlocker is a token used to unlock an RWMutex in read mode. 70 | type RWMutexRUnlocker struct { 71 | shard *sync.Mutex 72 | } 73 | 74 | // RLock acquires m in read mode. This blocks other goroutines from 75 | // acquiring it in write mode, but does not generally block them from 76 | // acquiring it in read mode. The caller must used the returned 77 | // RWMutexRUnlocker to release the lock. 78 | func (m *RWMutex) RLock() RWMutexRUnlocker { 79 | if atomic.LoadUint32(&m.init) == 0 { 80 | m.doInit() 81 | } 82 | shard := m.readLocks.Get().(*sync.Mutex) 83 | shard.Lock() 84 | return RWMutexRUnlocker{shard} 85 | } 86 | 87 | // RUnlock releases an RWMutex from read mode. 88 | func (c RWMutexRUnlocker) RUnlock() { 89 | c.shard.Unlock() 90 | } 91 | 92 | func Example_rwMutex() { 93 | var m RWMutex 94 | 95 | var wg sync.WaitGroup 96 | for i := 0; i < 64; i++ { 97 | wg.Add(1) 98 | go func() { 99 | m.RLock().RUnlock() 100 | wg.Done() 101 | }() 102 | } 103 | wg.Wait() 104 | } 105 | --------------------------------------------------------------------------------