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