-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperf-http.sh
40 lines (32 loc) · 1.19 KB
/
perf-http.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
seconds="${1:-15}"
pgrep="${2:-^mongod$}"
perf record -o - --call-graph fp -F99 -e cpu-cycles -p $(pgrep -d, "$pgrep" ) sleep "$seconds" |
perf script -F +pid | python3 -c "
# Start a simple Python HTTP server to serve the file
import http.server
import socketserver
PORT = 80
class PerfHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
# Serve the perf output
if self.path == '/':
try:
with open('/dev/stdin', 'rb') as f:
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(f.read())
except FileNotFoundError:
self.send_response(500)
self.end_headers()
self.wfile.write(b'Error: No perf output found')
else:
self.send_response(404)
self.end_headers()
self.wfile.write(b'Not Found')
# Run the server on port 8080
with socketserver.TCPServer((\"\", PORT), PerfHandler) as httpd:
print(f\"Serving perf data on port {PORT}\")
httpd.handle_request() # Only serve one request, then exit
"