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

"-n option" #64

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ nosetests.xml
# PyCharm
.idea

# Virtual Environment
.venv

pylokit/tests/.~*
21 changes: 21 additions & 0 deletions uwsgitop
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import sys
import traceback
from collections import defaultdict
import errno
import itertools


def human_size(n):
Expand Down Expand Up @@ -71,10 +72,19 @@ def merge_worker_with_cores(workers, rps_per_worker, cores, rps_per_core):
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--frequency', type=int, default=1, help='Refresh frequency in seconds')
parser.add_argument('-n', type=int, default=None, help='Number of cycles until uwsgitop quits')
parser.add_argument('address', help='uWSGI stats socket or address')

return parser.parse_args()


def capture_curses_content(screen):
rows, cols = screen.getmaxyx()
binary_lines = (screen.instr(i, 0) for i in range(rows))
text_lines = (bl.decode("utf-8", errors="ignore") for bl in binary_lines)
return "".join(tl for tl in text_lines if tl.strip())


def main():

need_reset = True
Expand Down Expand Up @@ -146,8 +156,19 @@ def main():
async_mode = 0
fast_screen = 0

# number of cycles to display
max_cycle = args.n
cycle = itertools.count()

while True:

# break out of loop if number of cycles reached
if max_cycle and max_cycle == next(cycle):
content = capture_curses_content(screen)
game_over()
print(content)
break

if fast_screen == 1:
screen.timeout(100)
else:
Expand Down