forked from rai-project/dlframework
/
read.go
36 lines (28 loc) · 824 Bytes
/
read.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package plotting
import (
"os"
"github.com/mailru/easyjson"
"github.com/unknwon/com"
"github.com/pkg/errors"
"github.com/c3sr/dlframework/evaluation"
model "github.com/jaegertracing/jaeger/model/json"
)
func ReadTraceFile(path string) ([]model.Span, error) {
if !com.IsFile(path) {
return nil, errors.Errorf("the trace file %v was not found", path)
}
f, err := os.Open(path)
if err != nil {
return nil, errors.Wrapf(err, "unable to open the trace file %v", path)
}
defer f.Close()
var trace evaluation.TraceInformation
err = easyjson.UnmarshalFromReader(f, &trace)
if err != nil {
return nil, errors.Wrapf(err, "unable to decode the trace file %v", path)
}
if len(trace.Traces) == 0 {
return nil, errors.Wrapf(err, "no traces were found in %v", path)
}
return trace.Traces[0].Spans, nil
}