-
Notifications
You must be signed in to change notification settings - Fork 7
/
web100_cli.go
67 lines (54 loc) · 1.38 KB
/
web100_cli.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// web100_cli provides a simple CLI interface to web100 functions.
package main
// example:
// go build cmd/web100_cli/web100_cli.go
// ./web100_cli -filename parser/testdata/20170509T13\:45\:13.590210000Z_eb.measurementlab.net\:44160.s2c_snaplog
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"cloud.google.com/go/bigquery"
"github.com/m-lab/etl/schema"
"github.com/m-lab/etl/web100"
)
var (
filename = flag.String("filename", "", "Trace filename.")
tcpKis = flag.String("tcp-kis", "tcp-kis.txt", "tcp-kis.txt filename.")
)
func prettyPrint(results map[string]bigquery.Value) {
b, err := json.MarshalIndent(results, "", " ")
if err != nil {
fmt.Println("error:", err)
}
fmt.Print(string(b))
}
func main() {
flag.Parse()
fmt.Println(*filename)
content, err := ioutil.ReadFile(*filename)
if err != nil {
panic(err)
}
snaplog, err := web100.NewSnapLog(content)
if err != nil {
panic(err)
}
err = snaplog.ValidateSnapshots()
if err != nil {
panic(err)
}
last := snaplog.SnapCount() - 1
snap, err := snaplog.Snapshot(last)
if err != nil {
panic(err)
}
snapValues := schema.EmptySnap()
snap.SnapshotValues(snapValues)
nestedConnSpec := make(schema.Web100ValueMap, 6)
snaplog.ConnectionSpecValues(nestedConnSpec)
results := schema.NewWeb100MinimalRecord(
snaplog.Version, int64(snaplog.LogTime),
nestedConnSpec, snapValues, nil)
prettyPrint(results)
}