Skip to content

Conversation

@leonvandermeer
Copy link
Contributor

Implement WakeLock so that the system does not enter sleep while benchmarks are running.

As a happy user of BDN, I was annoyed by the fact that long running benchmarks were not completed when I returned to my system. All because my system enters sleep, after not being touched for a while.

The test code needs to enumerate power requests. I decided not to pinvoke undocumented api as maintenance is difficult if it changes in future windows version. It gave me a chance to learn more about parsers in general 😂. Imo, maintaining the parser when powercfg /requests output would change is less difficult.

In case you prefer usage of Superpower library to parse, I'm willing to change that.

All test code is in integration tests, since powercfg needs elevation. I imagine developers dislike failing unit tests when they run those locally.

Copy link
Collaborator

@timcassell timcassell left a comment

Choose a reason for hiding this comment

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

I appreciate all the tests! Do any other OSes besides Windows need this treatment?

Copy link
Collaborator

@timcassell timcassell left a comment

Choose a reason for hiding this comment

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

LGTM! I would like a second review before merging this new functionality, though. @adamsitnik or @AndreyAkinshin may have different opinions on what the default should be.

@leonvandermeer
Copy link
Contributor Author

Hi @AndreyAkinshin and @adamsitnik . Happy New Year1!

Do you have time to look at this feature? I will be very happy if my contribution makes it into the product.

Footnotes

  1. Also applies to all other BDN team members.

Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

@leonvandermeer big thanks for your high quality contribution!

Overall the code looks good, but some feedback needs to be addressed before the code gets merged. PTAL at my comments.

@leonvandermeer
Copy link
Contributor Author

FYI, I'm finished with this rework round. Please take next steps to merge the feature.

@timcassell timcassell requested a review from adamsitnik January 15, 2025 18:17
@timcassell
Copy link
Collaborator

It looks to me like all the feedback was addressed, so I will go ahead and merge.

I actually recently ran into this issue on a MacBook, so hopefully someone can extend this to other OSes in the future.

Thanks @leonvandermeer!

@timcassell timcassell merged commit de8fb91 into dotnet:master Jan 30, 2025
8 checks passed
@timcassell timcassell added this to the v0.14.1 milestone Jan 30, 2025
Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

Thank you for addressing my feedback and providing high quality contribution to BenchmarkDotNet @leonvandermeer 👍

{
logger.WriteLineError($"Unable to allow the system from entering sleep or turning off the display (error message: {ex.Message}).");
}
safePowerHandle.Dispose();
Copy link
Member

Choose a reason for hiding this comment

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

the disposal should be put into a finally block

@leonvandermeer leonvandermeer deleted the feature/wake-lock branch January 31, 2025 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants