[VOL-3090] Adding profiler to ofagent-go
Change-Id: I846091a528a54a91af933d3fd6f888fb1d96295f
diff --git a/Makefile b/Makefile
index 5a83a0f..2e23c73 100644
--- a/Makefile
+++ b/Makefile
@@ -104,10 +104,16 @@
## Docker targets
docker-build: local-protos local-voltha local-lib-go
- docker build $(DOCKER_BUILD_ARGS) -t ${ADAPTER_IMAGENAME}:${DOCKER_TAG} -t ${ADAPTER_IMAGENAME}:latest -f docker/Dockerfile.ofagent-go .
+ docker build $(DOCKER_BUILD_ARGS) -t ${ADAPTER_IMAGENAME}:${DOCKER_TAG} -f docker/Dockerfile.ofagent-go .
+ifdef BUILD_PROFILED
+ docker build $(DOCKER_BUILD_ARGS) --build-arg EXTRA_GO_BUILD_TAGS="-tags profile" -t ${ADAPTER_IMAGENAME}:${DOCKER_TAG}-profile -f docker/Dockerfile.ofagent-go .
+endif
docker-push:
docker push ${ADAPTER_IMAGENAME}:${DOCKER_TAG}
+ifdef BUILD_PROFILED
+ docker push ${ADAPTER_IMAGENAME}:${DOCKER_TAG}-profile
+endif
## lint and unit tests
diff --git a/cmd/ofagent/main.go b/cmd/ofagent/main.go
index 987a8e6..d32fecc 100644
--- a/cmd/ofagent/main.go
+++ b/cmd/ofagent/main.go
@@ -104,6 +104,9 @@
log.SetAllLogLevel(logLevel)
+ // depending on the build tags start the profiler
+ realMain()
+
defer func() {
err := log.CleanUp()
if err != nil {
diff --git a/cmd/ofagent/profile.go b/cmd/ofagent/profile.go
new file mode 100644
index 0000000..6ac7528
--- /dev/null
+++ b/cmd/ofagent/profile.go
@@ -0,0 +1,31 @@
+// +build profile
+
+/*
+ * Copyright 2018-present Open Networking Foundation
+
+ * 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.
+ */
+
+package main
+
+import (
+ "net/http"
+ _ "net/http/pprof"
+)
+
+func realMain() {
+ go func() {
+ logger.Fatal(http.ListenAndServe("0.0.0.0:6060", nil))
+ }()
+
+}
\ No newline at end of file
diff --git a/cmd/ofagent/release.go b/cmd/ofagent/release.go
new file mode 100644
index 0000000..67f8187
--- /dev/null
+++ b/cmd/ofagent/release.go
@@ -0,0 +1,23 @@
+// +build !profile
+
+/*
+ * Copyright 2018-present Open Networking Foundation
+
+ * 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.
+ */
+
+package main
+
+func realMain() {
+ logger.Infoln("NOT PROFILING")
+}
diff --git a/docker/Dockerfile.ofagent-go b/docker/Dockerfile.ofagent-go
index b99dcbe..dff2d99 100644
--- a/docker/Dockerfile.ofagent-go
+++ b/docker/Dockerfile.ofagent-go
@@ -27,9 +27,11 @@
ARG org_opencord_vcs_commit_date=unknown
ARG org_opencord_vcs_dirty=unknown
+ARG EXTRA_GO_BUILD_TAGS=""
+
# Build ofagent-go
SHELL ["/bin/ash", "-o", "pipefail", "-c"]
-RUN go build -mod=vendor -o /build/ofagent \
+RUN go build $EXTRA_GO_BUILD_TAGS -mod=vendor -o /build/ofagent \
-ldflags \
"-X github.com/opencord/voltha-lib-go/v2/pkg/version.version=$org_label_schema_version \
-X github.com/opencord/voltha-lib-go/v2/pkg/version.vcsRef=$org_label_schema_vcs_ref \