Skip to content

add apis to read the performance data #562

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

Merged
merged 9 commits into from
Feb 25, 2017
Merged
Show file tree
Hide file tree
Changes from 8 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
12 changes: 12 additions & 0 deletions src/main/java/io/appium/java_client/MobileCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public class MobileCommand {
protected static final String GET_DEVICE_TIME;
protected static final String GET_SESSION;

protected static final String GET_PERFORMANCE_DATA;
protected static final String GET_SUPPORTED_PERFORMANCE_DATA_TYPES;


protected static final String HIDE_KEYBOARD;
protected static final String LOCK;
//iOS
Expand Down Expand Up @@ -92,6 +96,9 @@ public class MobileCommand {
GET_DEVICE_TIME = "getDeviceTime";
GET_SESSION = "getSession";

GET_PERFORMANCE_DATA = "getPerformanceData";
GET_SUPPORTED_PERFORMANCE_DATA_TYPES = "getSuppportedPerformanceDataTypes";

HIDE_KEYBOARD = "hideKeyboard";
LOCK = "lock";
SHAKE = "shake";
Expand Down Expand Up @@ -136,6 +143,11 @@ public class MobileCommand {
commandRepository.put(SET_SETTINGS, postC("/session/:sessionId/appium/settings"));
commandRepository.put(GET_DEVICE_TIME, getC("/session/:sessionId/appium/device/system_time"));
commandRepository.put(GET_SESSION,getC("/session/:sessionId/"));
commandRepository.put(GET_SUPPORTED_PERFORMANCE_DATA_TYPES,
postC("/session/:sessionId/appium/performanceData/types"));
commandRepository.put(GET_PERFORMANCE_DATA,
postC("/session/:sessionId/appium/getPerformanceData"));

//iOS
commandRepository.put(SHAKE, postC("/session/:sessionId/appium/device/shake"));
commandRepository.put(TOUCH_ID, postC("/session/:sessionId/appium/simulator/touch_id"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
public class AndroidDriver<T extends WebElement>
extends AppiumDriver<T>
implements PressesKeyCode, HasNetworkConnection, PushesFiles, StartsActivity,
FindsByAndroidUIAutomator<T>, LocksAndroidDevice, HasSettings, HasDeviceDetails {
FindsByAndroidUIAutomator<T>, LocksAndroidDevice, HasSettings, HasDeviceDetails,
HasSupportedPerformanceDataType {

private static final String ANDROID_PLATFORM = MobilePlatform.ANDROID;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,55 @@ public class AndroidMobileCommandHelper extends MobileCommand {
END_TEST_COVERAGE, prepareArguments(parameters, values));
}

/**
* returns the information type of the system state which is supported to read
* as like cpu, memory, network traffic, and battery.
* @return output - array like below
* [cpuinfo, batteryinfo, networkinfo, memoryinfo]
*
*/
public static Map.Entry<String, Map<String, ?>> getSupportedPerformanceDataTypesCommand() {
return new AbstractMap.SimpleEntry<>(
GET_SUPPORTED_PERFORMANCE_DATA_TYPES, ImmutableMap.<String, Object>of());
}

/**
* returns the resource usage information of the application. the resource is one of the system state
* which means cpu, memory, network traffic, and battery.
*
* @param packageName the package name of the application
* @param dataType the type of system state which wants to read.
* It should be one of the supported performance data types,
* the return value of the function "getSupportedPerformanceDataTypes"
* @param dataReadTimeout the number of attempts to read
* @return table of the performance data, The first line of the table represents the type of data.
* The remaining lines represent the values of the data.
* in case of battery info : [[power], [23]]
* in case of memory info :
* [[totalPrivateDirty, nativePrivateDirty, dalvikPrivateDirty, eglPrivateDirty, glPrivateDirty,
* totalPss, nativePss, dalvikPss, eglPss, glPss, nativeHeapAllocatedSize, nativeHeapSize],
* [18360, 8296, 6132, null, null, 42588, 8406, 7024, null, null, 26519, 10344]]
* in case of network info :
* [[bucketStart, activeTime, rxBytes, rxPackets, txBytes, txPackets, operations, bucketDuration,],
* [1478091600000, null, 1099075, 610947, 928, 114362, 769, 0, 3600000],
* [1478095200000, null, 1306300, 405997, 509, 46359, 370, 0, 3600000]]
* in case of network info :
* [[st, activeTime, rb, rp, tb, tp, op, bucketDuration],
* [1478088000, null, null, 32115296, 34291, 2956805, 25705, 0, 3600],
* [1478091600, null, null, 2714683, 11821, 1420564, 12650, 0, 3600],
* [1478095200, null, null, 10079213, 19962, 2487705, 20015, 0, 3600],
* [1478098800, null, null, 4444433, 10227, 1430356, 10493, 0, 3600]]
* in case of cpu info : [[user, kernel], [0.9, 1.3]]
* @throws Exception if the performance data type is not supported, thows Error
*/
public static Map.Entry<String, Map<String, ?>> getPerformanceDataCommand(
String packageName, String dataType, int dataReadTimeout) throws Exception {
String[] parameters = new String[] {"packageName", "dataType", "dataReadTimeout"};
Object[] values = new Object[] {packageName, dataType, dataReadTimeout};
return new AbstractMap.SimpleEntry<>(
GET_PERFORMANCE_DATA, prepareArguments(parameters, values));
}

/**
* This method forms a {@link java.util.Map} of parameters to
* Retrieve the display density of the Android device.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package io.appium.java_client.android;

import static io.appium.java_client.android.AndroidMobileCommandHelper.getPerformanceDataCommand;
import static io.appium.java_client.android.AndroidMobileCommandHelper.getSupportedPerformanceDataTypesCommand;

import io.appium.java_client.CommandExecutionHelper;
import io.appium.java_client.ExecutesMethod;

import java.util.List;

/**
* Created by hwangheeseon on 2017. 2. 2..
*/
Copy link
Member

Choose a reason for hiding this comment

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

@heeseon Can you remove these statements please?

public interface HasSupportedPerformanceDataType extends ExecutesMethod {

/**
* returns the information type of the system state which is supported to read
* as like cpu, memory, network traffic, and battery.
* @return output - array like below
* [cpuinfo, batteryinfo, networkinfo, memoryinfo]
*
*/
default List<String> getSupportedPerformanceDataTypes() {
return CommandExecutionHelper.execute(this, getSupportedPerformanceDataTypesCommand());
}

/**
* returns the resource usage information of the application. the resource is one of the system state
* which means cpu, memory, network traffic, and battery.
*
* @param packageName the package name of the application
* @param dataType the type of system state which wants to read.
* It should be one of the supported performance data types,
* the return value of the function "getSupportedPerformanceDataTypes"
* @param dataReadTimeout the number of attempts to read
* @return table of the performance data, The first line of the table represents the type of data.
* The remaining lines represent the values of the data.
* in case of battery info : [[power], [23]]
* in case of memory info :
* [[totalPrivateDirty, nativePrivateDirty, dalvikPrivateDirty, eglPrivateDirty, glPrivateDirty,
* totalPss, nativePss, dalvikPss, eglPss, glPss, nativeHeapAllocatedSize, nativeHeapSize],
* [18360, 8296, 6132, null, null, 42588, 8406, 7024, null, null, 26519, 10344]]
* in case of network info :
* [[bucketStart, activeTime, rxBytes, rxPackets, txBytes, txPackets, operations, bucketDuration,],
* [1478091600000, null, 1099075, 610947, 928, 114362, 769, 0, 3600000],
* [1478095200000, null, 1306300, 405997, 509, 46359, 370, 0, 3600000]]
* in case of network info :
* [[st, activeTime, rb, rp, tb, tp, op, bucketDuration],
* [1478088000, null, null, 32115296, 34291, 2956805, 25705, 0, 3600],
* [1478091600, null, null, 2714683, 11821, 1420564, 12650, 0, 3600],
* [1478095200, null, null, 10079213, 19962, 2487705, 20015, 0, 3600],
* [1478098800, null, null, 4444433, 10227, 1430356, 10493, 0, 3600]]
* in case of cpu info : [[user, kernel], [0.9, 1.3]]
* @throws Exception if the performance data type is not supported, thows Error
*/
default List<List<Object>> getPerformanceData(String packageName, String dataType, int dataReadTimeout)
throws Exception {
return CommandExecutionHelper.execute(this,
getPerformanceDataCommand(packageName, dataType, dataReadTimeout));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
import org.openqa.selenium.html5.Location;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


public class AndroidDriverTest extends BaseAndroidTest {

@Test public void getDeviceTimeTest() {
Expand Down Expand Up @@ -140,4 +143,43 @@ public class AndroidDriverTest extends BaseAndroidTest {
assertNotNull(driver.getDisplayDensity());
assertNotEquals(0, driver.getSystemBars().size());
}

@Test public void getSupportedPerformanceDataTypesTest() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok I used assertEquals

driver.startActivity("io.appium.android.apis", ".ApiDemos");

List<String> dataTypes = new ArrayList<String>();
dataTypes.add("cpuinfo");
dataTypes.add("memoryinfo");
dataTypes.add("batteryinfo");
dataTypes.add("networkinfo");

List<String> supportedPerformanceDataTypes = driver.getSupportedPerformanceDataTypes();

assertEquals(4, supportedPerformanceDataTypes.size());

for ( int i = 0 ; i < supportedPerformanceDataTypes.size() ; ++i) {
assertEquals(dataTypes.get(i), supportedPerformanceDataTypes.get(i));
}


}

@Test public void getPerformanceDataTest() throws Exception {
driver.startActivity("io.appium.android.apis", ".ApiDemos");

List<String> supportedPerformanceDataTypes = driver.getSupportedPerformanceDataTypes();

for (int i = 0 ; i < supportedPerformanceDataTypes.size() ; ++ i) {

String dataType = supportedPerformanceDataTypes.get(i);

List<List<Object>> valueTable = driver.getPerformanceData("com.example.android.apis", dataType, 60000);

for ( int j = 1 ; j < valueTable.size() ; ++ j) {
assertEquals(valueTable.subList(0,0).size(), valueTable.subList(j, j).size());
}
}

}

}