-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an image with profiling enabled.
Signed-off-by: Vitaliy Guschin <vitaliy.guschin@spirent.com>
- Loading branch information
Vitaliy Guschin
committed
Jun 26, 2024
1 parent
e081e3d
commit f90edad
Showing
8 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//go:build !profiler | ||
|
||
package main | ||
|
||
import "context" | ||
|
||
func startProfiler(ctx context.Context, profilerHTTPPort uint16) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//go:build profiler | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net/http" | ||
_ "net/http/pprof" // #nosec | ||
"time" | ||
|
||
"github.com/networkservicemesh/sdk/pkg/tools/log" | ||
) | ||
|
||
func startProfiler(ctx context.Context, profilerHTTPPort uint16) { | ||
go func() { | ||
log.FromContext(ctx).Infof("Profiler is enabled. Starting HTTP server on %d", profilerHTTPPort) | ||
|
||
address := fmt.Sprintf("localhost:%d", profilerHTTPPort) | ||
|
||
server := &http.Server{ | ||
Addr: address, | ||
ReadTimeout: 10 * time.Second, | ||
WriteTimeout: 10 * time.Second, | ||
} | ||
|
||
if err := server.ListenAndServe(); err != nil { | ||
log.FromContext(ctx).Errorf("Failed to start profiler: %s", err.Error()) | ||
} | ||
}() | ||
} |