blob: c334efcf5bfa71b1e8ab3e88382dbcad83c32688 [file] [log] [blame]
Akash Reddy Kankanala105581b2024-09-11 05:20:38 +05301//go:build profile
Naveen Sampath04696f72022-06-13 15:19:14 +05302// +build profile
3
4/*
5* Copyright 2022-present Open Networking Foundation
6* Licensed under the Apache License, Version 2.0 (the "License");
7* you may not use this file except in compliance with the License.
8* You may obtain a copy of the License at
9*
10* http://www.apache.org/licenses/LICENSE-2.0
11*
12* Unless required by applicable law or agreed to in writing, software
13* distributed under the License is distributed on an "AS IS" BASIS,
14* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15*
16*
17 */
18
19package pprofcontroller
20
21import (
22 "net/http"
23
24 // using for init
Akash Reddy Kankanala105581b2024-09-11 05:20:38 +053025 "context"
Naveen Sampath04696f72022-06-13 15:19:14 +053026 _ "net/http/pprof"
Tinoj Joseph1d108322022-07-13 10:07:39 +053027 "voltha-go-controller/log"
Naveen Sampath04696f72022-06-13 15:19:14 +053028)
29
30var logger log.CLogger
31var ctx = context.TODO()
32
33func Init() {
Tinoj Joseph1d108322022-07-13 10:07:39 +053034 // Setup this package so that it's log level can be modified at run time
35 var err error
36 logger, err = log.RegisterPackage(log.JSON, log.ErrorLevel, log.Fields{})
37 if err != nil {
38 panic(err)
39 }
Naveen Sampath04696f72022-06-13 15:19:14 +053040 logger.Error(ctx, "Profiling is ENABLED")
41 go func() {
42 err := http.ListenAndServe("0.0.0.0:6060", nil)
43 logger.Error(ctx, "Profiling enable FAILURE", log.Opts{"Error": err})
44 }()
45}