-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (44 loc) · 1.21 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
package main
import (
"log"
"os"
"runtime"
"runtime/pprof"
"github.com/Saur4ig/1brc_go/versions"
)
func main() {
path := "../1bcfile/measurements.txt"
//path := "data/test.txt"
// profile files
cpuProfile := "cpu.prof"
memProfile := "mem.prof"
// start CPU profiling
startCPUProfile(cpuProfile)
defer pprof.StopCPUProfile()
// read the file and process data
versions.ProcessParallelV1(path)
// capture memory profile.
writeMemoryProfile(memProfile)
}
// startCPUProfile starts CPU profiling and saves it to the specified file
func startCPUProfile(cpuProfile string) {
f, err := os.Create(cpuProfile)
if err != nil {
log.Fatalf("could not create CPU profile: %s", err)
}
if err := pprof.StartCPUProfile(f); err != nil {
log.Fatalf("could not start CPU profile: %s", err)
}
}
// writeMemoryProfile writes the current memory profile to the specified file
func writeMemoryProfile(memProfile string) {
mf, err := os.Create(memProfile)
if err != nil {
log.Fatalf("could not create memory profile: %s", err)
}
defer mf.Close()
runtime.GC() // run garbage collection to update memory statistics
if err := pprof.WriteHeapProfile(mf); err != nil {
log.Fatalf("could not write memory profile: %s", err)
}
}