-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
104 lines (93 loc) · 2.17 KB
/
main.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"flag"
"fmt"
"os"
"runtime"
"runtime/pprof"
"sort"
"github.com/wchargin/tensorboard-data-server/fs"
"github.com/wchargin/tensorboard-data-server/io/run"
)
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
var memprofile = flag.String("memprofile", "", "write memory profile to this file")
var bufsize = flag.Int("bufsize", 8192, "run.Reader.BufSize (bufio.NewReaderSize) capacity")
var chanbuf = flag.Int("chanbuf", 0, "make(chan ValueResult) capacity")
func main() {
flag.Parse()
args := flag.Args()
if len(args) != 1 {
fmt.Fprintf(os.Stderr, "must specify run directory as only argument\n")
os.Exit(1)
}
// Profiling structure copied from "go doc runtime/pprof".
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
fmt.Fprintf(os.Stderr, "creating CPU profile: %v\n", err)
os.Exit(1)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
readRunDirectory(args[0])
if *memprofile != "" {
fmt.Println("creating memory profile...")
f, err := os.Create(*memprofile)
if err != nil {
fmt.Fprintf(os.Stderr, "creating memory profile: %v\n", err)
os.Exit(1)
}
defer f.Close()
runtime.GC()
if err := pprof.WriteHeapProfile(f); err != nil {
fmt.Fprintf(os.Stderr, "writing memory profile: %v\n", err)
}
fmt.Println("done with memory profile")
}
}
func readRunDirectory(rundir string) {
rr := run.ReaderBuilder{
FS: fs.OS{},
Dir: rundir,
BufSize: *bufsize,
ChanBuf: *chanbuf,
}.Start()
done := make(chan struct{})
go func() {
rr.Reload()
close(done)
}()
events:
for {
select {
case res := <-rr.Out:
if res.Err != nil {
fmt.Fprintf(os.Stderr, "read error: %v\n", res)
}
case <-done:
break events
}
}
mds := rr.MetadataStore()
tags := make([]string, len(mds))
{
i := 0
for k := range mds {
tags[i] = k
i++
}
sort.Strings(tags)
for _, tag := range tags {
s := mds[tag].String()
if len(s) > 60 {
s = s[:57] + "..."
}
fmt.Printf("%v <%v>: meta=%v\n", tag, mds[tag].GetDataClass(), s)
}
}
if err := rr.Close(); err != nil {
fmt.Fprintf(os.Stderr, "closing run reader: %v\n", err)
os.Exit(1)
}
}