Permalink
Browse files

mmvdump: make InstanceDomains consistent and make Tocs array

  • Loading branch information...
1 parent a2faa89 commit 93bfea4a2352cdcc8b8e94bb6f64d3312d3185bf @suyash suyash committed Jul 24, 2016
Showing with 35 additions and 25 deletions.
  1. +22 −15 mmvdump/cmd/mmvdump/main.go
  2. +6 −6 mmvdump/mmvdump.go
  3. +7 −4 mmvdump/pcp.go
@@ -10,11 +10,11 @@ import (
var (
header *mmvdump.Header
- tocs map[int32]*mmvdump.Toc
+ tocs []*mmvdump.Toc
metrics map[uint64]*mmvdump.Metric
values map[uint64]*mmvdump.Value
instances map[uint64]*mmvdump.Instance
- indoms map[uint32]*mmvdump.InstanceDomain
+ indoms map[uint64]*mmvdump.InstanceDomain
strings map[uint64]*mmvdump.String
)
@@ -126,29 +126,36 @@ Flags = 0x%x
`, file, header.Version, header.G1, header.Toc, header.Cluster, header.Process, int(header.Flag))
toff := mmvdump.HeaderLength
+ var (
+ itemtype string
+ itemsize uint64
+ printItem func(uint64)
+ )
- for _, toc := range tocs {
+ for ti, toc := range tocs {
switch toc.Type {
case mmvdump.TocMetrics:
- fmt.Printf("TOC[%v], offset: %v, metrics offset: %v (%v entries)\n", int(toc.Type), toff, toc.Offset, toc.Count)
- for i, offset := int32(0), toc.Offset; i < toc.Count; i, offset = i+1, offset+mmvdump.MetricLength {
- printMetric(offset)
- }
+ itemtype = "metric"
+ itemsize = mmvdump.MetricLength
+ printItem = printMetric
case mmvdump.TocValues:
- fmt.Printf("TOC[%v], offset: %v, values offset: %v (%v entries)\n", int(toc.Type), toff, toc.Offset, toc.Count)
- for i, offset := int32(0), toc.Offset; i < toc.Count; i, offset = i+1, offset+mmvdump.ValueLength {
- printValue(offset)
- }
+ itemtype = "values"
+ itemsize = mmvdump.ValueLength
+ printItem = printValue
case mmvdump.TocStrings:
- fmt.Printf("TOC[%v], offset: %v, strings offset: %v (%v entries)\n", int(toc.Type), toff, toc.Offset, toc.Count)
- for i, offset := int32(0), toc.Offset; i < toc.Count; i, offset = i+1, offset+mmvdump.StringLength {
- printString(offset)
- }
+ itemtype = "strings"
+ itemsize = mmvdump.StringLength
+ printItem = printString
}
+ fmt.Printf("TOC[%v], offset: %v, %v offset: %v (%v entries)\n", ti, toff, itemtype, toc.Offset, toc.Count)
+ for i, offset := int32(0), toc.Offset; i < toc.Count; i, offset = i+1, offset+itemsize {
+ printItem(offset)
+ }
fmt.Println()
+
toff += mmvdump.TocLength
}
}
View
@@ -78,11 +78,11 @@ func readString(data []byte, offset uint64) (*String, error) {
// Dump creates a data dump from the passed data
func Dump(data []byte) (
h *Header,
- ts map[int32]*Toc,
+ ts []*Toc,
metrics map[uint64]*Metric,
values map[uint64]*Value,
instances map[uint64]*Instance,
- indoms map[uint32]*InstanceDomain,
+ indoms map[uint64]*InstanceDomain,
strings map[uint64]*String,
err error,
) {
@@ -91,13 +91,13 @@ func Dump(data []byte) (
return nil, nil, nil, nil, nil, nil, nil, err
}
- ts = make(map[int32]*Toc)
+ ts = make([]*Toc, h.Toc)
for i := 0; i < int(h.Toc); i++ {
t, err := readToc(data, HeaderLength+uint64(i)*TocLength)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, err
}
- ts[int32(t.Type)] = t
+ ts[i] = t
}
for _, toc := range ts {
@@ -112,13 +112,13 @@ func Dump(data []byte) (
instances[offset] = instance
}
case TocIndoms:
- indoms := make(map[uint32]*InstanceDomain)
+ indoms := make(map[uint64]*InstanceDomain)
for i, offset := int32(0), toc.Offset; i < toc.Count; i, offset = i+1, offset+InstanceDomainLength {
indom, err := readInstanceDomain(data, offset)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, err
}
- indoms[indom.Serial] = indom
+ indoms[offset] = indom
}
case TocMetrics:
metrics = make(map[uint64]*Metric)
View
@@ -4,13 +4,13 @@ package mmvdump
const MMVVersion = 1
const (
- // Maximum allowed length of a name
+ // NameMax is the maximum allowed length of a name
NameMax = 64
- // Maximum allowed length of a string
+ // StringMax is the maximum allowed length of a string
StringMax = 256
- // Constant used to indicate abscence of an indom from a metric
+ // NoIndom is a constant used to indicate abscence of an indom from a metric
NoIndom = -1
)
@@ -130,13 +130,16 @@ const (
)
// Values for Count Units
-const OneUnit Unit = 1<<20 | iota<<8
+const (
+ OneUnit Unit = 1<<20 | iota<<8
+)
//go:generate stringer --type=Unit
// Semantics represents an enumerated type representing all possible semantics of a metric
type Semantics int32
+// Values for Semantics
const (
NoSemantics Semantics = 0
CounterSemantics Semantics = 1

0 comments on commit 93bfea4

Please sign in to comment.