Skip to main content

Count number of bytes per field

Project description

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 :)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

avro_byte_counter-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

avro_byte_counter-0.1.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file avro_byte_counter-0.1.0.tar.gz.

File metadata

  • Download URL: avro_byte_counter-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.3 Linux/5.15.0-1037-azure

File hashes

Hashes for avro_byte_counter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f80f0d6135389d15f98c6a3e12b4384c99c4e677c7ae7f0b15d62d3888d4e899
MD5 7ef277400cb2fac41975d413df164184
BLAKE2b-256 146ea3db7a6fc13ad8a7d1d18cb3752f84f9da8f0f961c9b0e8b52c1bf15cb85

See more details on using hashes here.

File details

Details for the file avro_byte_counter-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: avro_byte_counter-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.3 Linux/5.15.0-1037-azure

File hashes

Hashes for avro_byte_counter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f135a1dd9a413d2430773e49606a37a23f0a443670679109a3476851d74cb94c
MD5 c2231659beff6eb11a82f64406459462
BLAKE2b-256 be8a4fbeb6b5d5c6ef84bdec29e0ccf90cf76fc0675987f06465f8cb558d0f61

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page