Skip to content

Commit

Permalink
fix(adaptive):make CompressInfo's attribuite public.
Browse files Browse the repository at this point in the history
  • Loading branch information
wqshr12345 committed Oct 24, 2023
1 parent daf952c commit 6ec335d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
12 changes: 6 additions & 6 deletions adaptive/adaptive.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package adaptive

type CompressInfo struct {
pkgId int
compressType int
compressTime int64
tranportTime int64
decompressTime int64
compressRatio float64
PkgId int
CompressType int
CompressTime int64
TranportTime int64
DecompressTime int64
CompressRatio float64
}

type ReportFunction func(CompressInfo)
Expand Down
15 changes: 10 additions & 5 deletions adaptive/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func NewReader(r io.Reader, reportFunc ReportFunction) *Reader {
inR: r,
cmpr: snappy.NewDecompressor(),
reportFunc: reportFunc,
pkgID: 0,
}
}

Expand All @@ -46,6 +47,8 @@ type Reader struct {
start int

reportFunc ReportFunction

pkgID int
}

func (r *Reader) Read(p []byte) (int, error) {
Expand Down Expand Up @@ -103,13 +106,15 @@ func (r *Reader) fill() error {
r.oBuf = r.cmpr.Decompress(nil, compressedData)
endTs := time.Now().UnixNano()
compressInfo := CompressInfo{
compressType: int(compressType),
compressTime: midTs - startTs,
tranportTime: mid2Ts - midTs,
decompressTime: endTs - mid2Ts,
compressRatio: float64(len(r.oBuf)) / float64(dataLen),
PkgId: r.pkgID,
CompressType: int(compressType),
CompressTime: midTs - startTs,
TranportTime: mid2Ts - midTs,
DecompressTime: endTs - mid2Ts,
CompressRatio: float64(len(r.oBuf)) / float64(dataLen),
}
r.reportFunc(compressInfo)
r.start = 0
r.pkgID += 1
return nil
}

0 comments on commit 6ec335d

Please sign in to comment.