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

Implemented power-management, add docs (#68) #952

Merged
merged 6 commits into from
Apr 1, 2019

Conversation

MarekM25
Copy link
Contributor

No description provided.

@dnfclas
Copy link

dnfclas commented Nov 10, 2018

CLA assistant check
All CLA requirements met.

@AndreyAkinshin
Copy link
Member

@MarekM25 thanks for the PR.


# Power Plans

This description concerns only version v0.11.2 and above of BenchmarkDotNet. In the previous versions, benchmarks in the power plans.
Copy link
Member

Choose a reason for hiding this comment

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

We don't need a note about the BenchmarkDotNet version. The documentation is always relevant only for the latest version of BenchmarkDotNet.

namespace BenchmarkDotNet.Samples
{
[HighPerformancePowerPlan(false)]
public class IntroPowerPlan
Copy link
Member

Choose a reason for hiding this comment

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

In the IntroSample, we need two jobs (enabled and disabled high performance power plan) to show the difference between them. An example of the summary table should be included in IntroPowerPlan.md.

/// determines if BenchmarDotNet changes power plan to High Performance
/// </summary>
[PublicAPI]
public class HighPerformancePowerPlanAttribute : Attribute, IConfigSource
Copy link
Member

Choose a reason for hiding this comment

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

It makes sense to add [AttributeUsage(AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)] here. It will allow comparing enabled/disabled configurations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be sure I thought about only enabling/disabling the high-performance plan. From my perspective, allowing multiple attributes with the current implementation is not enough (of course, I might be wrong). However, it is a remarkably great idea to do it, and I suggest doing more here. I mean not only analyzing disabled and enabled a high-performance plan but making it possible to compare any power plan for a user. For example, we could compare HighPerformance, Balanced, PowerSaver. What is more, I consider allowing a user to both use power plan enum and provide it by GUID string. The first way contains popular power plan GUIDs such as I mentioned previously. The second approach is essential because companies could have own, custom power plans for any device. This feature allows targeting benchmarks when we could expect what power plan is used by an end user. We could benchmark different power plans if we know that our software will be run on a server, a personal laptop or mobile phone. I could do it willingly as my next issue or by continuing actual:) What do you think?

internal class PowerManagementApplier
{
private Guid? _userCurrentPowerPlan;
private bool _powerPlanChanged = false;
Copy link
Member

Choose a reason for hiding this comment

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

We don't use underscores as private field prefixes. Please, remove it.

[Fact]
public void TestSettingAndRevertingBackGuid()
{
if (RuntimeInformation.IsWindows())
Copy link
Member

Choose a reason for hiding this comment

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

Please, use FactWindowsOnlyAttribute instead of such checks.

Copy link
Contributor Author

@MarekM25 MarekM25 Dec 15, 2018

Choose a reason for hiding this comment

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

Thx, this is exactly what I needed ! :)

{
if (RuntimeInformation.IsWindows())
{
if (highPerformancePowerPlan && _powerPlanChanged == false)
Copy link
Member

Choose a reason for hiding this comment

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

Could we move the Apply logic from constructor to a separate method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you tell me what do you mean by that? It is not the constructor but a method. Perhaps, I don't understand you. However, I moved logger injection to the constructor.

@MarekM25
Copy link
Contributor Author

@MarekM25 thanks for the PR.

And thanks for your review! :) Could you look why my build fail? Perhaps, we should retry it. I couldn't find that option was available for me.

@AndreyAkinshin
Copy link
Member

@MarekM25 the build is restarted.

To be sure I thought about only enabling/disabling the high-performance plan. From my perspective, allowing multiple attributes with the current implementation is not enough (of course, I might be wrong). However, it is a remarkably great idea to do it, and I suggest doing more here. I mean not only analyzing disabled and enabled a high-performance plan but making it possible to compare any power plan for a user. For example, we could compare HighPerformance, Balanced, PowerSaver. What is more, I consider allowing a user to both use power plan enum and provide it by GUID string. The first way contains popular power plan GUIDs such as I mentioned previously. The second approach is essential because companies could have own, custom power plans for any device. This feature allows targeting benchmarks when we could expect what power plan is used by an end user. We could benchmark different power plans if we know that our software will be run on a server, a personal laptop or mobile phone. I could do it willingly as my next issue or by continuing actual:) What do you think?

It looks pretty interesting. However, let's do the minimal implementation first. Currently, HighPerformancePowerPlan is a property of a config. That's why you had to duplicate your benchmark in the sample:

    [HighPerformancePowerPlan(false)]
    public class IntroPowerPlanDisabled
    {
        [Benchmark]
        public int SplitJoin()
            => string.Join(",", new string[1000]).Split(',').Length;
    }
    // By default benchmark.net uses high-performance power plan.
    // There is no need to set it to true explicitly
    [HighPerformancePowerPlan(true)]
    public class IntroPowerPlanEnabled
    {
        [Benchmark]
        public int SplitJoin()
            => string.Join(",", new string[1000]).Split(',').Length;
    }

The PowerPlan should be a property of a job (like Platform, Jit, and so on). In this case, users will be able to apply different power plans to the same benchmark class without code duplication.

@MarekM25
Copy link
Contributor Author

MarekM25 commented Feb 1, 2019

Hi @AndreyAkinshin ,
I finished working on this PR. Could you have a look? What do you think?
The build failed, but the same test locally and before squashing commits works fine. Is it possible that the test is unstable?

@AndreyAkinshin
Copy link
Member

@MarekM25 I will review this PR on the next week. Meanwhile, could you please resolve conflicts with the master branch?

# Conflicts:
#	src/BenchmarkDotNet/Configs/ConfigExtensions.cs
@MarekM25
Copy link
Contributor Author

MarekM25 commented Feb 5, 2019

@MarekM25 I will review this PR on the next week. Meanwhile, could you please resolve conflicts with the master branch?

Thx, done ;) @AndreyAkinshin could you take a look? :)

# Conflicts:
#	src/BenchmarkDotNet/Jobs/EnvironmentMode.cs
@AndreyAkinshin AndreyAkinshin merged commit 8aa6ade into dotnet:master Apr 1, 2019
@AndreyAkinshin
Copy link
Member

@MarekM25 sorry for such a delay, I had to verify this branch on different laptops. It works great! Thanks for your contribution!

@AndreyAkinshin AndreyAkinshin added this to the v0.11.5 milestone Apr 1, 2019
@AndreyAkinshin AndreyAkinshin mentioned this pull request Apr 1, 2019
@MarekM25
Copy link
Contributor Author

MarekM25 commented Apr 1, 2019

@MarekM25 sorry for such a delay, I had to verify this branch on different laptops. It works great! Thanks for your contribution!

Thx, it was pleasure for me!

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