Permalink
Browse files

mmvdump: fix some lint warnings

  • Loading branch information...
1 parent 0d922a0 commit cf504d2a3c56687e5d1b12cd75d5d256aa7b7671 @suyash suyash committed Jul 23, 2016
Showing with 40 additions and 24 deletions.
  1. +22 −17 mmvdump/cmd/mmvdump/main.go
  2. +18 −7 mmvdump/pcp.go
@@ -25,7 +25,7 @@ func printMetric(offset uint64) {
fmt.Printf("\t\ttype=%v (0x%x), sem=%v (0x%x), pad=0x%x\n", m.Typ, int(m.Typ), m.Sem, int(m.Sem), m.Padding)
fmt.Printf("\t\tunits=%v\n", m.Unit)
- if m.Indom == mmvdump.NO_INDOM {
+ if m.Indom == mmvdump.NoIndom {
fmt.Printf("\t\t(no indom)\n")
} else {
fmt.Printf("\t\tindom=%d\n", m.Indom)
@@ -61,7 +61,7 @@ func printValue(offset uint64) {
a, err = mmvdump.StringVal(v.Val, strings)
}
- if m.Indom != mmvdump.NO_INDOM {
+ if m.Indom != mmvdump.NoIndom {
i := instances[v.Instance]
fmt.Printf("[%d or \"%s\"]", i.Internal, string(i.External[:]))
}
@@ -77,15 +77,7 @@ func printString(offset uint64) {
fmt.Printf("\t[%v] %v\n", offset, string(strings[offset].Payload[:]))
}
-func main() {
- flag.Parse()
-
- if flag.NArg() < 1 {
- panic("Usage: mmvdump <file>")
- }
-
- file := flag.Arg(0)
-
+func data(file string) []byte {
f, err := os.Open(file)
if err != nil {
panic(err)
@@ -104,7 +96,20 @@ func main() {
panic(err)
}
- header, tocs, metrics, values, instances, indoms, strings, err = mmvdump.Dump(data)
+ return data
+}
+
+func main() {
+ flag.Parse()
+
+ if flag.NArg() < 1 {
+ panic("Usage: mmvdump <file>")
+ }
+
+ file := flag.Arg(0)
+ d := data(file)
+
+ header, tocs, metrics, values, instances, indoms, strings, err = mmvdump.Dump(d)
if err != nil {
panic(err)
}
@@ -120,30 +125,30 @@ Flags = 0x%x
`, file, header.Version, header.G1, header.Toc, header.Cluster, header.Process, int(header.Flag))
- offset := mmvdump.HeaderLength
+ toff := mmvdump.HeaderLength
for _, toc := range tocs {
switch toc.Type {
case mmvdump.TocMetrics:
- fmt.Printf("TOC[%v], offset: %v, metrics offset: %v (%v entries)\n", int(toc.Type), offset, toc.Offset, toc.Count)
+ 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)
}
case mmvdump.TocValues:
- fmt.Printf("TOC[%v], offset: %v, values offset: %v (%v entries)\n", int(toc.Type), offset, toc.Offset, toc.Count)
+ 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)
}
case mmvdump.TocStrings:
- fmt.Printf("TOC[%v], offset: %v, strings offset: %v (%v entries)\n", int(toc.Type), offset, toc.Offset, toc.Count)
+ 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)
}
}
fmt.Println()
- offset += mmvdump.TocLength
+ toff += mmvdump.TocLength
}
}
View
@@ -1,11 +1,17 @@
package mmvdump
+// MMVVersion is the current mmv format version
const MMVVersion = 1
const (
- NAMEMAX = 64
- STRINGMAX = 256
- NO_INDOM = -1
+ // Maximum allowed length of a name
+ NameMax = 64
+
+ // Maximum allowed length of a string
+ StringMax = 256
+
+ // Constant used to indicate abscence of an indom from a metric
+ NoIndom = -1
)
// Header describes the data in a MMV header
@@ -21,6 +27,7 @@ type Header struct {
// TocType is an enumerated type with different types as values
type TocType int32
+// Values for TocType
const (
TocIndoms TocType = iota + 1
TocInstances
@@ -43,18 +50,18 @@ type Instance struct {
Indom uint64
Padding uint32
Internal int32
- External [NAMEMAX]byte
+ External [NameMax]byte
}
// InstanceDomain defines the contents in a valid instance domain
type InstanceDomain struct {
Serial, Count uint32
- offset, shorttext, longtext uint64
+ Offset, Shorttext, Longtext uint64
}
// Metric defines the contents in a valid Metric
type Metric struct {
- Name [NAMEMAX]byte
+ Name [NameMax]byte
Item uint32
Typ Type
Sem Semantics
@@ -77,7 +84,7 @@ type Value struct {
// String wraps the payload for a PCP String
type String struct {
- Payload [STRINGMAX]byte
+ Payload [StringMax]byte
}
// Type is an enumerated type representing all valid types for a metric
@@ -101,6 +108,7 @@ const (
// Unit is an enumerated type with all possible units as values
type Unit uint32
+// Values for Space Units
const (
ByteUnit Unit = 1<<28 | iota<<16
KilobyteUnit
@@ -111,6 +119,7 @@ const (
ExabyteUnit
)
+// Values for Time Units
const (
NanosecondUnit Unit = 1<<24 | iota<<12
MicrosecondUnit
@@ -120,6 +129,7 @@ const (
HourUnit
)
+// Values for Count Units
const OneUnit Unit = 1<<20 | iota<<8
//go:generate stringer --type=Unit
@@ -136,6 +146,7 @@ const (
//go:generate stringer -type=Semantics
+// Byte Lengths for Different Components
const (
HeaderLength uint64 = 40
TocLength = 16

0 comments on commit cf504d2

Please sign in to comment.