Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nrm
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
16
Issues
16
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
argo
nrm
Commits
1498ec1b
Commit
1498ec1b
authored
Dec 19, 2017
by
Kamil Iskra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial support for perf wrapper
parent
f85f04bb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
144 additions
and
0 deletions
+144
-0
bin/argo-perf-wrapper
bin/argo-perf-wrapper
+144
-0
No files found.
bin/argo-perf-wrapper
0 → 100755
View file @
1498ec1b
#!/usr/bin/env python2
from
__future__
import
print_function
import
argparse
import
logging
import
zmq
import
os
import
tempfile
import
subprocess
import
uuid
logger
=
logging
.
getLogger
(
'perf-wrapper'
)
class
PerfWrapper
(
object
):
"""Implements middleware between the Linux perf and
the NRM downstream interface."""
def
__init__
(
self
):
pass
def
shutdown
(
self
):
update
=
{
'type'
:
'application'
,
'event'
:
'exit'
,
'uuid'
:
self
.
app_uuid
,
}
self
.
downstream_pub_socket
.
send_json
(
update
)
def
progress_report
(
self
,
progress
):
update
=
{
'type'
:
'application'
,
'event'
:
'progress'
,
'payload'
:
progress
,
'uuid'
:
self
.
app_uuid
,
}
self
.
downstream_pub_socket
.
send_json
(
update
)
def
setup
(
self
):
context
=
zmq
.
Context
()
self
.
downstream_pub_socket
=
context
.
socket
(
zmq
.
PUB
)
downstream_pub_param
=
"ipc:///tmp/nrm-downstream-in"
self
.
downstream_pub_socket
.
connect
(
downstream_pub_param
)
logger
.
info
(
"downstream pub socket connected to: %s"
,
downstream_pub_param
)
# retrieve our container uuid
self
.
container_uuid
=
os
.
environ
.
get
(
'ARGO_CONTAINER_UUID'
)
if
self
.
container_uuid
is
None
:
logger
.
error
(
"missing container uuid"
)
exit
(
1
)
self
.
app_uuid
=
str
(
uuid
.
uuid4
())
logger
.
info
(
"client uuid: %r"
,
self
.
app_uuid
)
# send an hello to the demon
update
=
{
'type'
:
'application'
,
'event'
:
'start'
,
'container'
:
self
.
container_uuid
,
'uuid'
:
self
.
app_uuid
,
'progress'
:
True
,
'threads'
:
{
'min'
:
1
,
'cur'
:
1
,
'max'
:
1
},
}
self
.
downstream_pub_socket
.
send_json
(
update
)
def
main
(
self
):
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"-v"
,
"--verbose"
,
help
=
"verbose logging information"
,
action
=
'store_true'
)
parser
.
add_argument
(
"-f"
,
"--frequency"
,
help
=
"sampling frequency in ms"
,
type
=
int
,
default
=
1000
)
parser
.
add_argument
(
"cmd"
,
help
=
"command and arguments"
,
nargs
=
argparse
.
REMAINDER
)
args
=
parser
.
parse_args
()
if
args
.
verbose
:
logger
.
setLevel
(
logging
.
DEBUG
)
logger
.
info
(
"cmd: %r"
,
args
.
cmd
)
self
.
setup
()
# create a named pipe between us and the to-be-launched perf
# There is no mkstemp for FIFOs but we can securely create a temporary
# directory and then create a FIFO inside of it.
tmpdir
=
tempfile
.
mkdtemp
()
fifoname
=
os
.
path
.
join
(
tmpdir
,
'perf-fifo'
)
logger
.
info
(
"fifoname: %r"
,
fifoname
)
os
.
mkfifo
(
fifoname
,
0600
)
argv
=
[
'perf'
,
'stat'
,
'-e'
,
'instructions'
,
'-x'
,
','
,
'-I'
,
str
(
args
.
frequency
),
'-o'
,
fifoname
,
'--'
]
argv
.
extend
(
args
.
cmd
)
logger
.
info
(
"argv: %r"
,
argv
)
p
=
subprocess
.
Popen
(
argv
,
close_fds
=
True
)
# This blocks until the other end opens as well so we need to invoke
# it after Popen.
# FIXME: will deadlock if Popen fails (say, no perf).
fifo
=
open
(
fifoname
,
'r'
)
last_time
=
0.0
# "for line in fifo" idiom didn't work for me here -- Python was
# buffering the output internally until perf was finished.
while
True
:
line
=
fifo
.
readline
();
if
not
line
:
break
line
=
line
.
strip
();
if
len
(
line
)
==
0
or
line
[
0
]
==
'#'
:
continue
tokens
=
line
.
split
(
','
)
logger
.
info
(
"tokens: %r"
,
tokens
)
time
=
float
(
tokens
[
0
])
if
tokens
[
1
]
==
'<not counted>'
:
instructions
=
0
else
:
instructions
=
int
(
tokens
[
1
])
ips
=
int
(
instructions
/
(
time
-
last_time
))
logger
.
info
(
"instructions per second: %r"
,
ips
)
self
.
progress_report
(
ips
)
last_time
=
time
# The child should be dead by now so this should terminate immediately.
p
.
wait
()
self
.
shutdown
()
fifo
.
close
()
os
.
remove
(
fifoname
)
os
.
rmdir
(
tmpdir
)
if
__name__
==
"__main__"
:
logging
.
basicConfig
(
level
=
logging
.
WARNING
)
wrapper
=
PerfWrapper
()
wrapper
.
main
()
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