2019-06-20 02:58:25 +03:00
|
|
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
2018-11-01 18:06:07 +03:00
|
|
|
#
|
2019-06-20 02:58:25 +03:00
|
|
|
# This software may be used and distributed according to the terms of the
|
|
|
|
# GNU General Public License version 2.
|
2018-11-01 18:06:07 +03:00
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
|
|
|
|
2020-11-19 23:57:23 +03:00
|
|
|
import argparse
|
|
|
|
import os
|
2021-02-25 22:29:19 +03:00
|
|
|
import pathlib
|
|
|
|
import sys
|
2020-11-19 23:57:23 +03:00
|
|
|
|
2018-11-01 18:06:07 +03:00
|
|
|
from . import subcmd as subcmd_mod
|
2020-11-19 23:57:23 +03:00
|
|
|
from .cmd_util import require_checkout
|
|
|
|
from .subcmd import Subcmd
|
2018-11-01 18:06:07 +03:00
|
|
|
|
|
|
|
|
|
|
|
trace_cmd = subcmd_mod.Decorator()
|
2020-11-19 23:57:23 +03:00
|
|
|
|
|
|
|
|
2021-02-25 22:29:19 +03:00
|
|
|
def get_trace_stream_command() -> pathlib.Path:
|
|
|
|
try:
|
|
|
|
return pathlib.Path(os.environ["EDENFS_TRACE_STREAM"])
|
|
|
|
except KeyError:
|
|
|
|
return pathlib.Path("/usr/local/libexec/eden/eden_trace_stream")
|
|
|
|
|
|
|
|
|
2020-11-19 23:57:23 +03:00
|
|
|
@trace_cmd("hg", "Trace hg object fetches")
|
|
|
|
class TraceHgCommand(Subcmd):
|
|
|
|
def setup_parser(self, parser: argparse.ArgumentParser) -> None:
|
|
|
|
parser.add_argument(
|
|
|
|
"checkout", default=None, nargs="?", help="Path to the checkout"
|
|
|
|
)
|
|
|
|
|
|
|
|
async def run(self, args: argparse.Namespace) -> int:
|
2021-02-25 22:29:19 +03:00
|
|
|
if sys.platform == "win32":
|
|
|
|
print("Not yet supported on Windows", file=sys.stderr)
|
|
|
|
return 1
|
2020-11-19 23:57:23 +03:00
|
|
|
instance, checkout, _rel_path = require_checkout(args, args.checkout)
|
|
|
|
|
2021-02-25 22:29:19 +03:00
|
|
|
trace_stream_command = get_trace_stream_command()
|
|
|
|
# TODO: Use subprocess.call on Windows.
|
|
|
|
os.execl(
|
|
|
|
trace_stream_command,
|
|
|
|
os.fsencode(trace_stream_command),
|
|
|
|
b"--mountRoot",
|
|
|
|
os.fsencode(checkout.path),
|
|
|
|
b"--trace=hg",
|
|
|
|
)
|
2021-06-17 22:06:34 +03:00
|
|
|
|
|
|
|
|
|
|
|
@trace_cmd("fs", "Monitor filesystem requests.")
|
|
|
|
class TraceFsCommand(Subcmd):
|
|
|
|
def setup_parser(self, parser: argparse.ArgumentParser) -> None:
|
|
|
|
parser.add_argument(
|
|
|
|
"checkout", default=None, nargs="?", help="Path to the checkout"
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--reads",
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="Limit trace to read operations",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--writes",
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="Limit trace to write operations",
|
|
|
|
)
|
|
|
|
|
|
|
|
async def run(self, args: argparse.Namespace) -> int:
|
|
|
|
if sys.platform == "win32":
|
|
|
|
print("Not yet supported on Windows", file=sys.stderr)
|
|
|
|
return 1
|
|
|
|
instance, checkout, _rel_path = require_checkout(args, args.checkout)
|
|
|
|
trace_stream_command = get_trace_stream_command()
|
|
|
|
# TODO: Use subprocess.call on Windows.
|
|
|
|
os.execl(
|
|
|
|
trace_stream_command,
|
|
|
|
os.fsencode(trace_stream_command),
|
|
|
|
b"--mountRoot",
|
|
|
|
os.fsencode(checkout.path),
|
|
|
|
b"--trace=fs",
|
|
|
|
f"--reads={'true' if args.reads else 'false'}".encode(),
|
|
|
|
f"--writes={'true' if args.writes else 'false'}".encode(),
|
|
|
|
)
|