MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / main

Function main

misc/python/materialize/cli/mz_workload_capture.py:199–640  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

197
198
199def main() -> int:
200 parser = argparse.ArgumentParser(
201 prog="mz-workload-capture",
202 formatter_class=argparse.RawDescriptionHelpFormatter,
203 description="Records a workload profile from a running Materialize instance (without actual data)",
204 )
205
206 parser.add_argument("mz_url", type=str)
207 # Default cluster to use
208 parser.add_argument("--cluster", type=str, default="quickstart")
209 parser.add_argument(
210 "-o",
211 "--output",
212 type=str,
213 help="Path to write the workload.yml, - for stdout",
214 default=f"workload_{datetime.now(timezone.utc).strftime('%Y-%m-%dT%H-%M-%S')}.yml",
215 )
216 parser.add_argument(
217 "--time",
218 type=int,
219 help="How long of a query/data ingestion history to capture, in seconds",
220 default=360,
221 )
222 # Currently too slow to always enable, not used yet.
223 parser.add_argument("--avg-column-size", action=argparse.BooleanOptionalAction)
224 parser.add_argument("-v", "--verbose", action=argparse.BooleanOptionalAction)
225
226 args = parser.parse_args()
227
228 global VERBOSE
229 VERBOSE = args.verbose
230
231 conn = psycopg.connect(args.mz_url)
232 conn.autocommit = True
233 with conn.cursor() as cur:
234 cur.execute(SQL("SET CLUSTER = {}").format(Identifier(args.cluster)))
235
236 workload = {
237 "databases": {},
238 "clusters": {},
239 "queries": [],
240 "mz_workload_version": "1.0.0",
241 }
242
243 with timed("Fetching clusters"):
244 for cluster, managed in query(
245 conn, "SELECT name, managed FROM mz_clusters WHERE id LIKE 'u%'"
246 ):
247 workload["clusters"][cluster] = {"managed": managed}
248 if managed:
249 workload["clusters"][cluster]["create_sql"] = query(
250 conn,
251 SQL("SELECT create_sql FROM (SHOW CREATE CLUSTER {})").format(
252 Identifier(cluster)
253 ),
254 )[0][0]
255
256 with timed("Fetching databases"):

Callers 1

Calls 15

timedFunction · 0.85
attach_avg_column_sizesFunction · 0.85
attach_source_statisticsFunction · 0.85
cursorMethod · 0.80
queryFunction · 0.70
nowMethod · 0.45
connectMethod · 0.45
executeMethod · 0.45
formatMethod · 0.45
appendMethod · 0.45
splitMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected