Commit 155506a9 authored by Kirill Smelkov's avatar Kirill Smelkov

*: ~gofmt

parent 0399d7ad
......@@ -22,13 +22,12 @@
// usage: `go tool trace -d <trace.out> |gmigrate`
package main
import (
"bufio"
"errors"
"fmt"
"io"
"log"
"fmt"
"os"
"regexp"
"sort"
......@@ -64,19 +63,19 @@ type goStart struct {
// information about a G
type gInfo struct {
g int
g int
m int // last time was running on this M
nmigrate int // how much times migrated between different Ms
}
func main() {
var pm = map[int]int{} // p -> m
var gg = map[int]*gInfo{} // g -> (m, #migrate)
var pm = map[int]int{} // p -> m
var gg = map[int]*gInfo{} // g -> (m, #migrate)
in := bufio.NewReader(os.Stdin)
tstart, tend, tprev := -1, -1, -1
for lineno := 1;; lineno++{
for lineno := 1; ; lineno++ {
bad := func(err error) {
log.Fatalf("%d: %v", lineno, err)
}
......@@ -187,7 +186,7 @@ func parseLineHeader(l string) (t int, event, args string, err error) {
// ex: 9782014 ProcStart p=2 g=0 off=133138 thread=5
var (
pStartArgvRe = regexp.MustCompile("^p=([^ ]+) g=[^ ]+ off=[^ ]+ thread=([^ ]+)$")
pStartArgvRe = regexp.MustCompile("^p=([^ ]+) g=[^ ]+ off=[^ ]+ thread=([^ ]+)$")
pStartArgvErr = errors.New("ProcStart: argv invalid")
)
......@@ -214,7 +213,7 @@ func parseProcStart(args string) (procStart, error) {
// ex: 9782310 GoStart p=2 g=33 off=133142 g=33 seq=0
var (
gStartArgvRe = regexp.MustCompile("^p=([^ ]+) g=([^ ]+) off=[^ ]+ g=([^ ]+) seq=[^ ]+$")
gStartArgvRe = regexp.MustCompile("^p=([^ ]+) g=([^ ]+) off=[^ ]+ g=([^ ]+) seq=[^ ]+$")
gStartArgvErr = errors.New("GoStart: argv invalid")
)
......
......@@ -112,9 +112,10 @@ func Raisef(format string, a ...interface{}) {
// Raiseif raises if err != nil.
//
// NOTE err can be != nil even if typed obj = nil:
// var obj *T;
// err = obj
// err != nil is true
//
// var obj *T;
// err = obj
// err != nil is true
func Raiseif(err error) {
//if err != nil && !reflect.ValueOf(err).IsNil() {
if err != nil {
......
......@@ -20,6 +20,7 @@
// As of go19 sync.Pool under race-detector randomly drops items on the floor
// https://github.com/golang/go/blob/ca360c39/src/sync/pool.go#L92
// so it is not possible to verify we will get what we've just put there.
//go:build !race
// +build !race
package mem
......
......@@ -35,10 +35,10 @@ import (
// Command describes one program subcommand.
type Command struct {
Name string
Summary string
Usage func (w io.Writer)
Main func (argv []string)
Name string
Summary string
Usage func(w io.Writer)
Main func(argv []string)
}
// CommandRegistry is ordered collection of Commands.
......@@ -78,10 +78,10 @@ func (helpv HelpRegistry) Lookup(topic string) *HelpTopic {
// MainProg defines a program to run with subcommands and help topics.
type MainProg struct {
Name string // name of the program, e.g. "zodb"
Summary string // 1-line summary of what program does
Commands CommandRegistry // provided subcommands
HelpTopics HelpRegistry // provided help topics
Name string // name of the program, e.g. "zodb"
Summary string // 1-line summary of what program does
Commands CommandRegistry // provided subcommands
HelpTopics HelpRegistry // provided help topics
}
// Exit is like os.Exit but makes sure deferred functions are run.
......
......@@ -1033,7 +1033,7 @@ var commands = prog.CommandRegistry{
}
var helpTopics = prog.HelpRegistry{
// XXX for now empty
// XXX for now empty
}
var gotrace = prog.MainProg{
......
......@@ -17,6 +17,7 @@
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
//go:build race
// +build race
package race
......
......@@ -17,6 +17,7 @@
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
//go:build !race
// +build !race
package race
......
......@@ -17,6 +17,7 @@
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
//go:build race
// +build race
package xruntime
......
......@@ -17,6 +17,7 @@
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
//go:build !race
// +build !race
package xruntime
......
......@@ -79,7 +79,7 @@ func TestStartStopTheWorld(t *testing.T) {
:= 0
tstart := time.Now()
for time.Now().Sub(tstart) < time.Second {
for i := 0; i < 100 ; i++ {
for i := 0; i < 100; i++ {
xnext = atomic.LoadInt32(&x)
if xnext != xprev {
+= 1
......
......@@ -37,7 +37,7 @@ var (
//
// The goroutine which sent the message will wait for Ack before continue.
type _Msg struct {
Event interface {}
Event interface{}
ack chan<- error // nil on Ack; !nil on nak
}
......
......@@ -33,16 +33,16 @@
// Verification of events for all streams can be done by one *sequential*
// process:
//
// - if events A and B in different streams are unrelated to each other by
// causality, the sequence of checks models a particular possible flow of
// time. Notably since events are delivered synchronously and sender is
// blocked until receiver/checker explicitly confirms event has been
// processed, by checking either A then B, or B then A allows to check
// for a particular race-condition.
// - if events A and B in different streams are unrelated to each other by
// causality, the sequence of checks models a particular possible flow of
// time. Notably since events are delivered synchronously and sender is
// blocked until receiver/checker explicitly confirms event has been
// processed, by checking either A then B, or B then A allows to check
// for a particular race-condition.
//
// - if events A and B in different streams are related to each other by
// causality (i.e. there is some happens-before relation for them) the
// sequence of checking should represent that ordering relation.
// - if events A and B in different streams are related to each other by
// causality (i.e. there is some happens-before relation for them) the
// sequence of checking should represent that ordering relation.
//
// Basic package usage is as follows:
//
......@@ -104,12 +104,12 @@ package tracetest
import (
"fmt"
"path/filepath"
"sort"
"strings"
"sync"
"reflect"
"runtime"
"runtime/debug"
"sort"
"strings"
"sync"
"testing"
"time"
......
......@@ -20,7 +20,7 @@
/*
Package tracing provides usage and runtime support for Go tracing facilities.
Trace events
# Trace events
A Go package can define several events of interest to trace via special
comments. With such definition a tracing event becomes associated with trace
......@@ -40,7 +40,7 @@ function that is used to signal when the event happens. For example:
By default using trace function does nothing and has very small overhead(*).
Probes
# Probes
However it is possible to attach probing functions to events. A probe, once
attached, is called whenever event is signalled in the context which triggered
......@@ -95,12 +95,12 @@ all at once using ProbeGroup:
Probes is general mechanism which allows various kinds of trace events usage.
Three ways particularly are well-understood and handy:
- recording events stream
- profiling
- synchronous tracing
- recording events stream
- profiling
- synchronous tracing
Recording events stream
# Recording events stream
To get better understanding of what happens when it is possible to record
events into a stream and later either visualize or postprocess them.
......@@ -117,7 +117,7 @@ understood by chromium trace-viewer: https://github.com/catapult-project/catapul
NOTE there is also talk/work to implement user events for runtime/trace: https://golang.org/issues/16619.
Profiling
# Profiling
A profile is aggregate summary of collection of stack traces showing the call sequences that led
to instances of a particular event. One could create runtime/pprof.Profile and
......@@ -131,25 +131,25 @@ XXX Profile.Add needs unique value for each invocation - how do we do? Provide N
XXX should tracing provide more tight integration with runtime/pprof.Profile?
Synchronous tracing
# Synchronous tracing
For testing purposes it is sometimes practical to leverage the property that
probes pause original code execution until the probe run is finished. That
means while the probe is running original goroutine
- is paused at well-defined point (where trace function is called), thus
- it cannot mutate any state it is programmed to mutate.
- is paused at well-defined point (where trace function is called), thus
- it cannot mutate any state it is programmed to mutate.
Using this properties it is possible to attach testing probes and verify that
a set of goroutines in tested code in question
- produce events in correct order, and
- at every event associated internal state is correct.
- produce events in correct order, and
- at every event associated internal state is correct.
Please see package lab.nexedi.com/kirr/go123/tracing/tracetest for details.
Cross package tracing
# Cross package tracing
Trace events are not part of exported package API with rationale that package's
regular API and internal trace events usually have different stability
......@@ -172,7 +172,7 @@ available as regular functions prefixed with imported package name:
...
Gotrace
# Gotrace
The way //trace:event and //trace:import work is via additional code being
generated for them. Whenever a package uses any //trace: directive,
......
......@@ -22,7 +22,6 @@ package xbufio
import (
"io"
//"log"
)
......@@ -31,17 +30,18 @@ import (
// Both forward, backward and interleaved forward/backward access patterns are supported
//
// NOTE SeqReaderAt is not safe to use from multiple goroutines concurrently.
//
// Strictly speaking this goes against io.ReaderAt interface but sequential
// workloads usually mean sequential processing. It would be a pity to
// add mutex for nothing.
// workloads usually mean sequential processing. It would be a pity to
// add mutex for nothing.
type SeqReaderAt struct {
// buffer for data at pos. cap(buf) - whole buffer capacity
buf []byte
pos int64
buf []byte
pos int64
posLastAccess int64 // position of last access request
posLastFwdAfter int64 // position of last forward access request
posLastBackward int64 // position of last backward access request
posLastAccess int64 // position of last access request
posLastFwdAfter int64 // position of last forward access request
posLastBackward int64 // position of last backward access request
r io.ReaderAt
......
......@@ -232,7 +232,7 @@ func TestSeqReaderAt(t *testing.T) {
}
// verify buffer state
if !(rb.pos == tt.bufPos && len(rb.buf) == tt.bufLen){
if !(rb.pos == tt.bufPos && len(rb.buf) == tt.bufLen) {
t.Fatalf("%v: -> unexpected buffer state @%v #%v", tt, rb.pos, len(rb.buf))
}
}
......
......@@ -19,7 +19,7 @@
// Package xcontext provides addons to std package context.
//
// Merging contexts
// # Merging contexts
//
// Merge could be handy in situations where spawned job needs to be canceled
// whenever any of 2 contexts becomes done. This frequently arises with service
......@@ -84,9 +84,9 @@ type mergeCtx struct {
//
// The result context:
//
// - is done when parent1 or parent2 is done, or cancel called, whichever happens first,
// - has deadline = min(parent1.Deadline, parent2.Deadline),
// - has associated values merged from parent1 and parent2, with parent1 taking precedence.
// - is done when parent1 or parent2 is done, or cancel called, whichever happens first,
// - has deadline = min(parent1.Deadline, parent2.Deadline),
// - has associated values merged from parent1 and parent2, with parent1 taking precedence.
//
// Canceling this context releases resources associated with it, so code should
// call cancel as soon as the operations running in this Context complete.
......@@ -229,9 +229,9 @@ type chanCtx struct {
//
// MergeChan, similarly to Merge, provides resulting context which:
//
// - is done when parent1 is done or done2 is closed, or cancel called, whichever happens first,
// - has the same deadline as parent1,
// - has the same associated values as parent1.
// - is done when parent1 is done or done2 is closed, or cancel called, whichever happens first,
// - has the same deadline as parent1,
// - has the same associated values as parent1.
//
// Canceling this context releases resources associated with it, so code should
// call cancel as soon as the operations running in this Context complete.
......
......@@ -19,8 +19,7 @@
// Package xerr provides addons for error-handling.
//
//
// Error context
// # Error context
//
// Context and Contextf are handy to concisely add context to returned error,
// for example:
......@@ -37,8 +36,7 @@
// returned error. Please see package github.com/pkg/errors for details on
// this topic.
//
//
// Error vector
// # Error vector
//
// Sometimes there are several operations performed and we want to collect
// errors from them all. For this Errorv could be used which is vector of
......@@ -82,9 +80,9 @@ type Errorv []error
// Error returns string representation of error vector.
//
// - "" if len(errv)==0
// - errv[0].Error() if len(errv)==1
// - "<n> errors:\n" + string representation of every error on separate line, otherwise.
// - "" if len(errv)==0
// - errv[0].Error() if len(errv)==1
// - "<n> errors:\n" + string representation of every error on separate line, otherwise.
func (errv Errorv) Error() string {
switch len(errv) {
case 0:
......@@ -120,9 +118,9 @@ func (errv *Errorv) Appendf(format string, a ...interface{}) {
// Err returns error in canonical form accumulated in error vector.
//
// - nil if len(errv)==0
// - errv[0] if len(errv)==1 // XXX is this good idea?
// - errv otherwise
// - nil if len(errv)==0
// - errv[0] if len(errv)==1 // XXX is this good idea?
// - errv otherwise
func (errv Errorv) Err() error {
switch len(errv) {
case 0:
......@@ -138,9 +136,9 @@ func (errv Errorv) Err() error {
//
// it returns:
//
// - nil if all errors are nil
// - single error if there is only one non-nil error
// - Errorv with non-nil errors if there is more than one non-nil error
// - nil if all errors are nil
// - single error if there is only one non-nil error
// - Errorv with non-nil errors if there is more than one non-nil error
func Merge(errv ...error) error {
ev := Errorv{}
for _, err := range errv {
......@@ -195,7 +193,7 @@ func Context(errp *error, context string) {
// Contextf is formatted analog of Context. Please see Context for details on how to use.
func Contextf(errp *error, format string, argv ...interface{}) {
if *errp == nil {
return
return
}
*errp = errors.WithMessage(*errp, fmt.Sprintf(format, argv...))
......
......@@ -182,14 +182,14 @@ func (b *Buffer) Xs(x string) *Buffer {
// AppendHex016 appends to b x formatted 16-character hex string.
func AppendHex016(b []byte, x uint64) []byte {
// like sprintf("%016x") but faster and less allocations
// like sprintf("%016x") but faster and less allocations
l := len(b)
b = xbytes.Grow(b, 16)
b = xbytes.Grow(b, 16)
bb := b[l:]
for i := 15; i >= 0; i-- {
bb[i] = hexdigits[x & 0xf]
x >>= 4
}
for i := 15; i >= 0; i-- {
bb[i] = hexdigits[x&0xf]
x >>= 4
}
return b
}
......
......@@ -19,19 +19,19 @@
// Package xio provides addons to standard package io.
//
// - Reader, Writer, ReadWriter, etc are io analogs that add support for contexts.
// - BindCtx*(X, ctx) converts xio.X into io.X that implicitly passes ctx
// to xio.X and can be used in legacy code.
// - WithCtx*(X) converts io.X back into xio.X that accepts context.
// It is the opposite operation for BindCtx, but for arbitrary io.X
// returned xio.X handles context only on best-effort basis. In
// particular IO cancellation is not reliably handled for os.File .
// - Pipe amends io.Pipe and creates synchronous in-memory pipe that
// supports IO cancellation.
// - Reader, Writer, ReadWriter, etc are io analogs that add support for contexts.
// - BindCtx*(X, ctx) converts xio.X into io.X that implicitly passes ctx
// to xio.X and can be used in legacy code.
// - WithCtx*(X) converts io.X back into xio.X that accepts context.
// It is the opposite operation for BindCtx, but for arbitrary io.X
// returned xio.X handles context only on best-effort basis. In
// particular IO cancellation is not reliably handled for os.File .
// - Pipe amends io.Pipe and creates synchronous in-memory pipe that
// supports IO cancellation.
//
// Miscellaneous utilities:
//
// - CountReader provides InputOffset for a Reader.
// - CountReader provides InputOffset for a Reader.
package xio
import (
......
......@@ -17,6 +17,7 @@
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
//go:build !go1.9
// +build !go1.9
package xmath
......
......@@ -17,6 +17,7 @@
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
//go:build go1.9
// +build go1.9
// Package xmath provides addons to std math package.
......
......@@ -35,11 +35,11 @@ import (
// only initiation events are traced:
//
// 1. Tx only (no Rx):
// - because Write, contrary to Read, never writes partial data on non-error
// - because in case of pipenet tracing writes only is enough to get whole network exchange picture
// - because Write, contrary to Read, never writes partial data on non-error
// - because in case of pipenet tracing writes only is enough to get whole network exchange picture
//
// 2. Dial only (no Accept)
// - for similar reasons.
// - for similar reasons.
//
// WARNING NetTrace functionality is currently very draft.
func NetTrace(inner Networker, tracerx TraceReceiver) *Tracer {
......
......@@ -136,10 +136,10 @@ type Accept struct {
//
// The registry could be implemented in several ways, for example:
//
// - dedicated network server,
// - hosts broadcasting information to each other similar to ARP,
// - shared memory or file,
// - ...
// - dedicated network server,
// - hosts broadcasting information to each other similar to ARP,
// - shared memory or file,
// - ...
//
// It should be safe to access registry from multiple goroutines simultaneously.
type Registry interface {
......
......@@ -27,8 +27,7 @@
// Package virtnet provides infrastructure for using and implementing such
// TCP-like virtual networks.
//
//
// Using virtnet networks
// # Using virtnet networks
//
// Addresses on a virtnet network are host:port pairs represented by Addr.
// A network conceptually consists of several SubNetworks each being home for
......@@ -49,8 +48,7 @@
// lab.nexedi.com/kirr/go123/xnet/pipenet for particular well-known
// virtnet-based networks.
//
//
// Implementing virtnet networks
// # Implementing virtnet networks
//
// To implement a virtnet-based network one need to implement Engine and Registry.
//
......
......@@ -159,8 +159,8 @@ const serialOnly testFlag = 1
//
// two scenarios are verified:
//
// - serial case: first close, then test, and
// - concurrent case: close is run in parallel to test.
// - serial case: first close, then test, and
// - concurrent case: close is run in parallel to test.
//
// if concurrent case is not applicable for test (e.g. it tries to run a
// function that does not block, like e.g. NewHost in pipenet case), it can be
......
......@@ -17,6 +17,7 @@
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
//go:build !race
// +build !race
// Package race complements standard package runtime/race.
......
......@@ -17,6 +17,7 @@
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
//go:build race
// +build race
package race
......
......@@ -19,7 +19,7 @@
// Package xsync complements standard package sync.
//
// - `WorkGroup` allows to spawn group of goroutines working on a common task.
// - `WorkGroup` allows to spawn group of goroutines working on a common task.
//
// Functionality provided by xsync package is also provided by Pygolang(*) in its
// standard package sync.
......@@ -37,17 +37,17 @@ import (
// Use .Go() to spawn goroutines, and .Wait() to wait for all of them to
// complete, for example:
//
// wg := xsync.NewWorkGroup(ctx)
// wg.Go(f1)
// wg.Go(f2)
// err := wg.Wait()
// wg := xsync.NewWorkGroup(ctx)
// wg.Go(f1)
// wg.Go(f2)
// err := wg.Wait()
//
// Every spawned function accepts context related to the whole work and derived
// from ctx used to initialize WorkGroup, for example:
//
// func f1(ctx context.Context) error {
// ...
// }
// func f1(ctx context.Context) error {
// ...
// }
//
// Whenever a function returns error, the work context is canceled indicating
// to other spawned goroutines that they have to cancel their work. .Wait()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment