()
| 43 | |
| 44 | |
| 45 | def main(): |
| 46 | parser = argparse.ArgumentParser() |
| 47 | parser.add_argument("binary") |
| 48 | parser.add_argument("corpus") |
| 49 | parser.add_argument("requests", type=int) |
| 50 | parser.add_argument("--stderr", help="file for the server's stderr; never discard it") |
| 51 | parser.add_argument("--tool", default="search_graph", |
| 52 | help="tool to repeat; varying it isolates which path leaks") |
| 53 | parser.add_argument("--idle-seconds", type=float, default=0.0, |
| 54 | help="pause midway; separates per-request growth from per-second growth") |
| 55 | parser.add_argument("--skip-index", action="store_true", |
| 56 | help="omit the initial index, to separate store setup from the loop") |
| 57 | args = parser.parse_args() |
| 58 | |
| 59 | proc = subprocess.Popen( |
| 60 | [args.binary], |
| 61 | stdin=subprocess.PIPE, |
| 62 | stdout=subprocess.PIPE, |
| 63 | # Never DEVNULL: when the server refuses to start, its stderr is the |
| 64 | # only thing that says why. |
| 65 | stderr=open(args.stderr, "w") if args.stderr else None, |
| 66 | text=True, |
| 67 | bufsize=1, |
| 68 | ) |
| 69 | served = 0 |
| 70 | failures = 0 |
| 71 | try: |
| 72 | rpc(proc, {"jsonrpc": "2.0", "id": 0, "method": "initialize", |
| 73 | "params": {"protocolVersion": "2024-11-05", "capabilities": {}, |
| 74 | "clientInfo": {"name": "memlab", "version": "1"}}}, |
| 75 | "initialize") |
| 76 | project = None |
| 77 | if not args.skip_index: |
| 78 | indexed = rpc(proc, {"jsonrpc": "2.0", "id": 1, "method": "tools/call", |
| 79 | "params": {"name": "index_repository", |
| 80 | "arguments": {"repo_path": args.corpus}}}, |
| 81 | "index_repository") |
| 82 | if tool_failed(indexed): |
| 83 | print(f"index failed: {indexed.get('error') or indexed.get('result')}", file=sys.stderr) |
| 84 | return 3 |
| 85 | project = (indexed.get("result", {}).get("structuredContent") or {}).get("project") |
| 86 | |
| 87 | halfway = 2 + args.requests // 2 |
| 88 | for i in range(2, args.requests + 2): |
| 89 | if args.idle_seconds > 0 and i == halfway: |
| 90 | # Nothing is requested during this gap. Any commit growth across |
| 91 | # it belongs to a background thread, not the request path. |
| 92 | print(f"idle-start id={i}", flush=True) |
| 93 | time.sleep(args.idle_seconds) |
| 94 | print(f"idle-end id={i}", flush=True) |
| 95 | arguments = {"search_graph": {"name_pattern": ".*Widget.*", "limit": 10}, |
| 96 | "list_projects": {}, |
| 97 | "get_graph_schema": {}, |
| 98 | "search_code": {"pattern": "Widget"}}.get(args.tool, {}) |
| 99 | if project and args.tool != "list_projects": |
| 100 | arguments = dict(arguments, project=project) |
| 101 | reply = rpc(proc, {"jsonrpc": "2.0", "id": i, "method": "tools/call", |
| 102 | "params": {"name": args.tool, "arguments": arguments}}, |
no test coverage detected