/
stats.go
153 lines (126 loc) · 3.28 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
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
}
// Stats returns internal stats as string
func Stats() (string, error) {
var msg *C.char
// Dump stats to string
ret := C.tiledb_stats_dump_str(&msg)
if ret != C.TILEDB_OK {
return "", fmt.Errorf("Error dumping stats to string")
}
s := C.GoString(msg)
ret = C.tiledb_stats_free_str(&msg)
if ret != C.TILEDB_OK {
return "", fmt.Errorf("Error freeing string from dumping stats to string")
}
return s, nil
}
// StatsRawDumpSTDOUT prints internal raw (json) stats to stdout
func StatsRawDumpSTDOUT() error {
ret := C.tiledb_stats_raw_dump(C.stdout)
if ret != C.TILEDB_OK {
return fmt.Errorf("Error dumping stats to stdout")
}
return nil
}
// StatsRawDump prints internal raw (json) stats to file path given
func StatsRawDump(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_raw_dump(cFile)
if ret != C.TILEDB_OK {
return fmt.Errorf("Error dumping stats to file %s", path)
}
return nil
}
// StatsRaw returns internal raw (json) stats as string
func StatsRaw() (string, error) {
var msg *C.char
// Dump stats to string
ret := C.tiledb_stats_raw_dump_str(&msg)
if ret != C.TILEDB_OK {
return "", fmt.Errorf("Error dumping raw stats to string")
}
s := C.GoString(msg)
ret = C.tiledb_stats_free_str(&msg)
if ret != C.TILEDB_OK {
return "", fmt.Errorf("Error freeing string from dumping raw stats to string")
}
return s, nil
}