Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display cpu+mem usage #149

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions molotov/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ async def scenario_one(session):
async with session.get("http://example.com") as resp:
if random.randint(1, 100) == 5:
raise AssertionError("Failed")
from base64 import b64encode
from os import urandom

for i in range(1000):
random_bytes = urandom(64)
token = b64encode(random_bytes).decode("utf-8")

assert resp.status == 200
2 changes: 1 addition & 1 deletion molotov/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _parser():
"--console-update",
help="Delay between each console update",
type=float,
default=0.2,
default=0.5,
)

parser.add_argument(
Expand Down
2 changes: 1 addition & 1 deletion molotov/ui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
class MolotovApp:
def __init__(
self,
refresh_interval=0.3,
refresh_interval=0.5,
max_lines=25,
simple_console=False,
single_process=True,
Expand Down
17 changes: 17 additions & 0 deletions molotov/ui/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from datetime import datetime

import humanize
import psutil
from prompt_toolkit import HTML
from prompt_toolkit.formatted_text import to_formatted_text
from prompt_toolkit.key_binding import KeyBindings
Expand Down Expand Up @@ -133,19 +134,35 @@ def __init__(self, max_lines=25):
super().__init__(max_lines)
self._status = {}
self._started = datetime.now()
self._p = psutil.Process()

def update(self, results):
self._status.update(results)

def get_resource_usage(self):
rss = self._p.memory_info().rss
cpu_percent = self._p.cpu_percent()

for child in self._p.children(recursive=True):
rss += child.memory_info().rss
cpu_percent += child.cpu_percent()

if cpu_percent > 0:
cpu_percent = cpu_percent / psutil.cpu_count()
return {"rss": rss, "cpu_percent": cpu_percent}

def formatted(self):
delta = datetime.now() - self._started
resources = self.get_resource_usage()

return to_formatted_text(
HTML(
f'<style fg="green" bg="#cecece">SUCCESS: {self._status.get("OK", 0)} </style>'
f'<style fg="red" bg="#cecece"> FAILED: {self._status.get("FAILED", 0)} </style>'
f' WORKERS: {self._status.get("WORKER", 0)}'
f' PROCESSES: {self._status.get("PROCESS", 0)} '
f'<style fg="blue" bg="#cecece"> ELAPSED: {humanize.precisedelta(delta)}</style>'
f' CPU% {resources["cpu_percent"]} MEM {humanize.naturalsize(resources["rss"])}'
)
)

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ aiodogstatsd==0.16.0
multiprocess==0.70.13
prompt_toolkit==3.0.31
humanize==4.4.0
psutil==5.9.3
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"multiprocess",
"humanize",
"prompt_toolkit",
"psutil"
]

description = ""
Expand Down