-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (61 loc) · 1.43 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
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"runtime/pprof"
"time"
"github.com/jackc/pgx/v5/pgxpool"
)
var connstring = "postgresql://postgres:postgres@localhost:5432/osmconverter"
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
var memprofile = flag.String("memprofile", "", "write mem profile to file")
var upload = flag.Bool("upload", false, "Upload data to postgres")
func main() {
flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
defer f.Close()
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
if *memprofile != "" {
f, err := os.Create(*memprofile)
if err != nil {
log.Fatal(err)
}
defer f.Close()
pprof.WriteHeapProfile(f)
}
start := time.Now()
// file, err := os.Open("D:/Downloads/rheinland-pfalz-latest.osm.pbf")
file, err := os.Open("./testdata/andorra-latest.osm.pbf")
if err != nil {
log.Fatalln("Error reading file:", err)
}
defer file.Close()
err = Parse(file)
if err != nil {
log.Fatal(err)
}
fmt.Println("Parsing done in:", time.Since(start))
if *upload {
start := time.Now()
pool, err := pgxpool.New(context.Background(), connstring)
if err != nil {
log.Fatal(err)
}
defer pool.Close()
toDB(pool)
if err != nil {
log.Fatal(err)
}
fmt.Println("Uploading done in :", time.Since(start))
}
fmt.Println("Everything finished in:", time.Since(start))
}