Skip to content

Commit febb1cb

Browse files
committed
Start adding dev docs
1 parent 1da6f16 commit febb1cb

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

api/src/opentrons/util/performance_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def _track_a_function(
103103
state_name: "RobotActivityState",
104104
func: _UnderlyingFunction[_UnderlyingFunctionParameters, _UnderlyingFunctionReturn],
105105
) -> typing.Callable[_UnderlyingFunctionParameters, _UnderlyingFunctionReturn]:
106-
"""Track a function.
106+
"""Wrap a passed function with RobotActivityTracker.track.
107107
108108
This function is a decorator that will track the given state for the
109109
decorated function.

performance-metrics/README.md

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,7 @@ It is assumed that you already have the other projects in the monorepo setup cor
1313
make -C performance-metrics setup
1414
```
1515

16-
### Testing against OT-2 Dev Server
17-
18-
```bash
19-
make -C robot-server dev-ot2
20-
```
21-
22-
### Testing against real OT-2
23-
24-
To push development packages to OT-2 run the following commands from the root directory of this repo:
25-
26-
```bash
27-
make -C performance-metrics push-no-restart host=<ot2-ip>
28-
make -C api push-no-restart host=<ot2-ip>
29-
make -C robot-server push host=<ot2-ip>
30-
```
31-
32-
### Testing against Flex Dev Server
33-
34-
```bash
35-
make -C robot-server dev-flex
36-
```
37-
38-
### Testing against real Flex
16+
### Pushing performance-metrics package to Flex
3917

4018
```bash
4119
make -C performance-metrics push-no-restart-ot3 host=<flex-ip>
@@ -69,3 +47,28 @@ To disable it run:
6947
```bash
7048
make unset-performance-metrics-ff host=<ip>
7149
```
50+
51+
## Available features
52+
53+
### Robot activity tracking
54+
55+
#### Description
56+
57+
Developers are able to track when the robot is in a block of code they choose to monitor. Looking at
58+
`api/src/opentrons/util/performance_helpers.py` you will see a class called `TrackingFunctions`. This class
59+
defines static methods which are decorators that can be used wrap arbitrary functions.
60+
61+
As of 2024-07-31, the following tracking functions are available:
62+
- `track_analysis`
63+
- `track_getting_cached_protocol_analysis`
64+
65+
Looking at `TrackingFunctions.track_analysis` we see that the underlying call to _track_a_function specifies a string `"ANALYZING_PROTOCOL"`. Whenever a function that is wrapped with `TrackingFunctions.track_analysis` executes, the tracking function will label the underlying function as `"ANALYZING_PROTOCOL"`.
66+
67+
To see where tracking function is used look at `robot_server/robot-server/protocols/protocol_analyzer.py`. You will see that the `ProtocolAnalyzer.analyze` function is wrapped with `TrackingFunctions.track_analysis`. Whenever `ProtocolAnalyzer.analyze` is called, the tracking function will start a timer. When the `ProtocolAnalyzer.analyze` function completes, the tracking function will stop the timer. It will then store the function start time and duration to the csv file, /data/performance_metrics_data/robot_activity_data
68+
69+
#### Adding new tracking decorator
70+
71+
To add a new tracking decorator, go to `performance-metrics/src/performance_metrics/_types.py`, and look at RobotActivityState literal and add a new state.
72+
Go to `api/src/opentrons/util/performance_helpers.py` and add a static method to the `TrackingFunctions` class that uses the new state.
73+
74+
You can now wrap your functions with your new tracking decorator.

performance-metrics/src/performance_metrics/_data_shapes.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ class RawActivityData(CSVStorageBase):
3434
"""Represents raw duration data with activity state information.
3535
3636
Attributes:
37-
- function_start_time (int): The start time of the function.
38-
- duration_measurement_start_time (int): The start time for duration measurement.
39-
- duration_measurement_end_time (int): The end time for duration measurement.
4037
- state (RobotActivityStates): The current state of the activity.
38+
- func_start (int): The start time of the function.
39+
- duration (int): The start time for duration measurement.
4140
"""
4241

4342
state: RobotActivityState

0 commit comments

Comments
 (0)