Skip to content
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
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ jobs:
go-version: oldstable
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v9.2.0
uses: golangci/golangci-lint-action@v9.3.0
with:
version: v2.11.3
version: v2.15.0
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ run:
linters:
default: all
disable:
- exhaustruct_v5
- cyclop
- err113
- errcheck
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#GOLANGCI_LINT_VERSION := "v2.11.3" # Optional configuration to pinpoint golangci-lint version.
#GOLANGCI_LINT_VERSION := "v2.15.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
2 changes: 1 addition & 1 deletion cmd/catp/catp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func Main(options ...func(o *Options)) error { //nolint:funlen,cyclop,gocognit,g

flag.IntVar(&r.parallel, "parallel", 1, "number of parallel readers if multiple files are provided\n"+
"lines from different files will go to output simultaneously (out of order of files, but in order of lines in each file)\n"+
"use 0 for multi-threaded zst decoder (slightly faster at cost of more CPU)")
"use 0 for a 2-block pipelined zst decoder (slightly faster at cost of more CPU)")

flag.BoolVar(&r.splitChunks, "split-chunks", false, "experimental: with -parallel N (N >= 2), split each uncompressed file (>= 1 MB per chunk)\n"+
"into up to N byte-range chunks processed in parallel as virtual files named file.chunkNN,\n"+
Expand Down
32 changes: 14 additions & 18 deletions cmd/catp/catp/catp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"time"

"github.com/bool64/progress"
"github.com/klauspost/compress/zstd"
gzip "github.com/klauspost/pgzip"
"github.com/vearutop/plot-go"
"golang.org/x/time/rate"
Expand Down Expand Up @@ -475,7 +474,7 @@

// speedJSON returns samples newer than ?since= as [ts, lines/s, MB/s] rows.
func (r *runner) speedJSON(w http.ResponseWriter, req *http.Request) {
since, _ := strconv.ParseInt(req.FormValue("since"), 10, 64) //nolint:gosec
since, _ := strconv.ParseInt(req.FormValue("since"), 10, 64)

Check notice on line 477 in cmd/catp/catp/catp.go

View workflow job for this annotation

GitHub Actions / test (stable)

2 statement(s) on lines 477:479 are not covered by tests.
rows := [][]any{}

r.statusMu.Lock()
Expand Down Expand Up @@ -519,7 +518,7 @@
mux := http.NewServeMux()
mux.HandleFunc("/rate-limit", func(w http.ResponseWriter, req *http.Request) {
if req.Method == http.MethodPost {
v, err := strconv.ParseFloat(req.FormValue("value"), 64) //nolint:gosec
v, err := strconv.ParseFloat(req.FormValue("value"), 64)

Check notice on line 521 in cmd/catp/catp/catp.go

View workflow job for this annotation

GitHub Actions / test (stable)

2 statement(s) on lines 521:522 are not covered by tests.
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)

Expand Down Expand Up @@ -741,7 +740,14 @@
out = w
}

if r.parallel <= 1 && !r.noProgress && !r.hasCompression {
if r.startLine != 0 || r.endLine != 0 {
r.countLines = true
}

Check notice on line 745 in cmd/catp/catp/catp.go

View workflow job for this annotation

GitHub Actions / test (stable)

1 statement(s) are not covered by tests.

useScan := r.filters.isSet() || r.parallel > 1 || r.hasOptions || r.countLines || r.limiter != nil || sampleBytes != nil

// consumed is only maintained by scanFile; readFile relies on the counting reader.
if r.parallel <= 1 && !r.noProgress && !r.hasCompression && useScan {
r.consumed = new(int64)
}

Expand All @@ -766,11 +772,7 @@
})
}

if r.startLine != 0 || r.endLine != 0 {
r.countLines = true
}

if r.filters.isSet() || r.parallel > 1 || r.hasOptions || r.countLines || r.limiter != nil || sampleBytes != nil {
if useScan {
r.scanFile(filename, rd, out, sampleBytes)
} else {
r.readFile(rd, out)
Expand All @@ -792,14 +794,8 @@
return nil, fmt.Errorf("failed to init gzip reader: %w", err)
}
case strings.HasSuffix(filename, ".zst"):
if r.parallel >= 1 {
if rd, err = zstdReader(rd); err != nil {
return nil, fmt.Errorf("failed to init zst reader: %w", err)
}
} else {
if rd, err = zstd.NewReader(rd); err != nil {
return nil, fmt.Errorf("failed to init zst reader: %w", err)
}
if rd, err = zstdReader(rd, r.parallel); err != nil {
return nil, fmt.Errorf("failed to init zst reader: %w", err)

Check notice on line 798 in cmd/catp/catp/catp.go

View workflow job for this annotation

GitHub Actions / test (stable)

2 statement(s) on lines 797:799 are not covered by tests.
}
}

Expand All @@ -817,7 +813,7 @@
}

go func() {
time.Sleep(10 * time.Second)
time.Sleep(30 * time.Second)

Check notice on line 816 in cmd/catp/catp/catp.go

View workflow job for this annotation

GitHub Actions / test (stable)

3 statement(s) on lines 816:819 are not covered by tests.
pprof.StopCPUProfile()
println("CPU profile written to", cpuProfile)

Expand Down
9 changes: 6 additions & 3 deletions cmd/catp/catp/cgo_zstd.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
//go:build cgo_zstd

package catp
Expand All @@ -5,17 +5,20 @@
import (
"io"

"github.com/DataDog/zstd"
zstd "github.com/vearutop/zstd-go/libzstd"
)

func init() {
versionExtra = append(versionExtra, "CGO_ZSTD")
}

func zstdReader(rd io.Reader) (io.Reader, error) {
func zstdReader(rd io.Reader, _ int) (io.Reader, error) {
return zstd.NewReader(rd), nil
}

func zstdWriter(w io.Writer) (io.WriteCloser, error) {
return zstd.NewWriterLevel(w, zstd.BestSpeed), nil
return zstd.NewWriter(w, zstd.ProfileFastest(), func(w *zstd.Writer) {
w.FrameSize = 16 << 20
w.Seekable = true
}), nil
}
20 changes: 12 additions & 8 deletions cmd/catp/catp/zstd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
package catp

import (
"fmt"
"io"

"github.com/klauspost/compress/zstd"
zstdgo "github.com/vearutop/zstd-go"
)

func zstdReader(rd io.Reader) (io.Reader, error) {
if rd, err := zstd.NewReader(rd, zstd.WithDecoderConcurrency(1)); err == nil {
return rd, nil
} else { //nolint:revive
return nil, fmt.Errorf("failed to init zst reader: %w", err)
// zstdReader decodes zstd, -parallel 0 enables a 2-block decoding pipeline (faster, more CPU).
func zstdReader(rd io.Reader, parallel int) (io.Reader, error) {
zr := zstdgo.NewReader(rd)
if parallel == 0 {
zr.Concurrency = 2

Check notice on line 15 in cmd/catp/catp/zstd.go

View workflow job for this annotation

GitHub Actions / test (stable)

3 statement(s) on lines 13:16 are not covered by tests.
}

return zr, nil

Check notice on line 18 in cmd/catp/catp/zstd.go

View workflow job for this annotation

GitHub Actions / test (stable)

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

func zstdWriter(w io.Writer) (io.WriteCloser, error) {
return zstd.NewWriter(w, zstd.WithEncoderLevel(zstd.SpeedFastest), zstd.WithLowerEncoderMem(true))
return zstdgo.NewWriter(w, zstdgo.ProfileFastest(), func(w *zstdgo.Writer) {
w.FrameSize = 16 << 20
w.Seekable = true
}), nil

Check notice on line 25 in cmd/catp/catp/zstd.go

View workflow job for this annotation

GitHub Actions / test (stable)

3 statement(s) are not covered by tests.
}
Binary file modified cmd/catp/default.pgo
Binary file not shown.
11 changes: 7 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ module github.com/bool64/progress
go 1.26.0

require (
github.com/DataDog/zstd v1.5.7
github.com/bool64/dev v0.2.45
github.com/bool64/dev v0.2.46
github.com/cloudflare/ahocorasick v0.0.0-20240916140611-054963ec9396
github.com/klauspost/compress v1.20.3
github.com/klauspost/pgzip v1.3.0
github.com/vearutop/plot-go v0.1.1
github.com/vearutop/zstd-go v0.0.4
golang.org/x/time v0.16.0
)

require github.com/vearutop/statigz v1.5.0 // indirect
require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/klauspost/compress v1.20.4 // indirect
github.com/vearutop/statigz v1.5.0 // indirect
)
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
github.com/DataDog/zstd v1.5.7 h1:ybO8RBeh29qrxIhCA9E8gKY6xfONU9T6G6aP9DTKfLE=
github.com/DataDog/zstd v1.5.7/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA=
github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA=
github.com/bool64/dev v0.2.45 h1:3nLKhAS/6Oklk3Mt2lHYSN/Cb4tdAD77KLwzeP+6eYE=
github.com/bool64/dev v0.2.45/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
github.com/bool64/dev v0.2.46 h1:oOM68buCVIZBJscLMEHfalYW/SOPfABr5grztbwBa3w=
github.com/bool64/dev v0.2.46/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cloudflare/ahocorasick v0.0.0-20240916140611-054963ec9396 h1:W2HK1IdCnCGuLUeyizSCkwvBjdj0ZL7mxnJYQ3poyzI=
github.com/cloudflare/ahocorasick v0.0.0-20240916140611-054963ec9396/go.mod h1:tGWUZLZp9ajsxUOnHmFFLnqnlKXsCn6GReG4jAD59H0=
github.com/klauspost/compress v1.20.3 h1:zWNoFqq/lSuYQRim3dUXlXeA0IqwuZGicdG5ZTfY5j4=
github.com/klauspost/compress v1.20.3/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI=
github.com/klauspost/compress v1.20.4 h1:dD0v/bvxtjCBqQu6sx1TNWkalEY5lNTIe+HY9w8TeNI=
github.com/klauspost/compress v1.20.4/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI=
github.com/klauspost/pgzip v1.3.0 h1:8t+KjjzD/0n/8vNlJGGZmTeK4njuwffOQvJm8tOSc8o=
github.com/klauspost/pgzip v1.3.0/go.mod h1:Xx7tAv5DH8ObLHUDQKXoE/nd8i/FYdNDTVMvi3SLTKI=
github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
Expand All @@ -16,6 +16,8 @@ github.com/vearutop/plot-go v0.1.1 h1:TU9XyjsA6zbanlpjNS/Hq80HZNao4kJAfr1k+z9k3f
github.com/vearutop/plot-go v0.1.1/go.mod h1:u/PnA1M0q8hVeruxfyF9rgqlOdU+BT7z1L20OARhgTY=
github.com/vearutop/statigz v1.5.0 h1:FuWwZiT82yBw4xbWdWIawiP2XFTyEPhIo8upRxiKLqk=
github.com/vearutop/statigz v1.5.0/go.mod h1:oHmjFf3izfCO804Di1ZjB666P3fAlVzJEx2k6jNt/Gk=
github.com/vearutop/zstd-go v0.0.4 h1:zrOEyqX4EcpivgpdaR69SSPGXcmUHWKvD2V/zEuGZ24=
github.com/vearutop/zstd-go v0.0.4/go.mod h1:1Gji1pmd5yWRZ+pSBC6E0/RJtJMh/afR4f8S4zFA/2E=
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
golang.org/x/time v0.16.0 h1:vMb6ptszcQMkcwiRTAuNNU50gom6++Q/6gY2hDM6VDE=
Expand Down
Loading