Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(performance-metrics): update dev documentation #15853

Merged
merged 3 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
55 changes: 32 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,34 @@ 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.

### System resource tracking

performance-metrics also exposes a tracking application called `SystemResourceTracker`. The application is implemented as a systemd service on the robot and records system resource usage by process. See the `oe-core` repo for more details.
You can configure the system resource tracker by modifying the environment variables set for the service. The service file lives at `/lib/systemd/system/system-resource-tracker.service`. You can change the defined environment variables or remove them and define them in the robot's environment variables. See `performance-metrics/src/performance_metrics/system_resource_tracker/_config.py` to see what environment variables are available.
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
Loading