Skip to content

Commit dc264e0

Browse files
committed
Add Result in example
1 parent a71b8c3 commit dc264e0

File tree

10 files changed

+261
-10
lines changed

10 files changed

+261
-10
lines changed

examples/basic/runtimes/README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
# サンプルリスト
1+
# サンプルリスト
22

33
このディレクトリには以下のサンプルがあります。
44

5-
| file | example name | note |
6-
|----------------|----------------------|--------------------------------|
7-
| version.go | runtime\_version | runtime.Version() のサンプルです。 |
8-
| memorystats.go | runtime\_memorystats | runtime.MemoryStats() のサンプルです. |
9-
| gomaxprocs.go | runtime\_gomaxprocs | runtime.GOMAXPROCS() のサンプルです。 |
10-
| goexit.go | runtime\_goexit | runtime.Goexit() のサンプルです |
11-
| numcpu.go | runtime\_numcpu | runtime.NumCPU() のサンプルです |
12-
| gosched.go | runtime\_gosched | runtime.Gosched() のサンプルです |
13-
| debug\_buildinfo.go | runtime\_debug\_buildinfo | runtime/debug.ReadBuildInfo() のサンプルです |
5+
| file | example name | note |
6+
| ------------------ | ----------------------- | -------------------------------------------- |
7+
| version.go | runtime_version | runtime.Version() のサンプルです。 |
8+
| memorystats.go | runtime_memorystats | runtime.MemoryStats() のサンプルです. |
9+
| gomaxprocs.go | runtime_gomaxprocs | runtime.GOMAXPROCS() のサンプルです。 |
10+
| goexit.go | runtime_goexit | runtime.Goexit() のサンプルです |
11+
| numcpu.go | runtime_numcpu | runtime.NumCPU() のサンプルです |
12+
| gosched.go | runtime_gosched | runtime.Gosched() のサンプルです |
13+
| debug_buildinfo.go | runtime_debug_buildinfo | runtime/debug.ReadBuildInfo() のサンプルです |
14+
| caller.go | runtime_caller | runtime.Caller() のサンプルです. |
15+
| callers.go | runtime_callers | runtime.Callers() のサンプルです。 |

examples/basic/runtimes/caller.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,22 @@ func Caller() error {
3939
}
4040

4141
return nil
42+
43+
/*
44+
$ task
45+
task: [build] go build .
46+
task: [run] ./try-golang -onetime
47+
48+
ENTER EXAMPLE NAME: runtime_caller
49+
50+
[Name] "runtime_caller"
51+
[runtime.Caller] 8194836 /workspace/try-golang/examples/basic/runtimes/caller.go 29
52+
[runtime.Caller] 9119412 /workspace/try-golang/runner/exec.go 52
53+
[runtime.Caller] 9121316 /workspace/try-golang/runner/loop.go 126
54+
[runtime.Caller] 9120584 /workspace/try-golang/runner/loop.go 86
55+
[runtime.Caller] 9124390 /workspace/try-golang/cmd/root.go 66
56+
[runtime.Caller] 9125774 /workspace/try-golang/main.go 6
57+
58+
[Elapsed] 90.889µs
59+
*/
4260
}

examples/basic/runtimes/callers.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,26 @@ func Callers() error {
3232
}
3333

3434
return nil
35+
36+
/*
37+
$ task
38+
task: [build] go build .
39+
task: [run] ./try-golang -onetime
40+
41+
ENTER EXAMPLE NAME: runtime_callers
42+
43+
[Name] "runtime_callers"
44+
[runtime.CallersFrames] frames=9
45+
[runtime.Frames] 8195016 /home/gitpod/go/src/runtime/extern.go 308
46+
[runtime.Frames] 8194998 /workspace/try-golang/examples/basic/runtimes/callers.go 17
47+
[runtime.Frames] 9119412 /workspace/try-golang/runner/exec.go 52
48+
[runtime.Frames] 9121316 /workspace/try-golang/runner/loop.go 126
49+
[runtime.Frames] 9120348 /workspace/try-golang/runner/loop.go 79
50+
[runtime.Frames] 9124390 /workspace/try-golang/cmd/root.go 66
51+
[runtime.Frames] 9125774 /workspace/try-golang/main.go 6
52+
[runtime.Frames] 4452858 /home/gitpod/go/src/runtime/proc.go 267
53+
[runtime.Frames] 4654400 /home/gitpod/go/src/runtime/asm_amd64.s 1650
54+
55+
[Elapsed] 140.35µs
56+
*/
3557
}

examples/basic/runtimes/debug_buildinfo.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,49 @@ func DebugBuildInfo() error {
3737
}
3838

3939
return nil
40+
41+
/*
42+
$ task
43+
task: [build] go build .
44+
task: [run] ./try-golang -onetime
45+
46+
ENTER EXAMPLE NAME: runtime_debug_buildinfo
47+
48+
[Name] "runtime_debug_buildinfo"
49+
[BuildInfo] go go1.21.6
50+
path github.com/devlights/try-golang
51+
mod github.com/devlights/try-golang (devel)
52+
dep github.com/devlights/gomy v0.6.0 h1:7BT8bSxr+ZeNkgEYNufuM2rSc6kIoN6g2FSZvrcT9zw=
53+
dep github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI=
54+
dep github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
55+
dep golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
56+
dep golang.org/x/exp v0.0.0-20240119083558-1b970713d09a h1:Q8/wZp0KX97QFTc2ywcOE0YRjZPVIx+MXInMzdvQqcA=
57+
dep golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
58+
dep golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
59+
dep golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
60+
dep golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
61+
dep gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
62+
dep gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
63+
build -buildmode=exe
64+
build -compiler=gc
65+
build CGO_ENABLED=1
66+
build CGO_CFLAGS=
67+
build CGO_CPPFLAGS=
68+
build CGO_CXXFLAGS=
69+
build CGO_LDFLAGS=
70+
build GOARCH=amd64
71+
build GOOS=linux
72+
build GOAMD64=v1
73+
build vcs=git
74+
build vcs.revision=a71b8c37618dedfcb77af1728fbe8359a37704e4
75+
build vcs.time=2024-01-31T05:28:38Z
76+
build vcs.modified=true
77+
78+
--------------------------------------------------
79+
[Go Version] go1.21.6
80+
[Path] github.com/devlights/try-golang
81+
[revision] a71b8c37618dedfcb77af1728fbe8359a37704e4
82+
83+
[Elapsed] 75.61µs
84+
*/
4085
}

examples/basic/runtimes/goexit.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,21 @@ func Goexit() error {
4040
<-done
4141

4242
return nil
43+
44+
/*
45+
$ task
46+
task: [build] go build .
47+
task: [run] ./try-golang -onetime
48+
49+
ENTER EXAMPLE NAME: runtime_goexit
50+
51+
[Name] "runtime_goexit"
52+
[before] runtime.Goexit() 呼び出し前
53+
[fn1] hello
54+
[fn2] world
55+
56+
57+
[Elapsed] 94.7µs
58+
*/
59+
4360
}

examples/basic/runtimes/gomaxprocs.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,20 @@ func GoMaxProcs() error {
2828
output.Stdoutl("GOMAXPROCS", runtime.GOMAXPROCS(0))
2929

3030
return nil
31+
32+
/*
33+
$ task
34+
task: [build] go build .
35+
task: [run] ./try-golang -onetime
36+
37+
ENTER EXAMPLE NAME: runtime_gomaxprocs
38+
39+
[Name] "runtime_gomaxprocs"
40+
NumCPU 16
41+
GOMAXPROCS 16
42+
43+
44+
[Elapsed] 12.65µs
45+
*/
46+
3147
}

examples/basic/runtimes/gosched.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,37 @@ func Gosched() error {
7272
wg.Wait()
7373

7474
return nil
75+
76+
/*
77+
$ task
78+
task: [build] go build .
79+
task: [run] ./try-golang -onetime
80+
81+
ENTER EXAMPLE NAME: runtime_gosched
82+
83+
[Name] "runtime_gosched"
84+
[goroutine-04] hello [4]
85+
[goroutine-04] world [4]
86+
[goroutine-02] hello [2]
87+
[goroutine-02] world [2]
88+
[goroutine-03] hello [3]
89+
[goroutine-03] world [3]
90+
[goroutine-01] hello [1]
91+
[goroutine-01] world [1]
92+
[goroutine-00] hello [0]
93+
[goroutine-00] world [0]
94+
--------------------------------------------------
95+
[goroutine-04] hello [4]
96+
[goroutine-00] hello [0]
97+
[goroutine-01] hello [1]
98+
[goroutine-02] hello [2]
99+
[goroutine-03] hello [3]
100+
[goroutine-04] world [4]
101+
[goroutine-00] world [0]
102+
[goroutine-02] world [2]
103+
[goroutine-03] world [3]
104+
[goroutine-01] world [1]
105+
106+
[Elapsed] 486.98µs
107+
*/
75108
}

examples/basic/runtimes/memorystats.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,76 @@ func RuntimeMemoryStats() error {
8989
printMemoryStats("after runtime.GC()")
9090

9191
return nil
92+
93+
/*
94+
$ task
95+
task: [build] go build .
96+
task: [run] ./try-golang -onetime
97+
98+
ENTER EXAMPLE NAME: runtime_memorystats
99+
100+
[Name] "runtime_memorystats"
101+
init ----------------------------
102+
Alloc 365
103+
HeapAlloc 365
104+
TotalAlloc 437
105+
HeapObjects 1
106+
Sys 9253
107+
NumGC 1
108+
(1) ----------------------------
109+
Alloc 4462
110+
HeapAlloc 4462
111+
TotalAlloc 4538
112+
HeapObjects 1
113+
Sys 13413
114+
NumGC 2
115+
(2) ----------------------------
116+
Alloc 8559
117+
HeapAlloc 8559
118+
TotalAlloc 8635
119+
HeapObjects 1
120+
Sys 17765
121+
NumGC 2
122+
(3) ----------------------------
123+
Alloc 12657
124+
HeapAlloc 12657
125+
TotalAlloc 12737
126+
HeapObjects 1
127+
Sys 22117
128+
NumGC 3
129+
(4) ----------------------------
130+
Alloc 16754
131+
HeapAlloc 16754
132+
TotalAlloc 16834
133+
HeapObjects 1
134+
Sys 26213
135+
NumGC 3
136+
(5) ----------------------------
137+
Alloc 20851
138+
HeapAlloc 20851
139+
TotalAlloc 20935
140+
HeapObjects 1
141+
Sys 30565
142+
NumGC 4
143+
latest ----------------------------
144+
Alloc 20852
145+
HeapAlloc 20852
146+
TotalAlloc 20935
147+
HeapObjects 1
148+
Sys 30565
149+
NumGC 4
150+
after runtime.GC() ----------------------------
151+
Alloc 372
152+
HeapAlloc 372
153+
TotalAlloc 20940
154+
HeapObjects 1
155+
Sys 30565
156+
NumGC 5
157+
158+
159+
[Elapsed] 10.010817629s
160+
*/
161+
92162
}
93163

94164
func printMemoryStats(prefix string) {

examples/basic/runtimes/numcpu.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,17 @@ func NumCpu() error {
2121
output.Stdoutl("[Number of CPU cores]", cpus)
2222

2323
return nil
24+
25+
/*
26+
$ task
27+
task: [build] go build .
28+
task: [run] ./try-golang -onetime
29+
30+
ENTER EXAMPLE NAME: runtime_numcpu
31+
32+
[Name] "runtime_numcpu"
33+
[Number of CPU cores] 16
34+
35+
[Elapsed] 8.79µs
36+
*/
2437
}

examples/basic/runtimes/version.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,19 @@ func RuntimeVersion() error {
1212
fmt.Println(ver)
1313

1414
return nil
15+
16+
/*
17+
$ task
18+
task: Task "build" is up to date
19+
task: [run] ./try-golang -onetime
20+
21+
ENTER EXAMPLE NAME: runtime_version
22+
23+
[Name] "runtime_version"
24+
go1.21.6
25+
26+
27+
[Elapsed] 3.21µs
28+
*/
29+
1530
}

0 commit comments

Comments
 (0)