Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sidecar
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
sidecar
Commits
51b6b278
Commit
51b6b278
authored
Sep 29, 2021
by
suyanlong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add runtimePProf function
parent
be162b7f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
2 deletions
+37
-2
start.go
cmd/sidecar/start.go
+37
-2
No files found.
cmd/sidecar/start.go
View file @
51b6b278
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"os"
"os"
"os/signal"
"os/signal"
"path/filepath"
"path/filepath"
"runtime/pprof"
"sync"
"sync"
"syscall"
"syscall"
"time"
"time"
...
@@ -18,6 +19,7 @@ import (
...
@@ -18,6 +19,7 @@ import (
"github.com/link33/sidecar/internal/loggers"
"github.com/link33/sidecar/internal/loggers"
"github.com/link33/sidecar/internal/repo"
"github.com/link33/sidecar/internal/repo"
"github.com/link33/sidecar/pkg/log"
"github.com/link33/sidecar/pkg/log"
"github.com/link33/sidecar/tool"
)
)
var
startCMD
=
cli
.
Command
{
var
startCMD
=
cli
.
Command
{
...
@@ -63,7 +65,8 @@ func start(ctx *cli.Context) error {
...
@@ -63,7 +65,8 @@ func start(ctx *cli.Context) error {
return
err
return
err
}
}
runPProf
(
config
.
Port
.
PProf
)
httpPProf
(
config
.
Port
.
PProf
)
runtimePProf
()
var
wg
sync
.
WaitGroup
var
wg
sync
.
WaitGroup
wg
.
Add
(
1
)
wg
.
Add
(
1
)
...
@@ -96,7 +99,7 @@ func handleShutdown(sidecar internal.Launcher, wg *sync.WaitGroup) {
...
@@ -96,7 +99,7 @@ func handleShutdown(sidecar internal.Launcher, wg *sync.WaitGroup) {
}()
}()
}
}
func
run
PProf
(
port
int64
)
{
func
http
PProf
(
port
int64
)
{
go
func
()
{
go
func
()
{
addr
:=
fmt
.
Sprintf
(
"localhost:%d"
,
port
)
addr
:=
fmt
.
Sprintf
(
"localhost:%d"
,
port
)
fmt
.
Printf
(
"Pprof on localhost:%d
\n\n
"
,
port
)
fmt
.
Printf
(
"Pprof on localhost:%d
\n\n
"
,
port
)
...
@@ -108,6 +111,38 @@ func runPProf(port int64) {
...
@@ -108,6 +111,38 @@ func runPProf(port int64) {
}()
}()
}
}
// runtimePProf will record the cpu or memory profiles every 5 second.
func
runtimePProf
()
{
tick
:=
time
.
NewTicker
(
time
.
Second
*
5
)
rootPath
:=
filepath
.
Join
(
repo
.
DefaultPathRoot
,
"/pprof/"
)
exist
:=
tool
.
Exist
(
rootPath
)
if
!
exist
{
err
:=
os
.
Mkdir
(
rootPath
,
os
.
ModePerm
)
if
err
!=
nil
{
fmt
.
Printf
(
"----- runtimePProf start failed, err: %s -----
\n
"
,
err
.
Error
())
return
}
}
go
func
()
{
for
{
select
{
case
<-
tick
.
C
:
pprof
.
StopCPUProfile
()
subCpuPath
:=
fmt
.
Sprint
(
"cpu-"
,
time
.
Now
()
.
Format
(
"20060102-15:04:05"
))
cpuPath
:=
filepath
.
Join
(
rootPath
,
subCpuPath
)
cpuFile
,
_
:=
os
.
Create
(
cpuPath
)
_
=
pprof
.
StartCPUProfile
(
cpuFile
)
subMemPath
:=
fmt
.
Sprint
(
"mem-"
,
time
.
Now
()
.
Format
(
"20060102-15:04:05"
))
memPath
:=
filepath
.
Join
(
rootPath
,
subMemPath
)
memFile
,
_
:=
os
.
Create
(
memPath
)
_
=
pprof
.
WriteHeapProfile
(
memFile
)
_
=
memFile
.
Close
()
}
}
}()
}
func
checkPlugin
(
pluginName
string
)
error
{
func
checkPlugin
(
pluginName
string
)
error
{
// check if plugin exists
// check if plugin exists
pluginRoot
,
err
:=
repo
.
PluginPath
()
pluginRoot
,
err
:=
repo
.
PluginPath
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment