forked from sorrell/profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
74 lines (56 loc) · 1.8 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
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"time"
"github.com/adrenallen/profiler/db"
"github.com/adrenallen/profiler/profiler"
)
func main() {
run()
}
func run() {
log.Println("Preparing profiler")
targetConnDBType := flag.String("targetDBType", db.DB_CONN_POSTGRES, "Target database type")
targetConnString := flag.String("targetDB", "", "Target database connection string")
profileConnDBType := flag.String("profileDBType", db.DB_CONN_POSTGRES, "Profile database type")
profileConnString := flag.String("profileDB", "", "Profile store database connection string")
profileDefinitionPath := flag.String("profileDefinition", "", "Path to profile definition JSON file")
usePascalCase := flag.Bool("usePascalCase", false, "Use pascal case for table and column naming in profile database")
flag.Parse()
targetCon, err := db.GetDBConnByType(*targetConnDBType, *targetConnString)
if err != nil {
log.Fatal(fmt.Errorf(`error getting target database connection: %v`, err))
}
profileCon, err := db.GetDBConnByType(*profileConnDBType, *profileConnString)
if err != nil {
log.Fatal(fmt.Errorf(`error getting profile database connection: %v`, err))
}
options := profiler.ProfilerOptions{
UsePascalCase: *usePascalCase,
}
//Read in the profile definition file
fileData, err := ioutil.ReadFile(*profileDefinitionPath)
if err != nil {
log.Fatal(err)
}
var profile profiler.ProfileDefinition
err = json.Unmarshal(fileData, &profile)
if err != nil {
log.Fatal(err)
}
log.Printf("Starting profile...\n")
start := time.Now()
p := profiler.NewProfilerWithOptions(targetCon, profileCon, options)
err = p.RunProfile(profile)
if err != nil {
log.Fatal(err)
} else {
log.Println("Success")
}
end := time.Now()
log.Printf("Finished... time taken: %v\n", end.Sub(start))
}