Performance Monitoring reference¶
At a glance¶
Performance.performance():trace(name),start_trace(name),data_collection_enabled,instrumentation_enabledTrace:name,start(),stop(),running,active,increment_metric(name, by=1),set_metric(name, value),get_metric(name),put_attribute(name, value),get_attribute(name),remove_attribute(name),attributes; a context managerHTTPMetric(url, method):start(),stop(),running,active,response_code,request_payload_size,response_payload_size,response_content_type, the attribute methods; a context manager;HTTPMethod
pyios_firebase.performance¶
Firebase Performance Monitoring: custom code traces and network requests.
from pyios_firebase.performance import HTTPMethod, HTTPMetric, Performance
with Performance.performance().trace("load_feed") as trace:
items = load_feed()
trace.increment_metric("items", len(items))
trace.put_attribute("source", "cache")
metric = HTTPMetric("https://api.example.com/feed", HTTPMethod.GET)
metric.start()
... # make the request
metric.response_code = 200
metric.response_payload_size = len(body)
metric.stop()
The SDK measures app start, screen rendering and the requests made with
NSURLSession by itself. Requests made from Python (urllib,
requests, httpx...) do not use NSURLSession: measure them with
HTTPMetric.
Bad names and values raise ValueError (the SDK would drop the trace,
metric or attribute quietly). While data collection is off, traces and HTTP
metrics are inactive (active is False) and do nothing.
Needs the FirebasePerformance framework.
Classes:
| Name | Description |
|---|---|
HTTPMethod |
The method of an |
Trace |
A custom code trace: the time between |
HTTPMetric |
A network request you measure yourself (for requests made from Python, |
Performance |
Performance Monitoring. Get it with |
HTTPMethod
¶
The method of an HTTPMetric's request (FIRHTTPMethod).
Trace
¶
Trace(native: ObjCObject | None, name: str)
Bases: _Timed
A custom code trace: the time between start and stop, with your
own metrics (counters) and attributes. Get it from Performance.
Use it with with to start and stop it::
with Performance.performance().trace("checkout") as trace:
trace.increment_metric("items", 3)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
native
|
ObjCObject | None
|
the native |
required |
name
|
str
|
the trace's name. |
required |
Methods:
| Name | Description |
|---|---|
increment_metric |
Add to a metric (a metric starts at 0). |
set_metric |
Set a metric. |
get_metric |
A metric's value (0 if it was never set). |
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The trace's name. |
increment_metric
¶
Add to a metric (a metric starts at 0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
the metric's name (as for trace names). |
required |
by
|
int
|
the amount to add (negative to subtract). |
1
|
Raises:
| Type | Description |
|---|---|
ValueError
|
an invalid name. |
RuntimeError
|
the trace is not running. |
set_metric
¶
Set a metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
the metric's name. |
required |
value
|
int
|
the value. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
an invalid name. |
RuntimeError
|
the trace is not running. |
get_metric
¶
A metric's value (0 if it was never set).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
the metric's name. |
required |
HTTPMetric
¶
Bases: _Timed
A network request you measure yourself (for requests made from Python, which the SDK does not see). Start it before sending the request, set the response fields, then stop it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
the request's |
required |
method
|
int
|
an |
GET
|
Raises:
| Type | Description |
|---|---|
ValueError
|
not an |
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str
|
The request's URL. |
response_code |
int
|
The HTTP status code (set it before |
request_payload_size |
int
|
The request body's size in bytes. |
response_payload_size |
int
|
The response body's size in bytes. |
response_content_type |
str | None
|
The response's |
Performance
¶
Performance(native: ObjCObject)
Performance Monitoring. Get it with Performance.performance().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
native
|
ObjCObject
|
the native |
required |
Methods:
| Name | Description |
|---|---|
performance |
The shared |
trace |
A new trace, not started (use |
start_trace |
A new trace, already started. |
Attributes:
| Name | Type | Description |
|---|---|---|
native |
ObjCObject
|
The |
data_collection_enabled |
bool
|
Collect and send data (custom traces too). Setting it is kept across |
instrumentation_enabled |
bool
|
Measure app start, screens and |
data_collection_enabled
property
writable
¶
Collect and send data (custom traces too). Setting it is kept across
launches; to start with it off, set
firebase_performance_collection_enabled to NO in Info.plist.
instrumentation_enabled
property
writable
¶
Measure app start, screens and NSURLSession requests automatically.
Takes effect at the next launch; firebase_performance_instrumentation_enabled
in Info.plist sets it at build time.
trace
¶
trace(name: str) -> Trace
A new trace, not started (use with, or start() / stop()).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
1 to 100 characters, not starting with |
required |
Returns:
| Type | Description |
|---|---|
Trace
|
A |
Raises:
| Type | Description |
|---|---|
ValueError
|
an invalid name. |
RuntimeError
|
Firebase is not configured yet (the SDK would abort the app). |