Permalink
Browse files

mmvdump: refactor main in cli

  • Loading branch information...
1 parent 5d7d6f5 commit 752f916ca7e5b10cf631071ef9118212704427d5 @suyash suyash committed Aug 6, 2016
Showing with 51 additions and 42 deletions.
  1. +47 −42 mmvdump/cmd/mmvdump/main.go
  2. +4 −0 mmvdump/pcp.go
@@ -142,62 +142,36 @@ func data(file string) []byte {
return data
}
-func main() {
- flag.Parse()
-
- if flag.NArg() < 1 {
- fmt.Println("usage: mmvdump <file>")
- return
- }
-
- file := flag.Arg(0)
- d := data(file)
-
- var err error
- header, tocs, metrics, values, instances, indoms, strings, err = mmvdump.Dump(d)
- if err != nil {
- panic(err)
- }
-
- fmt.Printf(`
-File = %v
-Version = %v
-Generated = %v
-Toc Count = %v
-Cluster = %v
-Process = %v
-Flags = 0x%x
-
-`, file, header.Version, header.G1, header.Toc, header.Cluster, header.Process, int(header.Flag))
-
- toff := mmvdump.HeaderLength
+func printComponents() {
var (
- itemtype string
- itemsize uint64
- printItem func(uint64)
+ toff = mmvdump.HeaderLength
+ itemtype string
+ itemsize uint64
+ printItem func(uint64)
+ InstanceLength, MetricLength uint64
)
+ if header.Version == 1 {
+ InstanceLength = mmvdump.Instance1Length
+ MetricLength = mmvdump.Metric1Length
+ } else {
+ InstanceLength = mmvdump.Instance2Length
+ MetricLength = mmvdump.Metric2Length
+ }
+
for ti, toc := range tocs {
switch toc.Type {
case mmvdump.TocInstances:
itemtype = "instances"
- if header.Version == 1 {
- itemsize = mmvdump.Instance1Length
- } else {
- itemsize = mmvdump.Instance2Length
- }
+ itemsize = InstanceLength
printItem = printInstance
case mmvdump.TocIndoms:
itemtype = "indoms"
itemsize = mmvdump.InstanceDomainLength
printItem = printInstanceDomain
case mmvdump.TocMetrics:
itemtype = "metric"
- if header.Version == 1 {
- itemsize = mmvdump.Metric1Length
- } else {
- itemsize = mmvdump.Metric2Length
- }
+ itemsize = MetricLength
printItem = printMetric
case mmvdump.TocValues:
itemtype = "values"
@@ -218,3 +192,34 @@ Flags = 0x%x
toff += mmvdump.TocLength
}
}
+
+func main() {
+ flag.Parse()
+
+ if flag.NArg() < 1 {
+ fmt.Println("usage: mmvdump <file>")
+ return
+ }
+
+ file := flag.Arg(0)
+ d := data(file)
+
+ var err error
+ header, tocs, metrics, values, instances, indoms, strings, err = mmvdump.Dump(d)
+ if err != nil {
+ panic(err)
+ }
+
+ fmt.Printf(`
+File = %v
+Version = %v
+Generated = %v
+Toc Count = %v
+Cluster = %v
+Process = %v
+Flags = 0x%x
+
+`, file, header.Version, header.G1, header.Toc, header.Cluster, header.Process, int(header.Flag))
+
+ printComponents()
+}
View
@@ -49,6 +49,7 @@ type Toc struct {
type Instance interface {
Indom() uint64
Internal() int32
+ Padding() uint32
}
// InstanceBase defines the common contents in a valid instance
@@ -64,6 +65,9 @@ func (i InstanceBase) Indom() uint64 { return i.indom }
// Internal returns the internal id
func (i InstanceBase) Internal() int32 { return i.internal }
+// Padding returns the padding value
+func (i InstanceBase) Padding() uint32 { return i.padding }
+
// Instance1 defines the contents in a valid mmv1 instance
type Instance1 struct {
InstanceBase

0 comments on commit 752f916

Please sign in to comment.