Skip to content

Commit

Permalink
refactor: 用户任务,go trace
Browse files Browse the repository at this point in the history
  • Loading branch information
yiGmMk committed Nov 10, 2023
1 parent ed9d1b5 commit 8ab9bcc
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions base/runtime/trace/trace_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package trace

import (
"context"
"fmt"
"log"
"os"
Expand Down Expand Up @@ -29,6 +30,10 @@ func TestTrace(t *testing.T) {
}
defer trace.Stop()

// 用户任务
ctx, task := trace.NewTask(context.Background(), "trace 用户任务")
defer task.End()

// 下面就是你的监控的程序
// 我简单写了一个文件读写
var wg sync.WaitGroup
Expand All @@ -37,13 +42,19 @@ func TestTrace(t *testing.T) {
// 一个协程用来读文件
go func() {
defer wg.Done()
r := trace.StartRegion(ctx, "reading file")
defer r.End()

content, err := os.ReadFile(`mxc.txt`)
fmt.Println(content, err)
}()

// 写文件协程
go func() {
defer wg.Done()
r := trace.StartRegion(ctx, "reading file")
defer r.End()

fmt.Println("hello trace")
}()
wg.Wait()
Expand Down

0 comments on commit 8ab9bcc

Please sign in to comment.