mirror of
https://github.com/facebook/sapling.git
synced 2024-10-05 14:28:17 +03:00
4f43f8bb8d
Summary: Previously `eden prefetch` had two subcommands `record-profile` and `finish-profile`, but then when we only want to use `eden prefetch PATTERN`, an error shows up saying that the COMMAND argument is missed. Since `eden prefetch` has many of its own arguments, and we don't want to use it with `record-profile` and `finish-profile` all the time, we remove those subcommands and create a new `eden debug prefetch_profile` command to get prefetch profiles. Reviewed By: fanzeyi Differential Revision: D22959981 fbshipit-source-id: 21b278555fcb56580a62f66a7384b1cff54ba398
66 lines
2.1 KiB
Python
66 lines
2.1 KiB
Python
# Copyright (c) Facebook, Inc. and its affiliates.
|
|
#
|
|
# This software may be used and distributed according to the terms of the
|
|
# GNU General Public License version 2.
|
|
|
|
import argparse
|
|
import os
|
|
|
|
from . import subcmd as subcmd_mod
|
|
from .cmd_util import get_eden_instance
|
|
from .subcmd import Subcmd
|
|
|
|
|
|
prefetch_profile_cmd = subcmd_mod.Decorator()
|
|
|
|
|
|
@prefetch_profile_cmd("record", "Start recording fetched file paths.")
|
|
class RecordProfileCmd(Subcmd):
|
|
def run(self, args: argparse.Namespace) -> int:
|
|
instance = get_eden_instance(args)
|
|
with instance.get_thrift_client() as client:
|
|
client.startRecordingBackingStoreFetch()
|
|
return 0
|
|
|
|
|
|
@prefetch_profile_cmd(
|
|
"finish",
|
|
"Stop recording fetched file paths and save previously"
|
|
" collected fetched file paths in the output prefetch profile",
|
|
)
|
|
class FinishProfileCmd(Subcmd):
|
|
def setup_parser(self, parser: argparse.ArgumentParser) -> None:
|
|
parser.add_argument(
|
|
"--output-path",
|
|
nargs="?",
|
|
help="The output path to store the prefetch profile",
|
|
)
|
|
|
|
def run(self, args: argparse.Namespace) -> int:
|
|
instance = get_eden_instance(args)
|
|
with instance.get_thrift_client() as client:
|
|
files = client.stopRecordingBackingStoreFetch()
|
|
output_path = (
|
|
args.output_path
|
|
if args.output_path
|
|
else os.path.abspath("prefetch_profile.txt")
|
|
)
|
|
with open(output_path, "w") as f:
|
|
f.write("HgQueuedBackingStore:\n")
|
|
for path in files.fetchedFilePaths["HgQueuedBackingStore"]:
|
|
f.write(os.fsdecode(path))
|
|
f.write("\n")
|
|
f.write("\n")
|
|
return 0
|
|
|
|
|
|
class PrefetchProfileCmd(Subcmd):
|
|
NAME = "prefetch_profile"
|
|
HELP = "Collect backing store fetched file paths to obtain a prefetch profile"
|
|
|
|
def setup_parser(self, parser: argparse.ArgumentParser) -> None:
|
|
self.add_subcommands(parser, prefetch_profile_cmd.commands)
|
|
|
|
def run(self, args: argparse.Namespace) -> int:
|
|
return 0
|