generated from networkservicemesh/cmd-template
-
Notifications
You must be signed in to change notification settings - Fork 22
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 <[email protected]>
- Loading branch information
Vitaliy Guschin
committed
Jun 26, 2024
1 parent
41f4bc6
commit c1f0940
Showing
7 changed files
with
82 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ ENV GO111MODULE=on | |
ENV CGO_ENABLED=0 | ||
ENV GOBIN=/bin | ||
ARG BUILDARCH=amd64 | ||
ARG ENABLE_PROFILER=false | ||
RUN rm -r /etc/vpp | ||
RUN go install github.com/go-delve/delve/cmd/[email protected] | ||
RUN go install github.com/grpc-ecosystem/[email protected] | ||
|
@@ -23,7 +24,11 @@ COPY ./internal/afxdp/afxdp.c ./internal/afxdp/ | |
RUN clang -O3 -g -Wextra -Wall -target bpf -I/usr/include/$(uname -m)-linux-gnu -I/usr/include -c -o /bin/afxdp.o ./internal/afxdp/afxdp.c | ||
RUN go build ./internal/imports | ||
COPY . . | ||
RUN go build -o /bin/forwarder . | ||
RUN if [ "$ENABLE_PROFILER" = "true" ]; then \ | ||
go build -tags profiler -o /bin/forwarder . ; \ | ||
else \ | ||
go build -o /bin/forwarder . ; \ | ||
fi | ||
|
||
FROM build as test | ||
CMD go test -test.v ./... | ||
|
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,23 @@ | ||
// Copyright (c) 2024 Pragmagic Inc. and/or its affiliates. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//go:build !profiler | ||
|
||
package main | ||
|
||
import "context" | ||
|
||
func startProfiler(_ context.Context, _ 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,47 @@ | ||
// Copyright (c) 2024 Pragmagic Inc. and/or its affiliates. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
//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()) | ||
} | ||
}() | ||
} |