Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

add mmvdump and more client tests #18

Merged
merged 17 commits into from Jul 28, 2016
View
@@ -14,7 +14,7 @@ deps:
gometalinter --install --update
lint:
- gometalinter ./... --vendor --deadline=10000s
+ gometalinter ./... --vendor --deadline=10000s --dupl-threshold=80
test:
go test ./...
@@ -10,14 +10,37 @@ 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
)
+func printInstance(offset uint64) {
+ i := instances[offset]
+ indom := indoms[i.Indom]
+ fmt.Printf("\t[%v/%v] instance = [%v/%v]\n", indom.Serial, offset, i.Internal, string(i.External[:]))
+}
+
+func printInstanceDomain(offset uint64) {
+ indom := indoms[offset]
+ fmt.Printf("\t[%v/%v] %d instances, starting at offset %d\n", indom.Serial, offset, indom.Count, indom.Offset)
+
+ if indom.Shorttext == 0 {
+ fmt.Printf("\t\t(no shorttext)\n")
+ } else {
+ fmt.Printf("\t\tshorttext=%v\n", string(strings[indom.Shorttext].Payload[:]))
+ }
+
+ if indom.Longtext == 0 {
+ fmt.Printf("\t\t(no longtext)\n")
+ } else {
+ fmt.Printf("\t\tlongtext=%v\n", string(strings[indom.Longtext].Payload[:]))
+ }
+}
+
func printMetric(offset uint64) {
m := metrics[offset]
@@ -108,6 +131,9 @@ func main() {
file := flag.Arg(0)
d, err := data(file)
+ if err != nil {
+ panic(err)
+ }
header, tocs, metrics, values, instances, indoms, strings, err = mmvdump.Dump(d)
if err != nil {
@@ -126,29 +152,42 @@ 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.TocInstances:
+ itemtype = "instances"
+ itemsize = mmvdump.InstanceLength
+ printItem = printInstance
+ case mmvdump.TocIndoms:
+ itemtype = "indoms"
+ itemsize = mmvdump.InstanceDomainLength
+ printItem = printInstanceDomain
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