-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmain.py
More file actions
89 lines (72 loc) · 2.26 KB
/
Copy pathmain.py
File metadata and controls
89 lines (72 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
from pathlib import Path
import quent_readme as quent
def main() -> None:
output_dir = Path("./events")
context = quent.Context("ndjson", str(output_dir))
# The context generates its own id and writes events under
# `output_dir/<id>/`. Reuse it as the root resource group id.
cluster_id = context.id
cluster = context.cluster_observer().cluster(cluster_id, "example_cluster")
# Spawn a worker.
worker = context.worker_observer().worker(
quent.now_v7(),
"worker_0",
cluster,
{
"version": "42.1.2",
"custom": {"threads": 256},
},
)
# Construct a queue.
queue = context.queue_observer().initializing(
quent.now_v7(),
"my_queue",
worker,
)
queue.operating(None)
# Construct a memory pool.
mem_pool = context.memory_pool_observer().initializing(
quent.now_v7(),
"my_memory_pool",
worker,
)
mem_pool.operating(1337)
mem_pool.resizing()
mem_pool.operating(2048)
# Spawn a thread.
thread = context.thread_observer().initializing(
quent.now_v7(),
"my_thread",
worker,
)
thread.operating()
# Single event entity.
context.info_observer().info(
quent.now_v7(),
"ready to operate",
__file__,
)
# Multi-event entity.
file_stats = context.file_stats_observer().create(quent.now_v7())
file_stats.checksum("sha256", "abc123def456")
file_stats.decompressed("snappy", 0.4)
# Queue a task. Usage arguments are either a handle, or a tuple whose first
# element is the handle and remaining elements are capacity values.
task = context.task_observer().queued(
quent.now_v7(),
"my_task_31415",
1,
worker,
(queue, 1),
)
task.computing(thread, None)
task.computing(thread, (mem_pool, 1024))
task.exit()
# Close context to flush all pending events.
context.close()
output_path = (output_dir / str(cluster_id) / "events.ndjson").resolve()
print(f"Events written to: {output_path}")
if __name__ == "__main__":
main()