Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add incremental speed status mode for more responsive speed and estimates #15

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.22.x
go-version: 1.23.x
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v4.0.0
uses: golangci/golangci-lint-action@v6.1.0
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.56.2
version: v1.61.0

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gorelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ concurrency:
cancel-in-progress: true

env:
GO_VERSION: 1.22.x
GO_VERSION: 1.23.x
jobs:
gorelease:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- created
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GO_VERSION: 1.22.x
GO_VERSION: 1.23.x
LINUX_AMD64_BUILD_OPTIONS: '-tags cgo_zstd'
GOAMD64: v3
jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
test:
strategy:
matrix:
go-version: [ 1.20.x, 1.21.x, 1.22.x ]
go-version: [ 1.21.x, 1.22.x, 1.23.x ]
runs-on: ubuntu-latest
steps:
- name: Install Go stable
Expand Down
17 changes: 7 additions & 10 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,32 @@ linters:
enable-all: true
disable:
- lll
- maligned
- gochecknoglobals
- gomnd
- wrapcheck
- paralleltest
- forbidigo
- exhaustivestruct
- interfacer # deprecated
- forcetypeassert
- scopelint # deprecated
- ifshort # too many false positives
- golint # deprecated
- varnamelen
- tagliatelle
- errname
- ireturn
- exhaustruct
- nonamedreturns
- nosnakecase
- structcheck
- varcheck
- deadcode
- testableexamples
- dupword
- depguard
- tagalign
- execinquery
- mnd
- testifylint

issues:
exclude-use-default: false
exclude-rules:
- linters:
- gomnd
- mnd
- goconst
- goerr113
- noctx
Expand All @@ -71,4 +65,7 @@ issues:
- errcheck # Error checking omitted for brevity.
- gosec
path: "example_"
- linters:
- revive
text: "unused-parameter: parameter"

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#GOLANGCI_LINT_VERSION := "v1.56.2" # Optional configuration to pinpoint golangci-lint version.
#GOLANGCI_LINT_VERSION := "v1.61.0" # Optional configuration to pinpoint golangci-lint version.

# The head of Makefile determines location of dev-go to include standard targets.
GO ?= go
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/bool64/progress
go 1.21

require (
github.com/DataDog/zstd v1.5.5
github.com/bool64/dev v0.2.34
github.com/klauspost/compress v1.17.8
github.com/DataDog/zstd v1.5.6
github.com/bool64/dev v0.2.36
github.com/klauspost/compress v1.17.10
github.com/klauspost/pgzip v1.2.6
)
16 changes: 6 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
github.com/DataDog/zstd v1.5.5 h1:oWf5W7GtOLgp6bciQYDmhHHjdhYkALu6S/5Ni9ZgSvQ=
github.com/DataDog/zstd v1.5.5/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/bool64/dev v0.2.33 h1:ETAcSa8H9w4talcCdSQCCnLX7PMHmuxdLcDl6TpSDj4=
github.com/bool64/dev v0.2.33/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
github.com/bool64/dev v0.2.34 h1:P9n315P8LdpxusnYQ0X7MP1CZXwBK5ae5RZrd+GdSZE=
github.com/bool64/dev v0.2.34/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4=
github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU=
github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/DataDog/zstd v1.5.6 h1:LbEglqepa/ipmmQJUDnSsfvA8e8IStVcGaFWDuxvGOY=
github.com/DataDog/zstd v1.5.6/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/bool64/dev v0.2.36 h1:yU3bbOTujoxhWnt8ig8t94PVmZXIkCaRj9C57OtqJBY=
github.com/bool64/dev v0.2.36/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
github.com/klauspost/compress v1.17.10 h1:oXAz+Vh0PMUvJczoi+flxpnBEPxoER1IaAnU/NMPtT0=
github.com/klauspost/compress v1.17.10/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
github.com/klauspost/pgzip v1.2.6 h1:8RXeL5crjEUFnR2/Sn6GJNWtSQ3Dk8pq4CL3jvdDyjU=
github.com/klauspost/pgzip v1.2.6/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs=
70 changes: 54 additions & 16 deletions progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Task string `json:"task"`
DonePercent float64 `json:"done_percent"`
LinesCompleted int64 `json:"lines_completed"`
BytesCompleted int64 `json:"bytes_completed"`
SpeedMBPS float64 `json:"speed_mbps"`
SpeedLPS float64 `json:"speed_lps"`
Elapsed time.Duration `json:"-"`
Expand All @@ -27,13 +28,20 @@
Print func(status Status)
ShowHeapStats bool
ShowLinesStats bool
done chan bool
task Task
lines func() int64
current func() int64
tot func() int64
prnt func(s Status)
start time.Time

// IncrementalSpeed shows speed and remaining estimate based on performance between two status updates.
IncrementalSpeed bool

done chan bool
task Task
lines func() int64
current func() int64
tot func() int64
prnt func(s Status)
start time.Time

prevStatus Status

continuedLines int64
continuedBytes int64
metrics []Metric
Expand Down Expand Up @@ -191,16 +199,34 @@
p.metrics = nil
}

func (p *Progress) printStatus(last bool) {
s := Status{}
s.Task = p.task.Task
s.LinesCompleted = p.Lines()
s.Metrics = p.metrics
func (p *Progress) speedStatus(s *Status) {
if p.IncrementalSpeed {
lc := s.LinesCompleted - p.prevStatus.LinesCompleted
bc := s.BytesCompleted - p.prevStatus.BytesCompleted
dc := s.DonePercent - p.prevStatus.DonePercent
ela := s.Elapsed - p.prevStatus.Elapsed

Check notice on line 207 in progress.go

View workflow job for this annotation

GitHub Actions / test (1.22.x)

12 statement(s) on lines 202:211 are not covered by tests.

b := float64(p.Bytes())
s.DonePercent = 100 * b / float64(p.tot())
s.Elapsed = time.Since(p.start)
s.SpeedMBPS = (b / s.Elapsed.Seconds()) / (1024 * 1024)
if lc > 0 {
s.SpeedLPS = float64(lc) / ela.Seconds()
}

Check notice on line 211 in progress.go

View workflow job for this annotation

GitHub Actions / test (1.22.x)

6 statement(s) on lines 203:211 are not covered by tests.

if bc > 0 {
s.SpeedMBPS = (float64(bc) / ela.Seconds()) / (1024 * 1024)
}

Check notice on line 215 in progress.go

View workflow job for this annotation

GitHub Actions / test (1.22.x)

2 statement(s) are not covered by tests.

if s.DonePercent > 0 {
s.Remaining = time.Duration((100.0 - s.DonePercent) * float64(ela) / dc)
s.Remaining = s.Remaining.Truncate(time.Second)
} else {
s.Remaining = 0
}

Check notice on line 222 in progress.go

View workflow job for this annotation

GitHub Actions / test (1.22.x)

6 statement(s) are not covered by tests.

p.prevStatus = *s

return

Check notice on line 226 in progress.go

View workflow job for this annotation

GitHub Actions / test (1.22.x)

2 statement(s) are not covered by tests.
}

s.SpeedMBPS = (float64(s.BytesCompleted) / s.Elapsed.Seconds()) / (1024 * 1024)

Check notice on line 229 in progress.go

View workflow job for this annotation

GitHub Actions / test (1.22.x)

3 statement(s) on lines 229:232 are not covered by tests.
s.SpeedLPS = float64(s.LinesCompleted) / s.Elapsed.Seconds()

if s.DonePercent > 0 {
Expand All @@ -209,6 +235,18 @@
} else {
s.Remaining = 0
}
}

func (p *Progress) printStatus(last bool) {
s := Status{}
s.Task = p.task.Task
s.LinesCompleted = p.Lines()
s.BytesCompleted = p.Bytes()
s.Metrics = p.metrics
s.Elapsed = time.Since(p.start)
s.DonePercent = 100 * float64(s.BytesCompleted) / float64(p.tot())

p.speedStatus(&s)

Check notice on line 249 in progress.go

View workflow job for this annotation

GitHub Actions / test (1.22.x)

9 statement(s) on lines 240:251 are not covered by tests.

if s.Remaining > 100*time.Millisecond || s.Remaining == 0 || last {
p.prnt(s)
Expand Down
Loading