Skip to content

Commit

Permalink
Added --aggregate option to attach
Browse files Browse the repository at this point in the history
Added --aggregate option which allows user to request aggregated mode for in-memory aggregation.

Signed-off-by: Ivona Stojanovic <[email protected]>
  • Loading branch information
ivonastojanovic committed Sep 8, 2023
1 parent bb9c0db commit 2751eb4
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/memray/commands/attach.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import threading

import memray
from memray import FileFormat
from memray._errors import MemrayCommandError

from .live import LiveCommand
Expand Down Expand Up @@ -241,6 +242,13 @@ def prepare_parser(self, parser: argparse.ArgumentParser) -> None:
default=False,
)

parser.add_argument(
"--aggregate",
help="Write aggregated stats to the output file instead of all allocations",
action="store_true",
default=False,
)

parser.add_argument(
"--native",
help="Track native (C/C++) stack frames as well",
Expand Down Expand Up @@ -332,11 +340,19 @@ def run(self, args: argparse.Namespace, parser: argparse.ArgumentParser) -> None
live_port = _get_free_port()
destination = memray.SocketDestination(server_port=live_port)

if args.aggregate and not hasattr(args, "output"):
parser.error("Can't use aggregated mode without an output file.")

file_format = (
f"file_format={FileFormat.AGGREGATED_ALLOCATIONS}" if args.aggregate else ""
)

tracker_call = (
f"memray.Tracker(destination=memray.{destination!r},"
f" native_traces={args.native},"
f" follow_fork={args.follow_fork},"
f" trace_python_allocators={args.trace_python_allocators})"
f" trace_python_allocators={args.trace_python_allocators},"
f"{file_format})"
)

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Expand Down

0 comments on commit 2751eb4

Please sign in to comment.