https://gerrit.fd.io/r/c/vpp/+/35640
Signed-off-by: Vladimir Lavor <vlavor@cisco.com>
Change-Id: I91820bb15655e7b309af814c659eb9f5e7cd08a4
// StatType represents type of stat directory and simply
// defines what type of stat data is stored in the stat entry.
// StatType represents type of stat directory and simply
// defines what type of stat data is stored in the stat entry.
- _ StatType = 0
- ScalarIndex StatType = 1
- SimpleCounterVector StatType = 2
- CombinedCounterVector StatType = 3
- ErrorIndex StatType = 4
- NameVector StatType = 5
- Empty StatType = 6
- Symlink StatType = 7
+ Unknown StatType = "UnknownStatType"
+ ScalarIndex StatType = "ScalarIndex"
+ SimpleCounterVector StatType = "SimpleCounterVector"
+ CombinedCounterVector StatType = "CombinedCounterVector"
+ ErrorIndex StatType = "ErrorIndex"
+ NameVector StatType = "NameVector"
+ Empty StatType = "Empty"
+ Symlink StatType = "Symlink"
-func (d StatType) String() string {
- switch d {
- case ScalarIndex:
- return "ScalarIndex"
- case SimpleCounterVector:
- return "SimpleCounterVector"
- case CombinedCounterVector:
- return "CombinedCounterVector"
- case ErrorIndex:
- return "ErrorIndex"
- case NameVector:
- return "NameVector"
- case Empty:
- return "Empty"
- case Symlink:
- return "Symlink"
- }
- return fmt.Sprintf("UnknownStatType(%d)", d)
-}
-
// StatDir defines directory of stats entries created by PrepareDir.
type StatDir struct {
Epoch int64
// StatDir defines directory of stats entries created by PrepareDir.
type StatDir struct {
Epoch int64
-const (
- statDirIllegal = 0
- statDirScalarIndex = 1
- statDirCounterVectorSimple = 2
- statDirCounterVectorCombined = 3
- statDirErrorIndex = 4
- statDirNameVector = 5
- statDirEmpty = 6
- statDirSymlink = 7
-)
+var dirTypeMapping = map[dirType]adapter.StatType{
+ 1: adapter.ScalarIndex,
+ 2: adapter.SimpleCounterVector,
+ 3: adapter.CombinedCounterVector,
+ 4: adapter.NameVector,
+ 5: adapter.Empty,
+ 6: adapter.Symlink,
+}
+
+var dirTypeMappingLegacy = map[dirType]adapter.StatType{
+ 1: adapter.ScalarIndex,
+ 2: adapter.SimpleCounterVector,
+ 3: adapter.CombinedCounterVector,
+ 4: adapter.ErrorIndex,
+ 5: adapter.NameVector,
+ 6: adapter.Empty,
+ 7: adapter.Symlink,
+}
type (
dirVector unsafe.Pointer
type (
dirVector unsafe.Pointer
-func (t dirType) String() string {
- return adapter.StatType(t).String()
-}
-
func getVersion(data []byte) uint64 {
type apiVersion struct {
value uint64
func getVersion(data []byte) uint64 {
type apiVersion struct {
value uint64
return dirVector(&vec.length)
}
return dirVector(&vec.length)
}
+func getStatType(dirTypeNum dirType, useLegacyMapping bool) (dirTyp adapter.StatType) {
+ var exists bool
+ if useLegacyMapping {
+ dirTyp, exists = dirTypeMappingLegacy[dirTypeNum]
+ } else {
+ dirTyp, exists = dirTypeMapping[dirTypeNum]
+ }
+ if exists {
+ return dirTyp
+ }
+ return adapter.Unknown
+}
+
//go:nosplit
func statSegPointer(v dirVector, offset uintptr) dirVector {
return dirVector(uintptr(v) + offset)
//go:nosplit
func statSegPointer(v dirVector, offset uintptr) dirVector {
return dirVector(uintptr(v) + offset)
- return statSegDir, dirName(name), dir.directoryType
+ return statSegDir, name, dir.directoryType
}
func (ss *statSegmentV1) GetEpoch() (int64, bool) {
}
func (ss *statSegmentV1) GetEpoch() (int64, bool) {
func (ss *statSegmentV1) CopyEntryData(segment dirSegment, _ uint32) adapter.Stat {
dirEntry := (*statSegDirectoryEntryV1)(segment)
func (ss *statSegmentV1) CopyEntryData(segment dirSegment, _ uint32) adapter.Stat {
dirEntry := (*statSegDirectoryEntryV1)(segment)
- dirType := adapter.StatType(dirEntry.directoryType)
+ typ := getStatType(dirEntry.directoryType, true)
- switch dirType {
- case statDirScalarIndex:
+ switch typ {
+ case adapter.ScalarIndex:
return adapter.ScalarStat(dirEntry.unionData)
return adapter.ScalarStat(dirEntry.unionData)
- case statDirErrorIndex:
+ case adapter.ErrorIndex:
if dirEntry.unionData == 0 {
debugf("offset invalid for %s", dirEntry.name)
break
if dirEntry.unionData == 0 {
debugf("offset invalid for %s", dirEntry.name)
break
}
return adapter.ErrorStat(errData)
}
return adapter.ErrorStat(errData)
- case statDirCounterVectorSimple:
+ case adapter.SimpleCounterVector:
if dirEntry.unionData == 0 {
debugf("offset invalid for %s", dirEntry.name)
break
if dirEntry.unionData == 0 {
debugf("offset invalid for %s", dirEntry.name)
break
}
return adapter.SimpleCounterStat(data)
}
return adapter.SimpleCounterStat(data)
- case statDirCounterVectorCombined:
+ case adapter.CombinedCounterVector:
if dirEntry.unionData == 0 {
debugf("offset invalid for %s", dirEntry.name)
break
if dirEntry.unionData == 0 {
debugf("offset invalid for %s", dirEntry.name)
break
}
return adapter.CombinedCounterStat(data)
}
return adapter.CombinedCounterStat(data)
- case statDirNameVector:
+ case adapter.NameVector:
if dirEntry.unionData == 0 {
debugf("offset invalid for %s", dirEntry.name)
break
if dirEntry.unionData == 0 {
debugf("offset invalid for %s", dirEntry.name)
break
}
return adapter.NameStat(data)
}
return adapter.NameStat(data)
debugf("Symlinks are not supported for stats v1")
default:
debugf("Symlinks are not supported for stats v1")
default:
func (ss *statSegmentV2) CopyEntryData(segment dirSegment, index uint32) adapter.Stat {
dirEntry := (*statSegDirectoryEntryV2)(segment)
func (ss *statSegmentV2) CopyEntryData(segment dirSegment, index uint32) adapter.Stat {
dirEntry := (*statSegDirectoryEntryV2)(segment)
- typ := adapter.StatType(dirEntry.directoryType)
+ typ := getStatType(dirEntry.directoryType, ss.getErrorVector() != nil)
// skip zero pointer value
// skip zero pointer value
- if typ != statDirScalarIndex && typ != statDirEmpty && dirEntry.unionData == 0 {
+ if typ != adapter.ScalarIndex && typ != adapter.Empty && dirEntry.unionData == 0 {
debugf("data pointer not defined for %s", dirEntry.name)
return nil
}
switch typ {
debugf("data pointer not defined for %s", dirEntry.name)
return nil
}
switch typ {
- case statDirScalarIndex:
+ case adapter.ScalarIndex:
return adapter.ScalarStat(dirEntry.unionData)
return adapter.ScalarStat(dirEntry.unionData)
- case statDirErrorIndex:
+ case adapter.ErrorIndex:
dirVector := ss.getErrorVector()
if dirVector == nil {
debugf("error vector pointer is out of range for %s", dirEntry.name)
dirVector := ss.getErrorVector()
if dirVector == nil {
debugf("error vector pointer is out of range for %s", dirEntry.name)
}
return adapter.ErrorStat(errData)
}
return adapter.ErrorStat(errData)
- case statDirCounterVectorSimple:
+ case adapter.SimpleCounterVector:
dirVector := ss.adjust(dirVector(&dirEntry.unionData))
if dirVector == nil {
debugf("data vector pointer is out of range for %s", dirEntry.name)
dirVector := ss.adjust(dirVector(&dirEntry.unionData))
if dirVector == nil {
debugf("data vector pointer is out of range for %s", dirEntry.name)
}
return adapter.SimpleCounterStat(data)
}
return adapter.SimpleCounterStat(data)
- case statDirCounterVectorCombined:
+ case adapter.CombinedCounterVector:
dirVector := ss.adjust(dirVector(&dirEntry.unionData))
if dirVector == nil {
debugf("data vector pointer is out of range for %s", dirEntry.name)
dirVector := ss.adjust(dirVector(&dirEntry.unionData))
if dirVector == nil {
debugf("data vector pointer is out of range for %s", dirEntry.name)
}
return adapter.CombinedCounterStat(data)
}
return adapter.CombinedCounterStat(data)
- case statDirNameVector:
+ case adapter.NameVector:
dirVector := ss.adjust(dirVector(&dirEntry.unionData))
if dirVector == nil {
debugf("data vector pointer is out of range for %s", dirEntry.name)
dirVector := ss.adjust(dirVector(&dirEntry.unionData))
if dirVector == nil {
debugf("data vector pointer is out of range for %s", dirEntry.name)
}
return adapter.NameStat(data)
}
return adapter.NameStat(data)
return adapter.EmptyStat("<none>")
// no-op
return adapter.EmptyStat("<none>")
// no-op
// prevent recursion loops
if index != ^uint32(0) {
debugf("received symlink with defined item index")
// prevent recursion loops
if index != ^uint32(0) {
debugf("received symlink with defined item index")
CounterStatsPrefix = "/err/"
MemoryStatSegPrefix = "/mem/statseg"
CounterStatsPrefix = "/err/"
MemoryStatSegPrefix = "/mem/statseg"
- MemoryStatPrefix = "/mem/stat"
- MemoryMainPrefix = "/mem/main"
+ MemoryStatSegment = "/mem/stat segment"
+ MemoryMainHeap = "/mem/main heap"
MemoryStats_Total = "total"
MemoryStats_Used = "used"
MemoryStats_Total = "total"
MemoryStats_Used = "used"
}
for i, stat := range c.errorStatsData.Entries {
}
for i, stat := range c.errorStatsData.Entries {
- if stat.Type != adapter.ErrorIndex {
- continue
- }
if errStat, ok := stat.Data.(adapter.ErrorStat); ok {
values := make([]uint64, len(errStat))
for j, errStatW := range errStat {
if errStat, ok := stat.Data.(adapter.ErrorStat); ok {
values := make([]uint64, len(errStat))
for j, errStatW := range errStat {
}
errorStats.Errors[i].Values = values
}
}
errorStats.Errors[i].Values = values
}
+ if errStat, ok := stat.Data.(adapter.SimpleCounterStat); ok {
+ values := make([]uint64, len(errStat))
+ for j, errStatW := range errStat {
+ for _, val := range errStatW {
+ values[j] += uint64(val)
+ }
+ }
+ errorStats.Errors[i].Values = values
+ }
}
func (c *StatsConnection) GetMemoryStats(memStats *api.MemoryStats) (err error) {
}
func (c *StatsConnection) GetMemoryStats(memStats *api.MemoryStats) (err error) {
- if err := c.updateStats(&c.memStatsData, MemoryStatSegPrefix, MemoryStatPrefix, MemoryMainPrefix); err != nil {
+ if err := c.updateStats(&c.memStatsData, MemoryStatSegPrefix, MemoryStatSegment, MemoryMainHeap); err != nil {
return err
}
convertStats := func(stats []adapter.Counter) api.MemoryCounters {
return err
}
convertStats := func(stats []adapter.Counter) api.MemoryCounters {
case MemoryStats_Used:
memStats.Used = val
}
case MemoryStats_Used:
memStats.Used = val
}
- } else if strings.Contains(string(stat.Name), MemoryStatPrefix) {
+ } else if string(stat.Name) == MemoryStatSegment {
if perHeapStats, ok := stat.Data.(adapter.SimpleCounterStat); ok {
if memStats.Stat == nil {
memStats.Stat = make(map[int]api.MemoryCounters)
if perHeapStats, ok := stat.Data.(adapter.SimpleCounterStat); ok {
if memStats.Stat == nil {
memStats.Stat = make(map[int]api.MemoryCounters)
memStats.Stat[heap] = convertStats(stats)
}
}
memStats.Stat[heap] = convertStats(stats)
}
}
- } else if strings.Contains(string(stat.Name), MemoryMainPrefix) {
+ } else if string(stat.Name) == MemoryMainHeap {
if perHeapStats, ok := stat.Data.(adapter.SimpleCounterStat); ok {
if memStats.Main == nil {
memStats.Main = make(map[int]api.MemoryCounters)
if perHeapStats, ok := stat.Data.(adapter.SimpleCounterStat); ok {
if memStats.Main == nil {
memStats.Main = make(map[int]api.MemoryCounters)