mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-18 04:49:55 +00:00
``` $ gvt delete github.com/weaveworks/common $ gvt fetch --revision 4d96fd8dcf2c7b417912c6219b310112cb4a4626 github.com/weaveworks/common 2018/07/23 15:31:11 Fetching: github.com/weaveworks/common 2018/07/23 15:31:14 · Skipping (existing): github.com/golang/protobuf/ptypes/any 2018/07/23 15:31:14 · Fetching recursive dependency: github.com/pkg/errors 2018/07/23 15:31:16 · Skipping (existing): github.com/aws/aws-sdk-go/aws 2018/07/23 15:31:16 · Fetching recursive dependency: github.com/sirupsen/logrus 2018/07/23 15:31:18 ·· Skipping (existing): golang.org/x/sys/unix 2018/07/23 15:31:18 ·· Skipping (existing): golang.org/x/crypto/ssh/terminal 2018/07/23 15:31:18 · Skipping (existing): google.golang.org/grpc/status 2018/07/23 15:31:18 · Skipping (existing): github.com/gorilla/mux 2018/07/23 15:31:18 · Fetching recursive dependency: github.com/opentracing-contrib/go-stdlib/nethttp 2018/07/23 15:31:20 ·· Skipping (existing): github.com/opentracing/opentracing-go/ext 2018/07/23 15:31:20 ·· Skipping (existing): github.com/opentracing/opentracing-go/log 2018/07/23 15:31:20 ·· Skipping (existing): github.com/opentracing/opentracing-go 2018/07/23 15:31:20 · Skipping (existing): github.com/prometheus/client_golang/prometheus 2018/07/23 15:31:20 · Skipping (existing): google.golang.org/grpc 2018/07/23 15:31:20 · Skipping (existing): github.com/pmezard/go-difflib/difflib 2018/07/23 15:31:20 · Fetching recursive dependency: github.com/go-kit/kit/log 2018/07/23 15:31:23 ·· Fetching recursive dependency: github.com/go-logfmt/logfmt 2018/07/23 15:31:25 ··· Fetching recursive dependency: github.com/kr/logfmt 2018/07/23 15:31:27 ·· Fetching recursive dependency: github.com/go-stack/stack 2018/07/23 15:31:29 · Fetching recursive dependency: google.golang.org/genproto/googleapis/rpc/status 2018/07/23 15:31:37 ·· Skipping (existing): github.com/golang/protobuf/proto 2018/07/23 15:31:37 ·· Skipping (existing): github.com/golang/protobuf/ptypes/any 2018/07/23 15:31:37 · Skipping (existing): github.com/opentracing/opentracing-go/log 2018/07/23 15:31:37 · Fetching recursive dependency: github.com/sercand/kuberesolver 2018/07/23 15:31:39 ·· Skipping (existing): google.golang.org/grpc/grpclog 2018/07/23 15:31:39 ·· Skipping (existing): google.golang.org/grpc/resolver 2018/07/23 15:31:39 ·· Skipping (existing): golang.org/x/net/context 2018/07/23 15:31:39 · Skipping (existing): google.golang.org/grpc/metadata 2018/07/23 15:31:39 · Skipping (existing): github.com/opentracing/opentracing-go/ext 2018/07/23 15:31:39 · Skipping (existing): github.com/armon/go-socks5 2018/07/23 15:31:39 · Skipping (existing): github.com/opentracing/opentracing-go 2018/07/23 15:31:39 · Skipping (existing): github.com/davecgh/go-spew/spew 2018/07/23 15:31:39 · Skipping (existing): github.com/golang/protobuf/ptypes 2018/07/23 15:31:39 · Skipping (existing): github.com/golang/protobuf/proto 2018/07/23 15:31:39 · Fetching recursive dependency: github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc 2018/07/23 15:31:41 ·· Skipping (existing): github.com/opentracing/opentracing-go/log 2018/07/23 15:31:41 ·· Skipping (existing): golang.org/x/net/context 2018/07/23 15:31:41 ·· Skipping (existing): google.golang.org/grpc/codes 2018/07/23 15:31:41 ·· Skipping (existing): github.com/golang/protobuf/proto 2018/07/23 15:31:41 ·· Skipping (existing): github.com/opentracing/opentracing-go 2018/07/23 15:31:41 ·· Skipping (existing): github.com/opentracing/opentracing-go/ext 2018/07/23 15:31:41 ·· Skipping (existing): google.golang.org/grpc 2018/07/23 15:31:41 ·· Skipping (existing): google.golang.org/grpc/metadata 2018/07/23 15:31:41 ·· Skipping (existing): google.golang.org/grpc/status 2018/07/23 15:31:41 · Fetching recursive dependency: github.com/uber/jaeger-client-go/config 2018/07/23 15:31:44 ·· Fetching recursive dependency: github.com/uber/jaeger-client-go/internal/throttler/remote 2018/07/23 15:31:44 ··· Fetching recursive dependency: github.com/uber/jaeger-client-go/utils 2018/07/23 15:31:44 ···· Fetching recursive dependency: github.com/uber/jaeger-client-go/thrift 2018/07/23 15:31:44 ···· Fetching recursive dependency: github.com/uber/jaeger-client-go/thrift-gen/agent 2018/07/23 15:31:44 ····· Fetching recursive dependency: github.com/uber/jaeger-client-go/thrift-gen/jaeger 2018/07/23 15:31:44 ····· Fetching recursive dependency: github.com/uber/jaeger-client-go/thrift-gen/zipkincore 2018/07/23 15:31:44 ··· Fetching recursive dependency: github.com/uber/jaeger-client-go 2018/07/23 15:31:44 ···· Fetching recursive dependency: github.com/crossdock/crossdock-go 2018/07/23 15:31:46 ····· Skipping (existing): github.com/davecgh/go-spew/spew 2018/07/23 15:31:46 ····· Skipping (existing): golang.org/x/net/context/ctxhttp 2018/07/23 15:31:46 ····· Skipping (existing): golang.org/x/net/context 2018/07/23 15:31:46 ····· Skipping (existing): github.com/pmezard/go-difflib/difflib 2018/07/23 15:31:46 ···· Skipping (existing): github.com/opentracing/opentracing-go/log 2018/07/23 15:31:46 ···· Fetching recursive dependency: go.uber.org/zap/zapcore 2018/07/23 15:31:49 ····· Fetching recursive dependency: go.uber.org/atomic 2018/07/23 15:31:51 ····· Fetching recursive dependency: go.uber.org/zap/internal/bufferpool 2018/07/23 15:31:51 ······ Fetching recursive dependency: go.uber.org/zap/buffer 2018/07/23 15:31:51 ····· Fetching recursive dependency: go.uber.org/multierr 2018/07/23 15:31:54 ····· Fetching recursive dependency: go.uber.org/zap/internal/exit 2018/07/23 15:31:54 ····· Fetching recursive dependency: go.uber.org/zap/internal/color 2018/07/23 15:31:54 ···· Fetching recursive dependency: go.uber.org/zap 2018/07/23 15:31:54 ···· Skipping (existing): github.com/opentracing/opentracing-go 2018/07/23 15:31:54 ···· Skipping (existing): github.com/opentracing/opentracing-go/ext 2018/07/23 15:31:54 ···· Fetching recursive dependency: github.com/uber/jaeger-lib/metrics 2018/07/23 15:31:56 ····· Fetching recursive dependency: github.com/uber-go/tally 2018/07/23 15:31:58 ······ Fetching recursive dependency: github.com/m3db/prometheus_client_golang/prometheus/promhttp 2018/07/23 15:32:00 ······· Skipping (existing): github.com/prometheus/client_golang/prometheus 2018/07/23 15:32:00 ······· Skipping (existing): github.com/prometheus/common/expfmt 2018/07/23 15:32:00 ······· Skipping (existing): github.com/prometheus/client_model/go 2018/07/23 15:32:00 ······ Fetching recursive dependency: gopkg.in/validator.v2 2018/07/23 15:32:06 ······ Fetching recursive dependency: github.com/cactus/go-statsd-client/statsd 2018/07/23 15:32:08 ······ Skipping (existing): gopkg.in/yaml.v2 2018/07/23 15:32:08 ······ Fetching recursive dependency: github.com/m3db/prometheus_client_golang/prometheus 2018/07/23 15:32:08 ······· Skipping (existing): github.com/prometheus/procfs 2018/07/23 15:32:08 ······· Skipping (existing): github.com/prometheus/client_model/go 2018/07/23 15:32:08 ······· Skipping (existing): github.com/prometheus/common/expfmt 2018/07/23 15:32:08 ······· Skipping (existing): golang.org/x/net/context 2018/07/23 15:32:08 ······· Skipping (existing): github.com/beorn7/perks/quantile 2018/07/23 15:32:08 ······· Skipping (existing): github.com/golang/protobuf/proto 2018/07/23 15:32:08 ······· Skipping (existing): github.com/prometheus/common/model 2018/07/23 15:32:08 ······· Skipping (existing): github.com/prometheus/client_golang/prometheus 2018/07/23 15:32:08 ······ Fetching recursive dependency: github.com/apache/thrift/lib/go/thrift 2018/07/23 15:32:13 ····· Skipping (existing): github.com/stretchr/testify/assert 2018/07/23 15:32:13 ····· Fetching recursive dependency: github.com/go-kit/kit/metrics/influx 2018/07/23 15:32:13 ······ Fetching recursive dependency: github.com/influxdata/influxdb/client/v2 2018/07/23 15:32:17 ······· Fetching recursive dependency: github.com/influxdata/influxdb/models 2018/07/23 15:32:17 ········ Fetching recursive dependency: github.com/influxdata/influxdb/pkg/escape 2018/07/23 15:32:17 ······ Fetching recursive dependency: github.com/go-kit/kit/metrics 2018/07/23 15:32:17 ······· Fetching recursive dependency: github.com/performancecopilot/speed 2018/07/23 15:32:19 ······· Fetching recursive dependency: github.com/aws/aws-sdk-go-v2/aws 2018/07/23 15:32:28 ········ Fetching recursive dependency: github.com/aws/aws-sdk-go-v2/internal/sdk 2018/07/23 15:32:28 ········ Skipping (existing): github.com/go-ini/ini 2018/07/23 15:32:28 ········ Fetching recursive dependency: github.com/aws/aws-sdk-go-v2/service/sts 2018/07/23 15:32:28 ········· Fetching recursive dependency: github.com/aws/aws-sdk-go-v2/private/protocol/query 2018/07/23 15:32:28 ·········· Fetching recursive dependency: github.com/aws/aws-sdk-go-v2/private/protocol 2018/07/23 15:32:28 ········· Fetching recursive dependency: github.com/aws/aws-sdk-go-v2/internal/awsutil 2018/07/23 15:32:28 ·········· Skipping (existing): github.com/jmespath/go-jmespath 2018/07/23 15:32:28 ······· Fetching recursive dependency: github.com/aws/aws-sdk-go-v2/service/cloudwatch 2018/07/23 15:32:29 ······· Skipping (existing): github.com/aws/aws-sdk-go/aws 2018/07/23 15:32:29 ······· Skipping (existing): github.com/prometheus/client_golang/prometheus 2018/07/23 15:32:29 ······· Skipping (existing): github.com/aws/aws-sdk-go/service/cloudwatch 2018/07/23 15:32:29 ······· Skipping (existing): github.com/aws/aws-sdk-go/service/cloudwatch/cloudwatchiface 2018/07/23 15:32:29 ······· Fetching recursive dependency: golang.org/x/sync/errgroup 2018/07/23 15:32:31 ········ Skipping (existing): golang.org/x/net/context 2018/07/23 15:32:31 ······· Fetching recursive dependency: github.com/go-kit/kit/util/conn 2018/07/23 15:32:31 ······· Fetching recursive dependency: github.com/VividCortex/gohistogram 2018/07/23 15:32:33 ····· Skipping (existing): github.com/prometheus/client_golang/prometheus 2018/07/23 15:32:33 ····· Fetching recursive dependency: github.com/codahale/hdrhistogram 2018/07/23 15:32:35 ·· Skipping (existing): github.com/opentracing/opentracing-go 2018/07/23 15:32:35 · Fetching recursive dependency: github.com/mwitkow/go-grpc-middleware 2018/07/23 15:32:37 ·· Fetching recursive dependency: github.com/grpc-ecosystem/go-grpc-middleware/logging 2018/07/23 15:32:39 ··· Fetching recursive dependency: github.com/grpc-ecosystem/go-grpc-middleware 2018/07/23 15:32:39 ···· Fetching recursive dependency: github.com/golang/protobuf/jsonpb 2018/07/23 15:32:42 ····· Skipping (existing): github.com/golang/protobuf/ptypes/timestamp 2018/07/23 15:32:42 ····· Skipping (existing): github.com/golang/protobuf/proto 2018/07/23 15:32:42 ····· Skipping (existing): github.com/golang/protobuf/ptypes/duration 2018/07/23 15:32:42 ····· Skipping (existing): github.com/golang/protobuf/ptypes/any 2018/07/23 15:32:42 ····· Skipping (existing): github.com/golang/protobuf/ptypes/struct 2018/07/23 15:32:42 ····· Skipping (existing): github.com/golang/protobuf/ptypes/wrappers 2018/07/23 15:32:42 ···· Skipping (existing): google.golang.org/grpc/metadata 2018/07/23 15:32:42 ···· Fetching recursive dependency: github.com/stretchr/testify/suite 2018/07/23 15:32:45 ····· Skipping (existing): github.com/stretchr/testify/assert 2018/07/23 15:32:45 ····· Fetching recursive dependency: github.com/stretchr/testify/require 2018/07/23 15:32:45 ······ Skipping (existing): github.com/stretchr/testify/assert 2018/07/23 15:32:45 ···· Skipping (existing): google.golang.org/grpc/peer 2018/07/23 15:32:45 ···· Skipping (existing): golang.org/x/net/context 2018/07/23 15:32:45 ···· Skipping (existing): golang.org/x/net/trace 2018/07/23 15:32:45 ···· Fetching recursive dependency: github.com/gogo/protobuf/gogoproto 2018/07/23 15:32:48 ····· Fetching recursive dependency: github.com/gogo/protobuf/protoc-gen-gogo/descriptor 2018/07/23 15:32:48 ······ Skipping (existing): github.com/gogo/protobuf/proto 2018/07/23 15:32:48 ····· Skipping (existing): github.com/gogo/protobuf/proto 2018/07/23 15:32:48 ···· Skipping (existing): google.golang.org/grpc/credentials 2018/07/23 15:32:48 ···· Skipping (existing): google.golang.org/grpc 2018/07/23 15:32:48 ···· Skipping (existing): github.com/opentracing/opentracing-go 2018/07/23 15:32:48 ···· Skipping (existing): google.golang.org/grpc/codes 2018/07/23 15:32:48 ···· Skipping (existing): github.com/golang/protobuf/proto 2018/07/23 15:32:48 ···· Skipping (existing): google.golang.org/grpc/grpclog 2018/07/23 15:32:48 ···· Skipping (existing): github.com/opentracing/opentracing-go/ext 2018/07/23 15:32:48 ···· Skipping (existing): github.com/opentracing/opentracing-go/log 2018/07/23 15:32:48 ··· Skipping (existing): golang.org/x/net/context 2018/07/23 15:32:48 ··· Skipping (existing): google.golang.org/grpc 2018/07/23 15:32:48 ··· Skipping (existing): google.golang.org/grpc/grpclog 2018/07/23 15:32:48 ··· Skipping (existing): google.golang.org/grpc/codes 2018/07/23 15:32:48 ··· Skipping (existing): github.com/golang/protobuf/proto 2018/07/23 15:32:48 ·· Skipping (existing): github.com/opentracing/opentracing-go 2018/07/23 15:32:48 ·· Skipping (existing): google.golang.org/grpc 2018/07/23 15:32:48 ·· Skipping (existing): golang.org/x/net/context 2018/07/23 15:32:48 ·· Skipping (existing): google.golang.org/grpc/codes 2018/07/23 15:32:48 ·· Skipping (existing): google.golang.org/grpc/grpclog 2018/07/23 15:32:48 ·· Skipping (existing): github.com/opentracing/opentracing-go/log 2018/07/23 15:32:48 ·· Skipping (existing): google.golang.org/grpc/metadata 2018/07/23 15:32:48 ·· Skipping (existing): google.golang.org/grpc/peer 2018/07/23 15:32:48 ·· Skipping (existing): google.golang.org/grpc/credentials 2018/07/23 15:32:48 ·· Skipping (existing): github.com/golang/protobuf/proto 2018/07/23 15:32:48 ·· Skipping (existing): golang.org/x/net/trace 2018/07/23 15:32:48 ·· Skipping (existing): github.com/opentracing/opentracing-go/ext 2018/07/23 15:32:48 · Fetching recursive dependency: github.com/weaveworks/promrus 2018/07/23 15:32:53 ·· Skipping (existing): gopkg.in/yaml.v2 2018/07/23 15:32:53 ·· Skipping (existing): golang.org/x/net/context/ctxhttp 2018/07/23 15:32:53 ·· Fetching recursive dependency: github.com/stretchr/objx 2018/07/23 15:32:55 ·· Fetching recursive dependency: gopkg.in/alecthomas/kingpin.v2 2018/07/23 15:32:58 ··· Fetching recursive dependency: github.com/alecthomas/units 2018/07/23 15:33:00 ··· Fetching recursive dependency: github.com/alecthomas/template 2018/07/23 15:33:02 ·· Fetching recursive dependency: github.com/julienschmidt/httprouter 2018/07/23 15:33:05 ·· Skipping (existing): golang.org/x/net/context 2018/07/23 15:33:05 · Skipping (existing): github.com/aws/aws-sdk-go/aws/credentials 2018/07/23 15:33:05 · Skipping (existing): github.com/golang/protobuf/ptypes/empty 2018/07/23 15:33:05 · Skipping (existing): golang.org/x/net/context 2018/07/23 15:33:05 · Skipping (existing): golang.org/x/tools/cover 2018/07/23 15:33:05 · Skipping (existing): github.com/mgutz/ansi ```
346 lines
8.5 KiB
Go
346 lines
8.5 KiB
Go
// Package mmvdump implements a go port of the C mmvdump utility included in PCP Core
|
|
//
|
|
// https://github.com/performancecopilot/pcp/blob/master/src/pmdas/mmv/mmvdump.c
|
|
//
|
|
// It has been written for maximum portability with the C equivalent, without having to use cgo or any other ninja stuff
|
|
//
|
|
// the main difference is that the reader is separate from the cli with the reading primarily implemented in mmvdump.go while the cli is implemented in cmd/mmvdump
|
|
//
|
|
// the cli application is completely go gettable and outputs the same things, in mostly the same way as the C cli app, to try it out,
|
|
//
|
|
// ```
|
|
// go get github.com/performancecopilot/speed/mmvdump/cmd/mmvdump
|
|
// ```
|
|
package mmvdump
|
|
|
|
import (
|
|
"math"
|
|
"sync"
|
|
"unsafe"
|
|
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
func readHeader(data []byte) (*Header, error) {
|
|
if uint64(len(data)) < HeaderLength {
|
|
return nil, errors.New("file too small to contain a valid Header")
|
|
}
|
|
|
|
header := (*Header)(unsafe.Pointer(&data[0]))
|
|
|
|
if m := header.Magic[:3]; string(m) != "MMV" {
|
|
return nil, errors.Errorf("Bad Magic: %v", string(m))
|
|
}
|
|
|
|
if header.G1 != header.G2 {
|
|
return nil, errors.Errorf("Mismatched version numbers, %v and %v", header.G1, header.G2)
|
|
}
|
|
|
|
return header, nil
|
|
}
|
|
|
|
func readToc(data []byte, offset uint64) (*Toc, error) {
|
|
if uint64(len(data)) < offset+TocLength {
|
|
return nil, errors.New("Incomplete/Partially Written TOC")
|
|
}
|
|
|
|
return (*Toc)(unsafe.Pointer(&data[offset])), nil
|
|
}
|
|
|
|
type itemReaderFunc func([]byte, uint64, int32) (interface{}, error)
|
|
|
|
func readInstance(data []byte, offset uint64, version int32) (interface{}, error) {
|
|
var InstanceLength = Instance1Length
|
|
if version == 2 {
|
|
InstanceLength = Instance2Length
|
|
}
|
|
|
|
if uint64(len(data)) < offset+InstanceLength {
|
|
return nil, errors.New("Incomplete/Partially Written Instance")
|
|
}
|
|
|
|
if version == 1 {
|
|
return (*Instance1)(unsafe.Pointer(&data[offset])), nil
|
|
}
|
|
|
|
return (*Instance2)(unsafe.Pointer(&data[offset])), nil
|
|
}
|
|
|
|
func readInstanceDomain(data []byte, offset uint64, version int32) (interface{}, error) {
|
|
if uint64(len(data)) < offset+InstanceDomainLength {
|
|
return nil, errors.New("Incomplete/Partially Written InstanceDomain")
|
|
}
|
|
|
|
return (*InstanceDomain)(unsafe.Pointer(&data[offset])), nil
|
|
}
|
|
|
|
func readMetric(data []byte, offset uint64, version int32) (interface{}, error) {
|
|
var MetricLength = Metric1Length
|
|
if version == 2 {
|
|
MetricLength = Metric2Length
|
|
}
|
|
|
|
if uint64(len(data)) < offset+MetricLength {
|
|
return nil, errors.New("Incomplete/Partially Written Metric")
|
|
}
|
|
|
|
if version == 1 {
|
|
return (*Metric1)(unsafe.Pointer(&data[offset])), nil
|
|
}
|
|
|
|
return (*Metric2)(unsafe.Pointer(&data[offset])), nil
|
|
}
|
|
|
|
func readValue(data []byte, offset uint64, version int32) (interface{}, error) {
|
|
if uint64(len(data)) < offset+ValueLength {
|
|
return nil, errors.New("Incomplete/Partially Written Value")
|
|
}
|
|
|
|
return (*Value)(unsafe.Pointer(&data[offset])), nil
|
|
}
|
|
|
|
func readString(data []byte, offset uint64, version int32) (interface{}, error) {
|
|
if uint64(len(data)) < offset+StringLength {
|
|
return nil, errors.New("Incomplete/Partially Written String")
|
|
}
|
|
|
|
return (*String)(unsafe.Pointer(&data[offset])), nil
|
|
}
|
|
|
|
func readTocs(data []byte, count int32) ([]*Toc, error) {
|
|
tocs := make([]*Toc, count)
|
|
|
|
for i := int32(0); i < count; i++ {
|
|
t, err := readToc(data, HeaderLength+uint64(i)*TocLength)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
tocs[i] = t
|
|
}
|
|
|
|
return tocs, nil
|
|
}
|
|
|
|
func readItems(data []byte, offset uint64, count int32, itemlength uint64, readItem itemReaderFunc, version int32) (map[uint64]interface{}, error) {
|
|
var wg sync.WaitGroup
|
|
wg.Add(int(count))
|
|
|
|
items := make(map[uint64]interface{})
|
|
|
|
var (
|
|
err error
|
|
m sync.Mutex
|
|
)
|
|
|
|
for i := int32(0); i < count; i, offset = i+1, offset+itemlength {
|
|
go func(offset uint64) {
|
|
if err == nil {
|
|
item, ierr := readItem(data, offset, version)
|
|
if ierr == nil {
|
|
m.Lock()
|
|
items[offset] = item
|
|
m.Unlock()
|
|
} else {
|
|
err = ierr
|
|
}
|
|
}
|
|
wg.Done()
|
|
}(offset)
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return items, nil
|
|
}
|
|
|
|
func readInstances(data []byte, offset uint64, count int32, version int32) (map[uint64]Instance, error) {
|
|
InstanceLength := Instance1Length
|
|
if version == 2 {
|
|
InstanceLength = Instance2Length
|
|
}
|
|
|
|
i, err := readItems(data, offset, count, InstanceLength, readInstance, version)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
instances := make(map[uint64]Instance)
|
|
for off, val := range i {
|
|
instances[off] = val.(Instance)
|
|
}
|
|
|
|
return instances, nil
|
|
}
|
|
|
|
func readInstanceDomains(data []byte, offset uint64, count int32, version int32) (map[uint64]*InstanceDomain, error) {
|
|
i, err := readItems(data, offset, count, InstanceDomainLength, readInstanceDomain, version)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
indoms := make(map[uint64]*InstanceDomain)
|
|
for off, val := range i {
|
|
indoms[off] = val.(*InstanceDomain)
|
|
}
|
|
|
|
return indoms, nil
|
|
}
|
|
|
|
func readMetrics(data []byte, offset uint64, count int32, version int32) (map[uint64]Metric, error) {
|
|
var MetricLength = Metric1Length
|
|
if version == 2 {
|
|
MetricLength = Metric2Length
|
|
}
|
|
|
|
m, err := readItems(data, offset, count, MetricLength, readMetric, version)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
metrics := make(map[uint64]Metric)
|
|
for off, val := range m {
|
|
metrics[off] = val.(Metric)
|
|
}
|
|
|
|
return metrics, nil
|
|
}
|
|
|
|
func readValues(data []byte, offset uint64, count int32, version int32) (map[uint64]*Value, error) {
|
|
v, err := readItems(data, offset, count, ValueLength, readValue, version)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
values := make(map[uint64]*Value)
|
|
for off, val := range v {
|
|
values[off] = val.(*Value)
|
|
}
|
|
|
|
return values, nil
|
|
}
|
|
|
|
func readStrings(data []byte, offset uint64, count int32, version int32) (map[uint64]*String, error) {
|
|
s, err := readItems(data, offset, count, StringLength, readString, version)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
strings := make(map[uint64]*String)
|
|
for off, val := range s {
|
|
strings[off] = val.(*String)
|
|
}
|
|
|
|
return strings, nil
|
|
}
|
|
|
|
func readComponents(data []byte, tocs []*Toc, version int32) (
|
|
metrics map[uint64]Metric,
|
|
values map[uint64]*Value,
|
|
instances map[uint64]Instance,
|
|
indoms map[uint64]*InstanceDomain,
|
|
strings map[uint64]*String,
|
|
ierr, inerr, merr, verr, serr error,
|
|
) {
|
|
var wg sync.WaitGroup
|
|
wg.Add(len(tocs))
|
|
|
|
for _, toc := range tocs {
|
|
switch toc.Type {
|
|
case TocInstances:
|
|
go func(offset uint64, count int32) {
|
|
instances, ierr = readInstances(data, offset, count, version)
|
|
wg.Done()
|
|
}(toc.Offset, toc.Count)
|
|
case TocIndoms:
|
|
go func(offset uint64, count int32) {
|
|
indoms, inerr = readInstanceDomains(data, offset, count, version)
|
|
wg.Done()
|
|
}(toc.Offset, toc.Count)
|
|
case TocMetrics:
|
|
go func(offset uint64, count int32) {
|
|
metrics, merr = readMetrics(data, offset, count, version)
|
|
wg.Done()
|
|
}(toc.Offset, toc.Count)
|
|
case TocValues:
|
|
go func(offset uint64, count int32) {
|
|
values, verr = readValues(data, offset, count, version)
|
|
wg.Done()
|
|
}(toc.Offset, toc.Count)
|
|
case TocStrings:
|
|
go func(offset uint64, count int32) {
|
|
strings, serr = readStrings(data, offset, count, version)
|
|
wg.Done()
|
|
}(toc.Offset, toc.Count)
|
|
}
|
|
}
|
|
|
|
wg.Wait()
|
|
|
|
return
|
|
}
|
|
|
|
// Dump creates a data dump from the passed data
|
|
func Dump(data []byte) (
|
|
h *Header,
|
|
tocs []*Toc,
|
|
metrics map[uint64]Metric,
|
|
values map[uint64]*Value,
|
|
instances map[uint64]Instance,
|
|
indoms map[uint64]*InstanceDomain,
|
|
strings map[uint64]*String,
|
|
err error,
|
|
) {
|
|
h, err = readHeader(data)
|
|
if err != nil {
|
|
return nil, nil, nil, nil, nil, nil, nil, err
|
|
}
|
|
|
|
tocs, err = readTocs(data, h.Toc)
|
|
if err != nil {
|
|
return nil, nil, nil, nil, nil, nil, nil, err
|
|
}
|
|
|
|
var ierr, inerr, merr, verr, serr error
|
|
|
|
metrics, values, instances, indoms, strings, ierr, inerr, merr, verr, serr = readComponents(data, tocs, h.Version)
|
|
|
|
switch {
|
|
case ierr != nil:
|
|
return nil, nil, nil, nil, nil, nil, nil, ierr
|
|
case inerr != nil:
|
|
return nil, nil, nil, nil, nil, nil, nil, inerr
|
|
case merr != nil:
|
|
return nil, nil, nil, nil, nil, nil, nil, merr
|
|
case verr != nil:
|
|
return nil, nil, nil, nil, nil, nil, nil, verr
|
|
case serr != nil:
|
|
return nil, nil, nil, nil, nil, nil, nil, serr
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// FixedVal will infer a fixed size value from the passed data
|
|
func FixedVal(data uint64, t Type) (interface{}, error) {
|
|
switch t {
|
|
case Int32Type:
|
|
return int32(data), nil
|
|
case Uint32Type:
|
|
return uint32(data), nil
|
|
case Int64Type:
|
|
return int64(data), nil
|
|
case Uint64Type:
|
|
return data, nil
|
|
case FloatType:
|
|
return math.Float32frombits(uint32(data)), nil
|
|
case DoubleType:
|
|
return math.Float64frombits(data), nil
|
|
}
|
|
|
|
return nil, errors.New("invalid type")
|
|
}
|