https://github.com/rtntubmt97/profiler
https://github.com/rtntubmt97/profiler
golang golang-library golang-package profiler realtime request-rate
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/rtntubmt97/profiler
- Owner: rtntubmt97
- License: mit
- Created: 2020-06-30T02:38:58.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-01T09:36:31.000Z (almost 6 years ago)
- Last Synced: 2024-06-20T16:46:15.624Z (almost 2 years ago)
- Topics: golang, golang-library, golang-package, profiler, realtime, request-rate
- Language: Go
- Homepage:
- Size: 56.6 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
required go 1.14 or above
example
```golang
package main
import (
"fmt"
"html"
"math/rand"
"net/http"
"time"
app "github.com/rtntubmt97/profiler/pkg/applications"
k "github.com/rtntubmt97/profiler/pkg/kernel"
)
// this default profiler will run on localhost:9081
var profiler k.Profiler = app.HttpPageProfiler()
func main() {
http.HandleFunc("/foo", FooHandler)
http.ListenAndServe(":9080", nil)
}
func FooHandler(rsp http.ResponseWriter, request *http.Request) {
mark := k.CreateMark()
defer profiler.Record("FooHandler", mark)
// doing something in handler
processTimeMillis := rand.Int() % 100
time.Sleep(time.Microsecond * time.Duration(processTimeMillis))
fmt.Fprintf(rsp, "Hello, %q", html.EscapeString(request.URL.Path))
// process something in db
n := rand.Int() % 5
for i := 0; i < n; i++ {
dbProcess()
}
}
func dbProcess() {
mark := k.CreateMark()
defer profiler.Record("dbProcess", mark)
processTimeMillis := rand.Int() % 100
time.Sleep(time.Microsecond * time.Duration(processTimeMillis))
}
```