Skip to content

Commit

Permalink
[feature] #19 增加pprof
Browse files Browse the repository at this point in the history
  • Loading branch information
runs committed Feb 25, 2023
1 parent 6cd959b commit ba0680e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"go.uber.org/zap"

"git.vtb.link/eoefans/internal/app"
"git.vtb.link/eoefans/internal/app/api/service"
Expand All @@ -24,7 +25,12 @@ func newAPI() fx.Option {
)
}

func lc(lifecycle fx.Lifecycle, ginServer *httpserver.Server, randPicsCache *service.RandomPicsCache) {
func lc(
lifecycle fx.Lifecycle,
ginServer *httpserver.Server,
randPicsCache *service.RandomPicsCache,
logger *zap.Logger,
) {
lifecycle.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
return ginServer.Start()
Expand All @@ -33,6 +39,11 @@ func lc(lifecycle fx.Lifecycle, ginServer *httpserver.Server, randPicsCache *ser
return ginServer.Stop()
},
})
lifecycle.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
return httpserver.RunPprofHttpServer(logger)
},
})
lifecycle.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
return randPicsCache.Run()
Expand Down
18 changes: 18 additions & 0 deletions internal/pkg/httpserver/pprof.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package httpserver

import (
"go.uber.org/zap"
"net/http"
_ "net/http/pprof"
)

func RunPprofHttpServer(logger *zap.Logger) error {
go func() {
err := http.ListenAndServe(":9651", nil)
if err != nil {
logger.Error("RunPprofHttpServer failed: ", zap.Error(err))
}
}()

return nil
}

0 comments on commit ba0680e

Please sign in to comment.