Skip to content

Commit

Permalink
examples: add ticker Stop function
Browse files Browse the repository at this point in the history
When using ticker, ensure ticker is stopped after program exit.

Signed-off-by: jun.gu <gujun4990@outlook.com>
  • Loading branch information
gujun4990 authored and lmb committed Apr 4, 2022
1 parent 51f435a commit 0d43986
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/cgroup_skb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func main() {
// Read loop reporting the total amount of times the kernel
// function was entered, once per second.
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()

for range ticker.C {
var value uint64
Expand Down
1 change: 1 addition & 0 deletions examples/kprobe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func main() {
// Read loop reporting the total amount of times the kernel
// function was entered, once per second.
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()

log.Println("Waiting for events..")

Expand Down
1 change: 1 addition & 0 deletions examples/kprobe_percpu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func main() {
// Read loop reporting the total amount of times the kernel
// function was entered, once per second.
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()

log.Println("Waiting for events..")

Expand Down
1 change: 1 addition & 0 deletions examples/kprobepin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func main() {
// Read loop reporting the total amount of times the kernel
// function was entered, once per second.
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()

log.Println("Waiting for events..")

Expand Down
2 changes: 2 additions & 0 deletions examples/tracepoint_in_c/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func main() {
// Read loop reporting the total amount of times the kernel
// function was entered, once per second.
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()

log.Println("Waiting for events..")
for range ticker.C {
var value uint64
Expand Down

0 comments on commit 0d43986

Please sign in to comment.