Getting started
Install with pip install avro-byte-counter
And run the following script.
from avro.io import *
import io
from avro_byte_counter.avro_byte_counter import AvroByteCounter
schema = avro.schema.parse("""{
"type": "record",
"name": "Person",
"fields": [
{"name": "userName", "type": "string"},
{"name": "favoriteNumber", "type": ["null", "long"], "default": null},
{"name": "interests", "type": {"type": "array", "items": "string"}}
]
}
""")
# Write bytes
writer = DatumWriter(schema)
bytes_writer = io.BytesIO()
writer.write(
{"userName": "Martin", "favoriteNumber": 1337, "interests": ["hacking", "daydreaming"]},
BinaryEncoder(bytes_writer)
)
# Count bytes per field
raw_bytes = bytes_writer.getvalue()
avro_byte_counter = AvroByteCounter(schema)
byte_count_per_field = avro_byte_counter.count_byte_per_field(raw_bytes)
print(byte_count_per_field)
For flamegraph compatible format, run:
from avro_byte_counter.utils import count_to_flamegraph_format
print(*count_to_flamegraph_format(byte_count_per_field), sep='\n')
Generate flamegraph
You can combine the python file created in getting started with the flamegraph.pl script to generate a flamegraph.
curl https://raw.githubusercontent.com/brendangregg/FlameGraph/d9fcc272b6a08c3e3e5b7919040f0ab5f8952d65/flamegraph.pl # any version is fine
chmod +x flamegraph.pl
python run myscript.py | ./flamegraph.pl --countname bytes > profiles/flamegraph.svg
Installation troubleshoot
Some users might need to add some flags to the pip command, such as --user or --no-build-isolation.
You can also try to install by cloning this repo and install with poetry directly.
If you still have issues or identified ones, don't hesitate to open an issue or a PR and ping me on it.
Feedbacks
I gladly take feedbacks you have regarding the API, the usefulness of the project or anything :)
Metadata
Release files for avro-byte-counter 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| avro_byte_counter-0.1.0.tar.gz | 4.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| avro_byte_counter-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.5 kB
Release files / avro_byte_counter-0.1.0.tar.gz
| Download URL | avro_byte_counter-0.1.0.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f80f0d6135389d15f98c6a3e12b4384c99c4e677c7ae7f0b15d62d3888d4e899
|
|
BLAKE2b-256 checksum How to use checksums |
146ea3db7a6fc13ad8a7d1d18cb3752f84f9da8f0f961c9b0e8b52c1bf15cb85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.11.3 Linux/5.15.0-1037-azure
|
Release files / avro_byte_counter-0.1.0-py3-none-any.whl
| Download URL | avro_byte_counter-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f135a1dd9a413d2430773e49606a37a23f0a443670679109a3476851d74cb94c
|
|
BLAKE2b-256 checksum How to use checksums |
be8a4fbeb6b5d5c6ef84bdec29e0ccf90cf76fc0675987f06465f8cb558d0f61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.5.1 CPython/3.11.3 Linux/5.15.0-1037-azure
|