Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
G
ghc-utils
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
7
Issues
7
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
3
Merge Requests
3
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ben Gamari
ghc-utils
Commits
c8e11dc8
Commit
c8e11dc8
authored
Jan 11, 2021
by
Ben Gamari
🐢
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sample-proc: Add ability to spawn new process
parent
768497fc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
4 deletions
+15
-4
sample_proc.py
sample_proc.py
+15
-4
No files found.
sample_proc.py
View file @
c8e11dc8
...
...
@@ -10,6 +10,7 @@ Typically used with the VmRSS and RssAnon metrics.
from
pathlib
import
Path
import
sys
import
time
import
subprocess
from
typing
import
List
,
Optional
def
read_proc
(
pid
:
int
)
->
dict
:
...
...
@@ -49,17 +50,26 @@ def plot_it(results: "numpy.ndarray",
def
main
():
import
argparse
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'-p'
,
'--pid'
,
required
=
True
,
type
=
int
,
help
=
'process id'
)
parser
.
add_argument
(
'-m'
,
'--metric'
,
action
=
'append'
,
type
=
str
,
help
=
'metric names'
)
parser
.
add_argument
(
'-s'
,
'--period'
,
type
=
float
,
help
=
'sampling period (seconds)'
,
default
=
0.1
)
parser
.
add_argument
(
'-o'
,
'--output'
,
type
=
argparse
.
FileType
(
'w'
),
help
=
'output file'
,
default
=
sys
.
stdout
)
parser
.
add_argument
(
'-P'
,
'--plot'
,
nargs
=
'?'
,
help
=
'plot it'
,
default
=
False
,
const
=
True
)
parser
.
add_argument
(
'-p'
,
'--pid'
,
type
=
int
,
help
=
'process id'
)
parser
.
add_argument
(
'cmdline'
,
type
=
str
,
nargs
=
'*'
,
help
=
'command-line to run'
)
args
=
parser
.
parse_args
()
metrics
=
args
.
metric
period
=
args
.
period
pid
=
args
.
pid
output
=
args
.
output
if
args
.
pid
is
not
None
and
args
.
cmdline
is
not
None
:
raise
ValueError
(
"Both pid and command-line given"
)
elif
args
.
pid
is
not
None
:
pid
=
args
.
pid
elif
args
.
cmdline
==
[]:
raise
ValueError
(
"Expected either pid or (non-empty) command-line"
)
else
:
subp
=
subprocess
.
Popen
(
args
.
cmdline
)
pid
=
subp
.
pid
if
args
.
plot
and
output
==
sys
.
stdout
:
print
(
"Must output to file in order to plot"
,
file
=
sys
.
stderr
)
...
...
@@ -68,13 +78,14 @@ def main():
try
:
while
True
:
t
=
time
.
time
()
result
=
read_proc
(
args
.
pid
)
result
=
read_proc
(
pid
)
values
=
[
result
[
metric
].
split
()[
0
]
for
metric
in
metrics
]
output
.
write
(
'
\t
'
.
join
([
str
(
t
)]
+
values
)
+
'
\n
'
)
output
.
flush
()
time
.
sleep
(
period
)
except
Exception
as
e
:
print
(
f"Failed with
{
e
}
"
,
file
=
sys
.
stderr
)
import
traceback
traceback
.
print_exc
(
file
=
sys
.
stderr
)
if
args
.
plot
is
not
False
:
if
args
.
plot
is
True
:
...
...
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