1
2
3
4
5 package main
6
7 import "C"
8 import (
9 "internal/syscall/windows"
10 "runtime"
11 "sync"
12 "syscall"
13 "unsafe"
14 )
15
16 func init() {
17 register("StackMemory", StackMemory)
18 }
19
20 func getPagefileUsage() (uintptr, error) {
21 p, err := syscall.GetCurrentProcess()
22 if err != nil {
23 return 0, err
24 }
25 var m windows.PROCESS_MEMORY_COUNTERS
26 err = windows.GetProcessMemoryInfo(p, &m, uint32(unsafe.Sizeof(m)))
27 if err != nil {
28 return 0, err
29 }
30 return m.PagefileUsage, nil
31 }
32
33 func StackMemory() {
34 mem1, err := getPagefileUsage()
35 if err != nil {
36 panic(err)
37 }
38 const threadCount = 100
39 var wg sync.WaitGroup
40 for i := 0; i < threadCount; i++ {
41 wg.Add(1)
42 go func() {
43 runtime.LockOSThread()
44 wg.Done()
45 select {}
46 }()
47 }
48 wg.Wait()
49 mem2, err := getPagefileUsage()
50 if err != nil {
51 panic(err)
52 }
53
54
55
56 print((mem2 - mem1) / (threadCount + 10))
57 }
58
View as plain text