Skip to content
This repository was archived by the owner on Jan 24, 2026. It is now read-only.

Profiling framework#114

Open
rcahoon wants to merge 3 commits into
mainfrom
rcahoon/profiling
Open

Profiling framework#114
rcahoon wants to merge 3 commits into
mainfrom
rcahoon/profiling

Conversation

@rcahoon
Copy link
Copy Markdown
Member

@rcahoon rcahoon commented Oct 4, 2025

Description

Add a way to easily report runtime of different parts of the code to AdvantageScope.

The functionality is controlled by a config file flag, and should be very low-overhead when disabled. To enable it, set "profiling": {"enabled": true} in the config file. It's recommended that you leave Save to config file on robot? unchecked when doing this, so that profiling will revert to being disabled when the robot is restarted (i.e. before it gets put on the field for a match).

A section of code can be profiled by wrapping it with

try (var profilingScope = Profiling.scope("Your Scope Name")) {
    ...
}

The whole robot main loop, Mechanism.run(), Procedures, RuleEngines, and Rules automatically get profiled.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Be detailed so that your code reviewer can understand exactly how much and what kinds of testing were done, and which might still be worthwhile to do.

  • Unit tests: [Add your description here]
  • Simulator testing: Ran example robot code in the simulator with AdvantageScope attached. Added a Thread.sleep(50) in the mechanism's run() method to produce some interesting data.
  • On-robot bench testing: [Add your description here]
  • On-robot field testing: [Add your description here]

@rcahoon
Copy link
Copy Markdown
Member Author

rcahoon commented Oct 4, 2025

image

@rcahoon rcahoon force-pushed the rcahoon/profiling branch from 59f7537 to 23f6fdc Compare October 6, 2025 03:15
if (!profilingEnabled.valueOr(false)) {
return null;
}
if (scopeIndex >= scopes.length) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log some kind of warning?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 done

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed?

Comment thread src/main/java/com/team766/framework/Profiling.java
Comment thread src/main/java/com/team766/framework/Profiling.java
Comment thread src/main/java/com/team766/framework/Profiling.java
Comment thread src/main/java/com/team766/hal/wpilib/RobotMain.java
if (!profilingEnabled.valueOr(false)) {
return null;
}
if (scopeIndex >= scopes.length) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pushed?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants