Skip to content

Commit

Permalink
Start adding dev docs
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekMaggio committed Jul 31, 2024
1 parent 1da6f16 commit febb1cb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion api/src/opentrons/util/performance_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def _track_a_function(
state_name: "RobotActivityState",
func: _UnderlyingFunction[_UnderlyingFunctionParameters, _UnderlyingFunctionReturn],
) -> typing.Callable[_UnderlyingFunctionParameters, _UnderlyingFunctionReturn]:
"""Track a function.
"""Wrap a passed function with RobotActivityTracker.track.
This function is a decorator that will track the given state for the
decorated function.
Expand Down
49 changes: 26 additions & 23 deletions performance-metrics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,7 @@ It is assumed that you already have the other projects in the monorepo setup cor
make -C performance-metrics setup
```

### Testing against OT-2 Dev Server

```bash
make -C robot-server dev-ot2
```

### Testing against real OT-2

To push development packages to OT-2 run the following commands from the root directory of this repo:

```bash
make -C performance-metrics push-no-restart host=<ot2-ip>
make -C api push-no-restart host=<ot2-ip>
make -C robot-server push host=<ot2-ip>
```

### Testing against Flex Dev Server

```bash
make -C robot-server dev-flex
```

### Testing against real Flex
### Pushing performance-metrics package to Flex

```bash
make -C performance-metrics push-no-restart-ot3 host=<flex-ip>
Expand Down Expand Up @@ -69,3 +47,28 @@ To disable it run:
```bash
make unset-performance-metrics-ff host=<ip>
```

## Available features

### Robot activity tracking

#### Description

Developers are able to track when the robot is in a block of code they choose to monitor. Looking at
`api/src/opentrons/util/performance_helpers.py` you will see a class called `TrackingFunctions`. This class
defines static methods which are decorators that can be used wrap arbitrary functions.

As of 2024-07-31, the following tracking functions are available:
- `track_analysis`
- `track_getting_cached_protocol_analysis`

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"`.

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

#### Adding new tracking decorator

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.
Go to `api/src/opentrons/util/performance_helpers.py` and add a static method to the `TrackingFunctions` class that uses the new state.

You can now wrap your functions with your new tracking decorator.
5 changes: 2 additions & 3 deletions performance-metrics/src/performance_metrics/_data_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ class RawActivityData(CSVStorageBase):
"""Represents raw duration data with activity state information.
Attributes:
- function_start_time (int): The start time of the function.
- duration_measurement_start_time (int): The start time for duration measurement.
- duration_measurement_end_time (int): The end time for duration measurement.
- state (RobotActivityStates): The current state of the activity.
- func_start (int): The start time of the function.
- duration (int): The start time for duration measurement.
"""

state: RobotActivityState
Expand Down

0 comments on commit febb1cb

Please sign in to comment.