Skip to content

Commit

Permalink
Merge pull request #59 from P403n1x87/feat/handle-interval-units
Browse files Browse the repository at this point in the history
feat: handle interval units
  • Loading branch information
P403n1x87 authored Nov 12, 2023
2 parents c56dffe + 5e4f176 commit c3c522c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
21 changes: 19 additions & 2 deletions echion/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ def attach(args: argparse.Namespace) -> None:
pipe_name.unlink()


def microseconds(v: str) -> int:
try:
if v.endswith("ms"):
return int(v[:-2]) * 1000
if v.endswith("s"):
return int(v[:-1]) * 1000000
return int(v)
except Exception as e:
raise ValueError("Invalid interval: %s" % v) from e


def main() -> None:
parser = argparse.ArgumentParser(
description="In-process CPython frame stack sampler",
Expand All @@ -100,7 +111,7 @@ def main() -> None:
"--interval",
help="sampling interval in microseconds",
default=1000,
type=int,
type=microseconds,
)
parser.add_argument(
"-c",
Expand Down Expand Up @@ -163,7 +174,13 @@ def main() -> None:
action="version",
version="%(prog)s " + __version__,
)
args = parser.parse_args()

try:
args = parser.parse_args()
except Exception as e:
print("echion: %s" % e)
parser.print_usage()
sys.exit(1)

# TODO: Validate arguments

Expand Down
2 changes: 1 addition & 1 deletion tests/test_echion.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def test_echion():
result, data = run_target("target")
result, _ = run_target("target", "-i", "10ms")
assert result.returncode == 0, result.stderr


Expand Down

0 comments on commit c3c522c

Please sign in to comment.