Skip to main content

macOS signpost API wrapper

Project description

os-signpost

macOS provides the OSSignposter API for measuring the duration of tasks in a program or marking events. These so-called signposts can be visualized in the Instruments.app application. This Python package provides a wrapper for the OSSignposter API, so that you can mark tasks and events in Python applications.

⏳ Install

Make sure you have Xcode installed and then install with pip:

pip install os-signpost

🚀 Quickstart

Creating a Signposter

Signposter is the main class of this package. You should create an instance of Signposter in order to emit an event. You can create an instance as follows:

from os_signpost import Signposter
signposter = Signposter("com.example.my_subsystem", Signposter.Category.DynamicTracing)

The first argument to the constructor is the name of the subsystem, which is usually the name of your organization followed by the name of the subsystem. The second argument is the category within the subsystem. The system uses the category to filter events. There are three predefined categories available:

  • Category.PointsOfInterest: signposts with this category are always enabled. The Points of Interest instrument shows signposts with this category.
  • Category.DynamicTracing: signposts with this category are only enabled when recording with a performance tool like Instruments.app. Create an os_signpost instrument that filters for the subsystem name to visualize DynamicTracing signposts.
  • Category.DynamicStackTracing: this category behaves like DynamicTracing, but also records backtraces.

Make signposts for the duration of a tasks

To measure the duration of a task, you can create signposts that mark an interval. The Signposter.begin_interval method adds a signpost that marks the beginning of an interval and returns a callback. This callback then marks the end of the interval:

end_interval = signposter.begin_interval("begin my task")
# The task for which you want to measure the duration.
end_interval("end my task")

Both the begin_interval method and the callback take a message. Instruments.app includes these messages in the visualization and allows you to categorize intervals by their messages. When no message is specified for the interval end, the same message as the begin will be used.

You can also use the Signposter.use_interval context manager in place of the callback approach:

with signposter.use_interval("begin my task", "end my task"):
    # The task for which you want to measure the duration.

use_interval takes the begin and end messages as its arguments. The end message is also optional for the context manager.

Emitting an event

Besides marking intervals, you can also emit an event signpost. Instruments.app shows events as single points. The Signposter.emit_event method emits an event:

signposter.emit_event("lp0 on fire")

🙈 Limitations

The macOS signpost API also allows associating a name with a signpost. However, this name is required to be a C string literal. Therefore, we hardcode the name of signposts python.

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

os-signpost-0.0.3.tar.gz (5.3 kB view hashes)

Uploaded Source

Built Distributions

os_signpost-0.0.3-cp310-cp310-macosx_11_0_arm64.whl (33.9 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

os_signpost-0.0.3-cp310-cp310-macosx_10_9_x86_64.whl (35.0 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

os_signpost-0.0.3-cp39-cp39-macosx_11_0_arm64.whl (33.6 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

os_signpost-0.0.3-cp39-cp39-macosx_10_9_x86_64.whl (34.7 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

os_signpost-0.0.3-cp38-cp38-macosx_11_0_arm64.whl (33.6 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

os_signpost-0.0.3-cp38-cp38-macosx_10_9_x86_64.whl (34.4 kB view hashes)

Uploaded CPython 3.8 macOS 10.9+ x86-64

os_signpost-0.0.3-cp37-cp37m-macosx_10_9_x86_64.whl (34.1 kB view hashes)

Uploaded CPython 3.7m macOS 10.9+ x86-64

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