openblockperf 0.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. openblockperf-0.0.3/LICENSE +201 -0
  2. openblockperf-0.0.3/PKG-INFO +52 -0
  3. openblockperf-0.0.3/README.md +34 -0
  4. openblockperf-0.0.3/pyproject.toml +83 -0
  5. openblockperf-0.0.3/setup.cfg +4 -0
  6. openblockperf-0.0.3/src/blockperf/__init__.py +19 -0
  7. openblockperf-0.0.3/src/blockperf/cli.py +32 -0
  8. openblockperf-0.0.3/src/blockperf/commands/__init__.py +5 -0
  9. openblockperf-0.0.3/src/blockperf/commands/analyze.py +60 -0
  10. openblockperf-0.0.3/src/blockperf/commands/base.py +25 -0
  11. openblockperf-0.0.3/src/blockperf/commands/monitor.py +87 -0
  12. openblockperf-0.0.3/src/blockperf/commands/run.py +48 -0
  13. openblockperf-0.0.3/src/blockperf/core/__init__.py +5 -0
  14. openblockperf-0.0.3/src/blockperf/core/apiclient.py +105 -0
  15. openblockperf-0.0.3/src/blockperf/core/async_utils.py +76 -0
  16. openblockperf-0.0.3/src/blockperf/core/config.py +90 -0
  17. openblockperf-0.0.3/src/blockperf/core/eventcollector.py +383 -0
  18. openblockperf-0.0.3/src/blockperf/core/eventprocessor.py +87 -0
  19. openblockperf-0.0.3/src/blockperf/core/events.py +434 -0
  20. openblockperf-0.0.3/src/blockperf/core/logreader.py +144 -0
  21. openblockperf-0.0.3/src/blockperf/main.py +14 -0
  22. openblockperf-0.0.3/src/openblockperf.egg-info/PKG-INFO +52 -0
  23. openblockperf-0.0.3/src/openblockperf.egg-info/SOURCES.txt +25 -0
  24. openblockperf-0.0.3/src/openblockperf.egg-info/dependency_links.txt +1 -0
  25. openblockperf-0.0.3/src/openblockperf.egg-info/entry_points.txt +2 -0
  26. openblockperf-0.0.3/src/openblockperf.egg-info/requires.txt +4 -0
  27. openblockperf-0.0.3/src/openblockperf.egg-info/top_level.txt +1 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,52 @@
1
+ Metadata-Version: 2.4
2
+ Name: openblockperf
3
+ Version: 0.0.3
4
+ Summary: The OpenBlockperf client
5
+ Author-email: Manuel Schmidt <manuel.schmidt@cardanofoundation.org>
6
+ Maintainer-email: Manuel Schmidt <manuel.schmidt@cardanofoundation.org>
7
+ Project-URL: Homepage, https://github.com/cardano-foundation/openblockperf
8
+ Project-URL: Bug Reports, https://github.com/cardano-foundation/openblockperf/issues
9
+ Keywords: cardano,cardano-foundation,ops
10
+ Requires-Python: >=3.12
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: click>=8.1.8
14
+ Requires-Dist: pydantic>=2.10.6
15
+ Requires-Dist: pydantic-settings>=2.8.0
16
+ Requires-Dist: typer>=0.15.2
17
+ Dynamic: license-file
18
+
19
+ # OpenBlockperf Client
20
+
21
+ The OpenBlockperf Client is a cli tool that collects various metrics from
22
+ a cardano node. If you dont know what a cardano-node is or dont run one
23
+ yourself, this tool is probably not for you.
24
+
25
+ ---
26
+
27
+ Install OpenBlockperf using pip:
28
+
29
+ ```shell
30
+ $ pip install openblockperf
31
+ ```
32
+
33
+ ## Get started
34
+
35
+ * You will need a `cardano-node` and and the `cardano-tracer` up and running.
36
+ * Set the network via the `NETWORK` environment variable.
37
+ * If you have not yet started to use uv i highly recommend you do. See https://docs.astral.sh/uv/getting-started/installation/
38
+
39
+ ```shell
40
+ export NETWORK="mainnet"
41
+ blockperf run
42
+ ```
43
+
44
+ ## Dependencies
45
+
46
+ We have tried to keep the dependencies as little as possible. Thi
47
+
48
+ * `typer` - We use typer to implement the cli interface
49
+ * `click` - Typer itself relies on the click library
50
+ * `pydantic` - For json (and other data) validation
51
+ * `pydantic-settings` - For the applications configuration
52
+
@@ -0,0 +1,34 @@
1
+ # OpenBlockperf Client
2
+
3
+ The OpenBlockperf Client is a cli tool that collects various metrics from
4
+ a cardano node. If you dont know what a cardano-node is or dont run one
5
+ yourself, this tool is probably not for you.
6
+
7
+ ---
8
+
9
+ Install OpenBlockperf using pip:
10
+
11
+ ```shell
12
+ $ pip install openblockperf
13
+ ```
14
+
15
+ ## Get started
16
+
17
+ * You will need a `cardano-node` and and the `cardano-tracer` up and running.
18
+ * Set the network via the `NETWORK` environment variable.
19
+ * If you have not yet started to use uv i highly recommend you do. See https://docs.astral.sh/uv/getting-started/installation/
20
+
21
+ ```shell
22
+ export NETWORK="mainnet"
23
+ blockperf run
24
+ ```
25
+
26
+ ## Dependencies
27
+
28
+ We have tried to keep the dependencies as little as possible. Thi
29
+
30
+ * `typer` - We use typer to implement the cli interface
31
+ * `click` - Typer itself relies on the click library
32
+ * `pydantic` - For json (and other data) validation
33
+ * `pydantic-settings` - For the applications configuration
34
+
@@ -0,0 +1,83 @@
1
+ [build-system]
2
+ requires = ["setuptools"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "openblockperf"
7
+ version = "0.0.3"
8
+ description = "The OpenBlockperf client"
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ dependencies = [
12
+ "click>=8.1.8",
13
+ "pydantic>=2.10.6",
14
+ "pydantic-settings>=2.8.0",
15
+ "typer>=0.15.2",
16
+ ]
17
+ keywords = ["cardano", "cardano-foundation", "ops"]
18
+ authors = [
19
+ {name = "Manuel Schmidt", email = "manuel.schmidt@cardanofoundation.org" },
20
+ ]
21
+ maintainers = [
22
+ {name = "Manuel Schmidt", email = "manuel.schmidt@cardanofoundation.org" },
23
+ ]
24
+
25
+ [project.scripts]
26
+ blockperf = "blockperf.main:run"
27
+
28
+ [project.urls]
29
+ "Homepage" = "https://github.com/cardano-foundation/openblockperf"
30
+ "Bug Reports" = "https://github.com/cardano-foundation/openblockperf/issues"
31
+
32
+ [dependency-groups]
33
+ dev = [
34
+ "ipython>=9.5.0",
35
+ "pudb>=2025.1",
36
+ "pytest>=8.4.2",
37
+ ]
38
+
39
+ [tool.mypy]
40
+ ignore_missing_imports = true
41
+
42
+ # Provide test pypi index configuration for use with uv publish --index testpypi
43
+ [[tool.uv.index]]
44
+ name = "testpypi"
45
+ url = "https://test.pypi.org/simple/"
46
+ publish-url = "https://test.pypi.org/legacy/"
47
+ explicit = true
48
+
49
+ [tool.ruff]
50
+ # Enable all rules by default, then selectively disable
51
+ select = ["E", "F", "W", "I", "N", "UP", "B", "A", "C4", "SIM", "PL"]
52
+ ignore = ["E501"] # Ignore line length violations
53
+ # Assume Python 3.12
54
+ target-version = "py312"
55
+
56
+ # Exclude a variety of commonly ignored directories
57
+ exclude = [
58
+ ".git",
59
+ ".mypy_cache",
60
+ ".ruff_cache",
61
+ ".venv",
62
+ "__pycache__",
63
+ ]
64
+
65
+ # Set the line length to 88 (match black)
66
+ line-length = 80
67
+
68
+ # Sort imports
69
+ [tool.ruff.isort]
70
+ known-first-party = ["app", "cli"]
71
+
72
+ #[tool.ruff.lint]
73
+ #extend-select = ["E", "W", "F", "B"]
74
+
75
+ [tool.ruff.format]
76
+ # Like Black, use double quotes for strings.
77
+ quote-style = "double"
78
+ # Like Black, indent with spaces, rather than tabs.
79
+ indent-style = "space"
80
+
81
+ # Docstring settings
82
+ [tool.ruff.pydocstyle]
83
+ convention = "google" # Or "numpy", "pep257"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,19 @@
1
+ # Version information for blockperf
2
+ # Version is read from pyproject.toml - edit the version there
3
+
4
+ import tomllib
5
+ from pathlib import Path
6
+
7
+
8
+ def _get_version():
9
+ """Read version from pyproject.toml"""
10
+ pyproject_path = Path(__file__).parent.parent.parent / "pyproject.toml"
11
+ try:
12
+ with open(pyproject_path, "rb") as f:
13
+ pyproject = tomllib.load(f)
14
+ return pyproject["project"]["version"]
15
+ except Exception:
16
+ return "unknown"
17
+
18
+
19
+ __version__ = _get_version()
@@ -0,0 +1,32 @@
1
+ """Setup the cli by creating the main Typer application (blockperf_app) and
2
+ adding the (sub)commands to it."""
3
+
4
+ import typer
5
+ from rich.console import Console
6
+
7
+ from blockperf.commands.analyze import analyze_app
8
+ from blockperf.commands.base import version_cmd
9
+ from blockperf.commands.monitor import monitor_app
10
+ from blockperf.commands.run import run_app
11
+
12
+ console = Console()
13
+
14
+
15
+ # Initialize the Typer application
16
+ blockperf_app = typer.Typer(
17
+ name="blockperf",
18
+ help="A CLI application for block performance analysis",
19
+ add_completion=True,
20
+ no_args_is_help=True,
21
+ )
22
+
23
+ # Add base commands directly to the app
24
+ blockperf_app.command("version")(version_cmd)
25
+ blockperf_app.add_typer(analyze_app)
26
+ blockperf_app.add_typer(monitor_app)
27
+ blockperf_app.add_typer(run_app)
28
+
29
+
30
+ def mycallback():
31
+ """Creates a single user Hiro Hamada. In the next version it will create 5 more users."""
32
+ console.print("Y A Y")
@@ -0,0 +1,5 @@
1
+ """Command modules for the BlockPerf CLI."""
2
+
3
+ from blockperf.commands import base
4
+
5
+ __all__ = ["base"]
@@ -0,0 +1,60 @@
1
+ import asyncio
2
+ import random
3
+
4
+ import typer
5
+ from rich.console import Console
6
+
7
+ from blockperf.core.async_utils import run_async
8
+
9
+ console = Console()
10
+
11
+ analyze_app = typer.Typer(
12
+ name="analyze",
13
+ help="Performance analysis commands",
14
+ )
15
+
16
+
17
+ @analyze_app.command(name="blocks")
18
+ def analyze_blocks(
19
+ blocks: int = typer.Option(
20
+ 10, "--blocks", "-b", help="Number of blocks to analyze"
21
+ ),
22
+ network: str = typer.Option(
23
+ "mainnet", "--network", "-n", help="Network to analyze"
24
+ ),
25
+ timeout: int = typer.Option(
26
+ 60, "--timeout", "-t", help="Timeout in seconds"
27
+ ),
28
+ ) -> None:
29
+ """Analyze a number of blocks for performance metrics.
30
+
31
+ Args:
32
+ blocks: Number of blocks to analyze
33
+ network: Network to analyze blocks from
34
+ timeout: Timeout in seconds for analysis operations
35
+ """
36
+ run_async(_analyze_blocks_async(blocks, network, timeout))
37
+
38
+
39
+ async def _analyze_blocks_async(
40
+ blocks: int, network: str, timeout: int
41
+ ) -> None:
42
+ """Async implementation of block analysis.
43
+
44
+ Args:
45
+ blocks: Number of blocks to analyze
46
+ network: Network to analyze blocks from
47
+ timeout: Timeout in seconds for analysis operations
48
+ """
49
+ console.print(
50
+ f"Analyzing [bold]{blocks}[/] blocks on [bold]{network}[/]..."
51
+ )
52
+
53
+ # Simulate work with asyncio
54
+ for i in range(blocks):
55
+ console.print(f"Processing block {i + 1}/{blocks}")
56
+ await asyncio.sleep(
57
+ random.uniform(0.1, 6)
58
+ ) # Simulate network or processing delay
59
+
60
+ console.print("[bold green]Analysis complete![/]")
@@ -0,0 +1,25 @@
1
+ """Base commands implementation for BlockPerf CLI."""
2
+
3
+ import typer
4
+ from rich.console import Console
5
+
6
+ from blockperf import __version__
7
+
8
+ console = Console()
9
+
10
+
11
+ def version_cmd(verbose: bool = False) -> None:
12
+ """Display the version of BlockPerf.
13
+
14
+ Args:
15
+ verbose: Display more detailed version information
16
+ """
17
+ console.print(f"BlockPerf version: [bold green]{__version__}[/]")
18
+
19
+ if verbose:
20
+ console.print("\n[bold]Environment:[/]")
21
+ import platform
22
+ import sys
23
+
24
+ console.print(f"Python version: [cyan]{sys.version}[/]")
25
+ console.print(f"Platform: [cyan]{platform.platform()}[/]")
@@ -0,0 +1,87 @@
1
+ import asyncio
2
+ import time
3
+
4
+ import typer
5
+ from rich.console import Console
6
+ from rich.progress import Progress, SpinnerColumn, TextColumn, TimeElapsedColumn
7
+
8
+ from blockperf.core.async_utils import run_async
9
+
10
+ console = Console()
11
+
12
+
13
+ # Create the monitor command group
14
+ monitor_app = typer.Typer(
15
+ name="monitor",
16
+ help="Real-time monitoring commands",
17
+ invoke_without_command=True,
18
+ )
19
+
20
+
21
+ @monitor_app.callback()
22
+ def monitor_app_callback(verboze: bool = False):
23
+ pass
24
+
25
+
26
+ @monitor_app.command(name="blocks")
27
+ def monitor_blocks(
28
+ duration: int = typer.Option(
29
+ 0,
30
+ "--duration",
31
+ "-d",
32
+ help="Duration to monitor in seconds (0 for indefinite)",
33
+ ),
34
+ network: str = typer.Option(
35
+ "mainnet", "--network", "-n", help="Network to monitor"
36
+ ),
37
+ ) -> None:
38
+ """Monitor blocks in real-time.
39
+
40
+ Args:
41
+ duration: Duration to monitor in seconds (0 for indefinite)
42
+ network: Network to monitor blocks from
43
+ """
44
+ try:
45
+ run_async(_monitor_blocks_async(duration, network))
46
+ except KeyboardInterrupt:
47
+ console.print("\n[bold yellow]Monitoring stopped.[/]")
48
+
49
+
50
+ async def _monitor_blocks_async(duration: int, network: str) -> None:
51
+ """Async implementation of block monitoring.
52
+
53
+ Args:
54
+ duration: Duration to monitor in seconds (0 for indefinite)
55
+ network: Network to monitor blocks from
56
+ """
57
+ start_time = time.time()
58
+ block_count = 0
59
+
60
+ with Progress(
61
+ SpinnerColumn(),
62
+ TextColumn("[bold blue]Monitoring blocks..."),
63
+ TimeElapsedColumn(),
64
+ console=console,
65
+ ) as progress:
66
+ task = progress.add_task(
67
+ "Monitoring", total=duration if duration > 0 else None
68
+ )
69
+
70
+ while True:
71
+ # Check if we've reached the duration
72
+ if duration > 0:
73
+ elapsed = time.time() - start_time
74
+ progress.update(task, completed=elapsed)
75
+ if elapsed >= duration:
76
+ break
77
+
78
+ # Simulate receiving a new block
79
+ block_count += 1
80
+ console.print(f"New block received: #{block_count} on {network}")
81
+
82
+ # Wait for next block
83
+ await asyncio.sleep(2) # Simulate block time
84
+
85
+ console.print(
86
+ f"[bold green]Monitoring complete! Observed {block_count} blocks.[/]"
87
+ )
@@ -0,0 +1,48 @@
1
+ import asyncio
2
+ from datetime import datetime
3
+
4
+ import rich
5
+ import typer
6
+ from rich.console import Console
7
+
8
+ from blockperf.core.async_utils import run_async
9
+ from blockperf.core.config import settings
10
+ from blockperf.core.eventprocessor import EventProcessor
11
+ from blockperf.core.logreader import create_log_reader
12
+
13
+ console = Console()
14
+
15
+ run_app = typer.Typer(
16
+ name="run",
17
+ help="Run the blockperf client",
18
+ invoke_without_command=True,
19
+ )
20
+
21
+
22
+ @run_app.callback()
23
+ def run_app_callback():
24
+ """Runs the blockperf client.
25
+
26
+ Creates a log reader first and then the event processor. The event
27
+ processor uses the log reader to read log events and process them.
28
+ The event processor is run inside an asyncio
29
+ """
30
+ try:
31
+ rich.print(
32
+ f"[bold]Network[/]: [color red]{settings().network.value.capitalize()}[/] [bold]Magic[/]: {settings().network_config.magic} [bold]Startime[/]: {datetime.fromtimestamp(settings().network_config.starttime).isoformat()}",
33
+ )
34
+
35
+ log_reader = create_log_reader("journalctl", "cardano-tracer")
36
+ event_processor = EventProcessor(log_reader=log_reader)
37
+ run_async(_run_event_processor(event_processor))
38
+ except KeyboardInterrupt:
39
+ console.print("\n[bold yellow]Monitoring stopped.[/]")
40
+
41
+
42
+ async def _run_event_processor(event_processor: EventProcessor):
43
+ """Asyncronously run the given event processor."""
44
+ try:
45
+ event_processor_task = asyncio.create_task(event_processor.start())
46
+ await event_processor_task
47
+ except asyncio.CancelledError:
48
+ await event_processor.stop()
@@ -0,0 +1,5 @@
1
+ """Core functionality modules for BlockPerf."""
2
+
3
+ from blockperf.core import async_utils
4
+
5
+ __all__ = ["async_utils"]