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

feat: Get Performance Data & Performance Data Types #422

Merged
merged 8 commits into from
Sep 7, 2020

Conversation

laolubenson
Copy link
Collaborator

closes #361

Change list

Please provide briefly described change list which are you going to propose.

Types of changes

What types of changes are you proposing/introducing to .NET client?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • New feature (non-breaking change which adds value to the project)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Documentation

  • Have you proposed a file change/ PR with appium to update documentation?

This can be done by navigating to the documentation section on http://appium.io selecting the appropriate command/endpoint and clicking the 'Edit this doc' link to update the C# example

Integration tests

  • Have you provided integration tests to pass against the beta version of appium? (for Bugfix or New feature)

Details

Adds support for getting performance data and performance data types on Android
Adds the following methods to AndroidDriver.cs

GetPerformanceDataTypes()
GetPerformanceData(packageName,dataType,dataReadTimeout)

Please provide more details about changes if it is necessary. If there are new features you can provide code samples which show the way they
work and possible use cases. Also you can create gists with pasted C# code samples or put them here using markdown.
About markdown please read Mastering markdown and Writing on GitHub

@laolubenson
Copy link
Collaborator Author

I couldn't get 'cpuinfo' to work/return a good response. An error occurred each time, so I commented out the assertion

@mykola-mokhnach
Copy link

@akinsolb Please provide the actual server error, perhaps I could fix it

/// [1478098800, null, null, 4444433, 10227, 1430356, 10493, 0, 3600]]
/// in case of cpu info : [[user, kernel], [0.9, 1.3]]
/// </returns>
IList<object> GetSupportPerformanceData(string packageName, string dataType, int dataReadTimeout = 0);

Choose a reason for hiding this comment

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

does zero value mean the timeout is not limited?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can't even remember the specification for the timeout. When I do, i'll add it to the xml documentation

Choose a reason for hiding this comment

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

actually, I've jus checked the source code. The argument name is confusing. The value means how many times the perf data retrieval operation should be retried in case of failure: https://github.com/appium/appium-android-driver/blob/c1a8ee54b69e14940d4c2ecb766be7f75235aba2/lib/commands/performance.js#L69

The default value is 2 with 1000ms delays between each retry

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If I set this to 0 the appium logs doesn't display a second attempt, it just returns null.

  1. I'm going to change the parameter to dataReadAttempts and update the param notes to make this clearer.
  2. Set the default value of dataReadAttempts to 1 because setting it to 0 returns null from the server (1.18).
  3. Prevent users from setting 0 as the default value

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

made the above changes

Choose a reason for hiding this comment

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

I would rather create an overloaded method without this parameter. As far as I can see it is optional, so you could just skip sending it to the server: https://github.com/appium/appium-base-driver/blob/eba4635dcd8fe81899c3349d7e474acfb66037e7/lib/protocol/routes.js#L380

Copy link
Collaborator Author

@laolubenson laolubenson Sep 5, 2020

Choose a reason for hiding this comment

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

I could either create an overload method or perform a check on the method parameter, as it's optional, it already works as an overload to users

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changes made

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

An alternative is making the dataReadAttempts argument nullable on the driver like so:

public IList<object> GetPerformanceData(string packageName, string performanceDataType, int? dataReadAttempts = null)
and checking for the value in the android command executor like so:

public static object[] GetPerformanceData(IExecuteMethod executeMethod, string packageName, string dataType, int? dataReadTimeout)

  `{
        var requiredKeys = new [] {"packageName", "dataType"};
        var requiredKeyValues = new object[] {packageName, dataType};
        if (dataReadTimeout is null)
            return executeMethod.Execute(AppiumDriverCommand.GetPerformanceData,
                PrepareArguments(requiredKeys, requiredKeyValues)).Value as object[];
        requiredKeys.SetValue("dataReadTimeout", 2);
        requiredKeyValues.SetValue(dataReadTimeout, 2);
        return executeMethod.Execute(AppiumDriverCommand.GetPerformanceData,
            PrepareArguments(requiredKeys, requiredKeyValues)).Value as object[];
    }`

@laolubenson
Copy link
Collaborator Author

@akinsolb Please provide the actual server error, perhaps I could fix it

https://gist.github.com/akinsolb/78d3343b39baf2f989f8e5a21c8c4a52 This is a run on an emulator (Android 10)

public IList<object> GetPerformanceData(string packageName, string performanceDataType,
int dataReadAttempts = 1)
{
if (dataReadAttempts < 1) throw new ArgumentException($"{nameof(dataReadAttempts)} must be greater than 0");

Choose a reason for hiding this comment

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

👍

@mykola-mokhnach
Copy link

I've pushed appium/appium-android-driver#659 to fix the issue #422 (comment)

You could check it out locally and verify now or wait until it's approved and is merged to beta

@laolubenson
Copy link
Collaborator Author

I've pushed appium/appium-android-driver#659 to fix the issue #422 (comment)

You could check it out locally and verify now or wait until it's approved and is merged to beta

Thanks. I'll wait till it's merged into beta.

Copy link

@mykola-mokhnach mykola-mokhnach left a comment

Choose a reason for hiding this comment

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

the cpuinfo fix has been published

@laolubenson laolubenson merged commit 5737c05 into appium:master Sep 7, 2020
@laolubenson laolubenson deleted the feature/performance-data branch September 7, 2020 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Get Performance Data endpoint
2 participants