-
Notifications
You must be signed in to change notification settings - Fork 921
/
measure_allocs.go
38 lines (30 loc) · 1.13 KB
/
measure_allocs.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
package allocstat
import (
"fmt"
"runtime"
"time"
"github.com/jonas747/dcmd"
"github.com/jonas747/yagpdb/commands"
"github.com/jonas747/yagpdb/common"
"github.com/jonas747/yagpdb/stdcommands/util"
)
var Command = &commands.YAGCommand{
CmdCategory: commands.CategoryDebug,
HideFromCommandsPage: true,
Name: "allocstat",
Description: "Memory statistics.",
HideFromHelp: true,
RunFunc: util.RequireBotAdmin(func(data *dcmd.Data) (interface{}, error) {
common.BotSession.ChannelTyping(data.CS.ID)
var memstatsStarted runtime.MemStats
runtime.ReadMemStats(&memstatsStarted)
time.Sleep(time.Second * 10)
var memstatsStopped runtime.MemStats
runtime.ReadMemStats(&memstatsStopped)
bytesAlloc := (memstatsStopped.TotalAlloc - memstatsStarted.TotalAlloc) / 1000
numAlloc := memstatsStopped.Mallocs - memstatsStarted.Mallocs
lastGC := time.Unix(0, int64(memstatsStopped.LastGC))
numGC := memstatsStopped.NumGC
return fmt.Sprintf("Bytes allocated(10s): %dKB\nNum allocs (10s): %d\nLast gc: %s\nNum gc (from start): %d", bytesAlloc, numAlloc, time.Since(lastGC), numGC), nil
}),
}