/
main.go
70 lines (59 loc) · 1.39 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
package main
import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"runtime/pprof"
"strings"
"time"
"github.com/arukim/expansion/network"
)
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
var memprofile = flag.String("memprofile", "", "write memory profile to this file")
var urlStr = flag.String("url", "ws://127.0.0.1:8080/codenjoy-contest/ws?user=1@a.com", "server url")
func main() {
//"ws://ecsc00104eef.epam.com:8080/codenjoy-contest/ws?user=nikita_smelov3@epam.com"
flag.Parse()
log.SetFlags(0)
urls := strings.Split(*urlStr, " ")
for id, url := range urls {
network.NewClient(id, url)
}
if *memprofile != "" {
go func() {
for {
time.Sleep(time.Second * 2)
f, err := os.Create(*memprofile)
if err != nil {
log.Fatal(err)
}
pprof.WriteHeapProfile(f)
f.Close()
}
}()
}
if *cpuprofile != "" {
go func() {
for {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
fmt.Println("CPU profile start")
pprof.StartCPUProfile(f)
time.Sleep(time.Second * 30)
pprof.StopCPUProfile()
fmt.Println("CPU profile done")
f.Close()
}
}()
}
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
<-interrupt
log.Println("exiting")
// To cleanly close a connection, a client should send a close
// frame and wait for the server to close the connection.
}