Skip to content

Commit

Permalink
chore: add trace
Browse files Browse the repository at this point in the history
Signed-off-by: Bo-Yi Wu <[email protected]>
  • Loading branch information
appleboy committed Aug 19, 2021
1 parent 02068ec commit 10041f8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
13 changes: 13 additions & 0 deletions trace/trace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package trace

import (
"log"
"time"
)

func ExecuteTime(title string, fn func()) {
start := time.Now()
fn()
elapsed := time.Since(start)
log.Printf("[%s] %s", elapsed, title)
}
21 changes: 21 additions & 0 deletions trace/trace_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package trace

import (
"time"
)

func ExampleExecuteTime() {
ExecuteTime("step 1.", func() {
time.Sleep(200 * time.Millisecond)
})

ExecuteTime("step 2.", func() {
time.Sleep(300 * time.Millisecond)
})

ExecuteTime("step 3.", func() {
time.Sleep(400 * time.Millisecond)
})

// Output:
}

0 comments on commit 10041f8

Please sign in to comment.