Skip to main content

Chronos: A Python library for advanced task timing with features like distributed timing, batch timing, real-time visualization, and debugging-friendly timers.

Project description

Chronos

Chronos is a Python library for advanced task timing, performance monitoring, and debugging tools. It is designed for developers who need precise control over timing tasks, distributed systems, batch processing, and more, with features like real-time visualization and debugging-friendly timers.

Features

  • Base Timer: Core functionality for timing tasks with unit conversion, logging, and threshold warnings.
  • ChronosTimer: A basic timer with all core features.
  • DistributedChronosTimer: Aggregate timing data across distributed systems.
  • BatchChronosTimer: Time multiple tasks and compute aggregate statistics.
  • DebuggingChronosTimer: Pause and resume timers during debugging sessions.
  • ChronosTimerWithVisualization: Real-time ASCII progress bars for task timing.

Installation

Install Chronos using pip:

pip install chronos-context-timer

Usage Examples

Basic Timer

from chronos import ChronosTimer

with ChronosTimer("Basic Task") as timer:
    # Simulate some work
    import time
    time.sleep(1)

print(f"Task completed in {timer.get_elapsed('seconds')} seconds")

Distributed Timer

from chronos import DistributedChronosTimer

with DistributedChronosTimer("Distributed Task") as timer:
    import time
    time.sleep(1)

# Add external timings
timer.add_timing(0.5)
timer.add_timing(1.5)

print(f"Total elapsed time: {timer.get_total_time('seconds')} seconds")

Batch Timer

from chronos import BatchChronosTimer

def example_task():
    import time
    time.sleep(0.5)

batch_timer = BatchChronosTimer("Batch Example")
for _ in range(3):
    batch_timer.time_task(example_task)

stats = batch_timer.get_statistics("seconds")
print(f"Average time: {stats['average_time']} seconds")
print(f"Total time: {stats['total_time']} seconds")

Debugging Timer

from chronos import DebuggingChronosTimer

with DebuggingChronosTimer("Debug Task") as timer:
    input("Press Ctrl+Z to pause, and again to resume. Press Enter to finish.")

Timer with Visualization

from chronos import ChronosTimerWithVisualization

with ChronosTimerWithVisualization("Visualized Task", interval=0.2, threshold=5):
    import time
    time.sleep(5)

Development

Running Tests

Run all tests using pytest:

pytest tests/

Type Checking

Chronos is fully type-checked using mypy. To run type checks:

mypy chronos/

License

Chronos is licensed under the MIT License. See LICENSE for details.


Documentation

Complete documentation is available here.

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

chronos_context_timer-1.0.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chronos_context_timer-1.0.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file chronos_context_timer-1.0.0.tar.gz.

File metadata

  • Download URL: chronos_context_timer-1.0.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for chronos_context_timer-1.0.0.tar.gz
Algorithm Hash digest
SHA256 07a7337a17b80131df2193028517c965177b87aabdb7f9831647a73e26363ccf
MD5 6b80a74051b86647f14bc3b00fa5aeca
BLAKE2b-256 8c65f97ab6381120345e29e4500c3e9a348a2d4148cc54ef4090bcda397fcd30

See more details on using hashes here.

Provenance

The following attestation bundles were made for chronos_context_timer-1.0.0.tar.gz:

Publisher: publish-to-pypi.yml on adambirds/chronos

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chronos_context_timer-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for chronos_context_timer-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f133c0081870434c729208c8fcefe588f1c43e656875ff3d9e08c505176f6543
MD5 aef7faa47a299081291d5709498228e4
BLAKE2b-256 6a6a7e112472fc0d99ec3504946510dbe5a54b65e3b8cc39bd6bd9e1146dd349

See more details on using hashes here.

Provenance

The following attestation bundles were made for chronos_context_timer-1.0.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on adambirds/chronos

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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