-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathinstrumentation.go
77 lines (61 loc) · 1.5 KB
/
instrumentation.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
// +build instrumentation
// +build !debug
package cu
import (
"log"
"runtime"
"sync"
)
const DEBUG = false
var tc uint32
// var _logger_ = log.New(os.Stderr, "", 0)
// var replacement = "\n"
func tabcount() int { return 0 }
func enterLoggingContext() {}
func leaveLoggingContext() {}
func logf(format string, others ...interface{}) {}
func logCaller(inspect string) {
pc, _, _, _ := runtime.Caller(2)
logf("%q Called by %v", inspect, runtime.FuncForPC(pc).Name())
}
/* Operational statistics related debugging */
var ql = new(sync.Mutex)
var q = make([]int, 0, 1000) // 1000 calls to DoWork
var blockingCallers = make(map[string]int)
func addQueueLength(l int) {
ql.Lock()
q = append(q, l)
ql.Unlock()
}
// QueueLengths return the queue lengths recorded
func QueueLengths() []int {
return q
}
// AverageQueueLength returns the average queue length recorded. This allows for optimizations.
func AverageQueueLength() int {
ql.Lock()
var s int
for _, l := range q {
s += l
}
avg := s / len(q) // yes, it's an integer division
ql.Unlock()
return avg
}
func addBlockingCallers() {
pc, _, _, _ := runtime.Caller(3)
fn := runtime.FuncForPC(pc)
ql.Lock()
blockingCallers[fn.Name()]++
ql.Unlock()
}
func BlockingCallers() map[string]int {
return blockingCallers
}
func (ctx *BatchedContext) QUEUE() []call {
log.Println(len(ctx.queue))
return ctx.queue
}
func (ctx *BatchedContext) Introspect() string {
return ctx.introspect()
}