github.com/fzfile/BaiduPCS-Go@v0.0.0-20200606205115-4408961cf336/internal/pcsfunctions/statistic.go (about)

     1  package pcsfunctions
     2  
     3  import (
     4  	"github.com/fzfile/BaiduPCS-Go/baidupcs/expires"
     5  	"sync/atomic"
     6  	"time"
     7  )
     8  
     9  type (
    10  	Statistic struct {
    11  		totalSize int64
    12  		startTime time.Time
    13  	}
    14  )
    15  
    16  func (s *Statistic) AddTotalSize(size int64) int64 {
    17  	return atomic.AddInt64(&s.totalSize, size)
    18  }
    19  
    20  func (s *Statistic) TotalSize() int64 {
    21  	return s.totalSize
    22  }
    23  
    24  func (s *Statistic) StartTimer() {
    25  	s.startTime = time.Now()
    26  	expires.StripMono(&s.startTime)
    27  }
    28  
    29  func (s *Statistic) Elapsed() time.Duration {
    30  	return time.Now().Sub(s.startTime)
    31  }