git.frostfs.info/TrueCloudLab/frostfs-sdk-go@v0.0.0-20241022124111-5361f0ecebd3/pool/tree/statistic.go (about)

     1  package tree
     2  
     3  import (
     4  	"time"
     5  
     6  	"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/pool"
     7  )
     8  
     9  // Statistic is metrics of the tree pool.
    10  type Statistic struct {
    11  	methods []pool.StatusSnapshot
    12  }
    13  
    14  func (s *Statistic) Requests() (requests uint64) {
    15  	for _, val := range s.methods {
    16  		requests += val.AllRequests()
    17  	}
    18  	return requests
    19  }
    20  
    21  func (s *Statistic) AverageGetNodes() time.Duration {
    22  	return s.averageTime(methodGetNodes)
    23  }
    24  
    25  func (s *Statistic) AverageGetSubTree() time.Duration {
    26  	return s.averageTime(methodGetSubTree)
    27  }
    28  
    29  func (s *Statistic) AverageAddNode() time.Duration {
    30  	return s.averageTime(methodAddNode)
    31  }
    32  
    33  func (s *Statistic) AverageAddNodeByPath() time.Duration {
    34  	return s.averageTime(methodAddNodeByPath)
    35  }
    36  
    37  func (s *Statistic) AverageMoveNode() time.Duration {
    38  	return s.averageTime(methodMoveNode)
    39  }
    40  
    41  func (s *Statistic) AverageRemoveNode() time.Duration {
    42  	return s.averageTime(methodRemoveNode)
    43  }
    44  
    45  func (s *Statistic) averageTime(method MethodIndex) time.Duration {
    46  	stat := s.methods[method]
    47  	if stat.AllRequests() == 0 {
    48  		return 0
    49  	}
    50  	return time.Duration(stat.AllTime() / stat.AllRequests())
    51  }