diff options
author | Vladimir Lavor <vlavor@cisco.com> | 2021-03-17 12:27:10 +0100 |
---|---|---|
committer | Vladimir Lavor <vlavor@cisco.com> | 2021-05-05 13:26:19 +0200 |
commit | c380ee6064379258768fdfe4e9d4ad9138980ec0 (patch) | |
tree | 28903f9ee23bb3206e21a2c04001ebfc560de944 /adapter/statsclient/stat_segment_api.go | |
parent | a6607d9c1ba37320984c13580c932076cbff6dd6 (diff) |
statsclient: allow index as pattern
* ListStats() returns stats identifiers containing the stat name and index
* New method PrepareDirOnIndex(indexes...). Instead of the name filter
it does not browse through all available indexes
* Stats example shows how to get the last epoch value (added "e" or "epoch" command)
Change-Id: Ibb15090fb0dfdb7f9b0ecf8ac07a5eb9a9ace8f8
Signed-off-by: Vladimir Lavor <vlavor@cisco.com>
Diffstat (limited to 'adapter/statsclient/stat_segment_api.go')
-rw-r--r-- | adapter/statsclient/stat_segment_api.go | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/adapter/statsclient/stat_segment_api.go b/adapter/statsclient/stat_segment_api.go index 0ca0c8b..23755a5 100644 --- a/adapter/statsclient/stat_segment_api.go +++ b/adapter/statsclient/stat_segment_api.go @@ -48,15 +48,18 @@ const ( statDirEmpty = 6 ) -type statDirectoryType int32 - -type statDirectoryName []byte +type ( + dirVector unsafe.Pointer + dirSegment unsafe.Pointer + dirName []byte + dirType int32 +) // statSegment represents common API for every stats API version type statSegment interface { // GetDirectoryVector returns pointer to memory where the beginning // of the data directory is located. - GetDirectoryVector() unsafe.Pointer + GetDirectoryVector() dirVector // GetStatDirOnIndex accepts directory vector and particular index. // Returns pointer to the beginning of the segment. Also the directory @@ -65,7 +68,7 @@ type statSegment interface { // // Note that if the index is equal to 0, the result pointer points to // the same memory address as the argument. - GetStatDirOnIndex(directory unsafe.Pointer, index uint32) (unsafe.Pointer, statDirectoryName, statDirectoryType) + GetStatDirOnIndex(v dirVector, index uint32) (dirSegment, dirName, dirType) // GetEpoch re-loads stats header and returns current epoch //and 'inProgress' value @@ -73,11 +76,11 @@ type statSegment interface { // CopyEntryData accepts pointer to a directory segment and returns adapter.Stat // based on directory type populated with data - CopyEntryData(segment unsafe.Pointer) adapter.Stat + CopyEntryData(segment dirSegment) adapter.Stat // UpdateEntryData accepts pointer to a directory segment with data, and stat // segment to update - UpdateEntryData(segment unsafe.Pointer, s *adapter.Stat) error + UpdateEntryData(segment dirSegment, s *adapter.Stat) error } // vecHeader represents a vector header @@ -86,7 +89,7 @@ type vecHeader struct { vectorData [0]uint8 } -func (t statDirectoryType) String() string { +func (t dirType) String() string { return adapter.StatType(t).String() } @@ -102,12 +105,12 @@ func getVersion(data []byte) uint64 { return version.value } -func vectorLen(v unsafe.Pointer) unsafe.Pointer { +func vectorLen(v dirVector) dirVector { vec := *(*vecHeader)(unsafe.Pointer(uintptr(v) - unsafe.Sizeof(uint64(0)))) - return unsafe.Pointer(&vec.length) + return dirVector(&vec.length) } //go:nosplit -func statSegPointer(p unsafe.Pointer, offset uintptr) unsafe.Pointer { - return unsafe.Pointer(uintptr(p) + offset) +func statSegPointer(v dirVector, offset uintptr) dirVector { + return dirVector(uintptr(v) + offset) } |