-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathstats.go
79 lines (67 loc) · 1.58 KB
/
stats.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
package tiledb
/*
#cgo LDFLAGS: -ltiledb
#cgo linux LDFLAGS: -ldl
#include <tiledb/tiledb.h>
#include <stdio.h>
#include <stdlib.h>
*/
import "C"
import (
"fmt"
"os"
"unsafe"
)
// StatsEnable enable internal statistics gathering
func StatsEnable() error {
ret := C.tiledb_stats_enable()
if ret != C.TILEDB_OK {
return fmt.Errorf("Error enabling stats")
}
return nil
}
// StatsDisable disable internal statistics gathering.
func StatsDisable() error {
ret := C.tiledb_stats_disable()
if ret != C.TILEDB_OK {
return fmt.Errorf("Error disabling stats")
}
return nil
}
// StatsReset reset all internal statistics counters to 0.
func StatsReset() error {
ret := C.tiledb_stats_reset()
if ret != C.TILEDB_OK {
return fmt.Errorf("Error resetting stats")
}
return nil
}
// StatsDumpSTDOUT prints internal stats to stdout
func StatsDumpSTDOUT() error {
ret := C.tiledb_stats_dump(C.stdout)
if ret != C.TILEDB_OK {
return fmt.Errorf("Error dumping stats to stdout")
}
return nil
}
// StatsDump prints internal stats to file path given
func StatsDump(path string) error {
if _, err := os.Stat(path); err == nil {
return fmt.Errorf("Error path already %s exists", path)
}
// Convert to char *
cPath := C.CString(path)
defer C.free(unsafe.Pointer(cPath))
// Set mode as char*
cMode := C.CString("w")
defer C.free(unsafe.Pointer(cMode))
// Open file to get FILE*
cFile := C.fopen(cPath, cMode)
defer C.fclose(cFile)
// Dump stats to file
ret := C.tiledb_stats_dump(cFile)
if ret != C.TILEDB_OK {
return fmt.Errorf("Error dumping stats to file %s", path)
}
return nil
}