Skip to content

Commit a51e34f

Browse files
hydraxmanshbu
andauthored
Add performance test classes to provide interfaces and name definitions and uml (#231)
There is only new classes and comments checked in, so it's expected that we can remain the main trunk intact. Co-authored-by: shbu <shaopeng@microsoft.com>
1 parent e6907c4 commit a51e34f

File tree

14 files changed

+379
-1
lines changed

14 files changed

+379
-1
lines changed

common/doc/UML/perf_design.puml

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
@startuml
2+
'https://plantuml.com/class-diagram'
3+
4+
package "sdk" {
5+
6+
class PerformanceTestSpec {
7+
-String inspector
8+
-String appId
9+
-String deviceId
10+
-String name
11+
}
12+
interface PerformanceInspector {
13+
void initialize(PerformanceTestSpec performanceTestSpec)
14+
PerformanceInspectionResult inspect(PerformanceTestSpec performanceTestSpec)
15+
PerformanceTestResult parse(List<PerformanceInspectionResult>)
16+
}
17+
18+
interface IPerformanceInspectionService {
19+
void reset(PerformanceInspection);
20+
PerformanceInspectionResult inspect(PerformanceInspection);
21+
void inspectWithStrategy(PerformanceInspection, InspectionStrategy);
22+
List<PerformanceTestResult> parse();
23+
}
24+
25+
class PerformanceInspectionService {
26+
}
27+
28+
class PerformanceTestResult {
29+
String category
30+
Object performanceData
31+
List<PerformanceInspectionResult> performanceInspectionResultList
32+
}
33+
34+
class PerformanceInspectionResult {
35+
String type;
36+
File profilingRawResultFile;
37+
}
38+
39+
PerformanceInspector -left..> PerformanceTestSpec
40+
PerformanceInspector -up..> PerformanceInspectionResult
41+
PerformanceInspector <---right PerformanceInspectionService
42+
PerformanceInspector -up..> PerformanceTestResult
43+
PerformanceTestResult -right..> PerformanceInspectionResult
44+
PerformanceInspectionService -u-|> IPerformanceInspectionService
45+
}
46+
47+
package "agent" {
48+
abstract class TestRunner {
49+
}
50+
}
51+
52+
package "common" {
53+
class PerformanceTestManagementService {
54+
55+
}
56+
57+
PerformanceInspector <|-- AndroidBatteryInspector
58+
PerformanceInspector <|-- AndroidMemoryInfoInspector
59+
PerformanceInspector <|-- AndroidMemoryDumpInspector
60+
PerformanceInspector <|-- WindowsBatteryInspector
61+
PerformanceInspector <|-- WindowsMemoryInspector
62+
63+
AndroidBatteryInspector --o PerformanceTestManagementService
64+
AndroidMemoryInfoInspector --o PerformanceTestManagementService
65+
AndroidMemoryDumpInspector --o PerformanceTestManagementService
66+
WindowsBatteryInspector --o PerformanceTestManagementService
67+
WindowsMemoryInspector --o PerformanceTestManagementService
68+
PerformanceTestManagementService --|> IPerformanceInspectionService
69+
70+
TestRunner o-u- PerformanceTestManagementService
71+
}
72+
@enduml
73+
74+
@startuml
75+
participant PerformanceManager
76+
participant Runner
77+
participant PerformanceInspectionService
78+
participant AndroidMemoryInfoInspector
79+
participant AndroidBatteryInspector
80+
participant WindowsBatteryInspector
81+
82+
title Sequence 1: Regularly inspect performance metrics
83+
84+
PerformanceManager -> PerformanceManager: new Inspectors
85+
activate Runner
86+
Runner -> PerformanceInspectionService : new PerformanceInspectionService()
87+
activate PerformanceInspectionService
88+
Runner -> PerformanceManager: get Inspectors
89+
PerformanceManager -> Runner: Inspectors
90+
Runner -> PerformanceInspectionService : add Inspectors
91+
Runner -> PerformanceInspectionService : startInspectPerformanceTimer(performanceTestSpec, interval)
92+
PerformanceInspectionService -> AndroidMemoryInfoInspector : initialize
93+
PerformanceInspectionService -> AndroidBatteryInspector : initialize
94+
PerformanceInspectionService -> WindowsBatteryInspector : initialize
95+
PerformanceInspectionService -> AndroidMemoryInfoInspector : inspect
96+
AndroidMemoryInfoInspector -> PerformanceInspectionService : PerformanceInspectionResult
97+
PerformanceInspectionService -> AndroidBatteryInspector : inspect
98+
AndroidBatteryInspector -> PerformanceInspectionService : PerformanceInspectionResult
99+
PerformanceInspectionService -> WindowsBatteryInspector : inspect
100+
WindowsBatteryInspector -> PerformanceInspectionService : PerformanceInspectionResult
101+
Runner -> PerformanceInspectionService : parse
102+
PerformanceInspectionService -> AndroidMemoryInfoInspector : parse
103+
AndroidMemoryInfoInspector -> PerformanceInspectionService : PerformanceTestResult
104+
PerformanceInspectionService -> AndroidBatteryInspector : parse
105+
AndroidBatteryInspector -> PerformanceInspectionService : PerformanceTestResult
106+
PerformanceInspectionService -> WindowsBatteryInspector : parse
107+
WindowsBatteryInspector -> PerformanceInspectionService : PerformanceTestResult
108+
PerformanceInspectionService -> Runner: List<PerformanceTestResult>
109+
deactivate PerformanceInspectionService
110+
deactivate Runner
111+
@enduml
112+
113+
@startuml
114+
participant PerformanceManager
115+
participant Runner
116+
participant TestCase
117+
participant PerformanceInspectionService
118+
participant AndroidMemoryInfoInspector
119+
participant AndroidBatteryInspector
120+
participant WindowsBatteryInspector
121+
participant ThreadParam
122+
123+
title Sequence 2: Trigger performance metrics inspection by test case
124+
125+
PerformanceManager -> PerformanceManager: new Inspectors
126+
activate Runner
127+
Runner -> PerformanceInspectionService : new PerformanceInspectionService()
128+
activate PerformanceInspectionService
129+
Runner -> PerformanceManager: get Inspectors
130+
PerformanceManager -> Runner: Inspectors
131+
Runner -> PerformanceInspectionService : add Inspectors
132+
Runner -> ThreadParam: init(..., PerformanceInspectionService)
133+
activate ThreadParam
134+
Runner -> TestCase : execute
135+
activate TestCase
136+
TestCase -> ThreadParam : getPerformanceInspectionService
137+
ThreadParam -> TestCase : PerformanceInspectionService
138+
TestCase -> PerformanceInspectionService : initialize
139+
PerformanceInspectionService -> AndroidMemoryInfoInspector : initialize
140+
PerformanceInspectionService -> AndroidBatteryInspector : initialize
141+
PerformanceInspectionService -> WindowsBatteryInspector : initialize
142+
TestCase -> PerformanceInspectionService : inspect
143+
PerformanceInspectionService -> AndroidMemoryInfoInspector : inspect
144+
AndroidMemoryInfoInspector -> PerformanceInspectionService : PerformanceInspectionResult
145+
PerformanceInspectionService -> AndroidBatteryInspector : inspect
146+
AndroidBatteryInspector -> PerformanceInspectionService : PerformanceInspectionResult
147+
PerformanceInspectionService -> WindowsBatteryInspector : inspect
148+
WindowsBatteryInspector -> PerformanceInspectionService : PerformanceInspectionResult
149+
PerformanceInspectionService -> TestCase : List<PerformanceInspectionResult>
150+
TestCase -> Runner: return
151+
deactivate
152+
Runner -> PerformanceInspectionService : parse
153+
PerformanceInspectionService -> AndroidMemoryInfoInspector : parse
154+
AndroidMemoryInfoInspector -> PerformanceInspectionService : PerformanceTestResult
155+
PerformanceInspectionService -> AndroidBatteryInspector : parse
156+
AndroidBatteryInspector -> PerformanceInspectionService : PerformanceTestResult
157+
PerformanceInspectionService -> WindowsBatteryInspector : parse
158+
WindowsBatteryInspector -> PerformanceInspectionService : PerformanceTestResult
159+
PerformanceInspectionService -> Runner: List<PerformanceTestResult>
160+
deactivate PerformanceInspectionService
161+
Runner -> ThreadParam: clean
162+
deactivate ThreadParam
163+
deactivate Runner
164+
@enduml

common/src/main/java/com/microsoft/hydralab/common/entity/common/TestRun.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.alibaba.fastjson.JSONArray;
66
import com.alibaba.fastjson.JSONObject;
7+
import com.microsoft.hydralab.ITestRun;
78
import com.microsoft.hydralab.common.util.Const;
89
import lombok.Data;
910
import org.slf4j.Logger;
@@ -19,7 +20,7 @@
1920
@Entity
2021
@Table(name = "device_test_task", indexes = {
2122
@Index(name = "task_id_index", columnList = "test_task_id")})
22-
public class TestRun implements Serializable {
23+
public class TestRun implements Serializable, ITestRun {
2324
// private static Pattern testResultLine = Pattern.compile("Tests run:\\s+(\\d+),\\s+Failures:\\s+(\\d+)");
2425
// OK (8 tests)
2526
// private static Pattern testResultOkLine = Pattern.compile("OK\\s+\\((\\d+)\\s+tests\\)");
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.microsoft.hydralab.performance;
2+
3+
import com.microsoft.hydralab.ITestRun;
4+
import com.microsoft.hydralab.performance.inspectors.AndroidBatteryInfoInspector;
5+
import org.jetbrains.annotations.NotNull;
6+
import org.springframework.util.Assert;
7+
8+
import java.io.File;
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
import java.util.concurrent.ConcurrentHashMap;
12+
13+
public class PerformanceTestManagementService implements IPerformanceInspectionService {
14+
private final Map<String, PerformanceInspector> performanceInspectorMap = Map.of(
15+
PerformanceInspector.INSPECTOR_ANDROID_BATTERY_INFO, new AndroidBatteryInfoInspector()
16+
);
17+
private final Map<ITestRun, Map<String, PerformanceTestResult>> testRunPerfResultMap = new ConcurrentHashMap<>();
18+
19+
20+
public void initialize() {
21+
PerformanceInspectionService.getInstance().swapImplementation(this);
22+
}
23+
private PerformanceInspector getInspectorByName(String inspectorName) {
24+
return performanceInspectorMap.get(inspectorName);
25+
}
26+
@Override
27+
public PerformanceInspectionResult inspect(PerformanceInspection performanceInspection) {
28+
String inspector = performanceInspection.inspector;
29+
PerformanceInspector performanceInspector = getInspectorByName(inspector);
30+
Assert.notNull(performanceInspector, "Found no matched inspector: " + performanceInspection.inspector);
31+
ITestRun testRun = getTestRun();
32+
File performanceFolder = new File(testRun.getResultFolder(), "performance");
33+
Assert.isTrue(performanceFolder.mkdirs(), "performanceInspection.resultFolder.mkdirs() failed in " + performanceFolder.getAbsolutePath());
34+
performanceInspection.resultFolder = performanceFolder;
35+
36+
PerformanceInspectionResult result = performanceInspector.inspect(performanceInspection);
37+
38+
Map<String, PerformanceTestResult> performanceTestResultMap = testRunPerfResultMap.putIfAbsent(getTestRun(), new HashMap<>());
39+
Assert.notNull(performanceTestResultMap, "performanceTestResultMap should not be null ");
40+
PerformanceTestResult performanceTestResult = performanceTestResultMap.putIfAbsent(performanceInspection.inspectionKey, createPerformanceTestResult(performanceInspection));
41+
Assert.notNull(performanceTestResult, "performanceTestResult should not be null ");
42+
performanceTestResult.performanceInspectionResults.add(result);
43+
44+
return result;
45+
}
46+
47+
@NotNull
48+
private static PerformanceTestResult createPerformanceTestResult(PerformanceInspection performanceInspection) {
49+
PerformanceTestResult performanceTestResult = new PerformanceTestResult();
50+
performanceTestResult.inspector = performanceInspection.inspector;
51+
return performanceTestResult;
52+
}
53+
54+
/**
55+
* TODO
56+
* @return the test run object from TestRunThreadContext
57+
*/
58+
private ITestRun getTestRun() {
59+
return null;
60+
}
61+
62+
@Override
63+
public void inspectWithStrategy(PerformanceInspection performanceInspection, InspectionStrategy inspectionStrategy) {
64+
65+
}
66+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.microsoft.hydralab.performance.inspectors;
2+
3+
import com.microsoft.hydralab.performance.PerformanceInspection;
4+
import com.microsoft.hydralab.performance.PerformanceInspectionResult;
5+
import com.microsoft.hydralab.performance.PerformanceInspector;
6+
7+
public class AndroidBatteryInfoInspector implements PerformanceInspector {
8+
@Override
9+
public PerformanceInspectionResult inspect(PerformanceInspection performanceInspection) {
10+
return null;
11+
}
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.microsoft.hydralab;
2+
3+
import java.io.File;
4+
5+
public interface ITestRun {
6+
File getResultFolder();
7+
}

sdk/src/main/java/com/microsoft/hydralab/appium/ThreadParam.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
import java.util.Map;
66

7+
/**
8+
* TODO: rename this to TestRunThreadContext and move this above to package com.microsoft.hydralab
9+
*/
710
public class ThreadParam {
811
private static InheritableThreadLocal<AppiumParam> appiumParam = new InheritableThreadLocal<>();
912
private static InheritableThreadLocal<Map<String, String>> configMap = new InheritableThreadLocal<>();
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.microsoft.hydralab.performance;
2+
3+
public interface IPerformanceInspectionService {
4+
PerformanceInspectionResult inspect(PerformanceInspection performanceInspection);
5+
void inspectWithStrategy(PerformanceInspection performanceInspection, InspectionStrategy inspectionStrategy);
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.microsoft.hydralab.performance;
2+
3+
public class InspectionStrategy {
4+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.microsoft.hydralab.performance;
2+
3+
import java.io.File;
4+
5+
public class PerformanceInspection {
6+
public final String inspector;
7+
public final String appId;
8+
public final String deviceIdentifier;
9+
public final String name;
10+
public final String inspectionKey;
11+
File resultFolder;
12+
13+
public PerformanceInspection(String name, String inspector, String appId, String deviceIdentifier) {
14+
this.inspector = inspector;
15+
this.appId = appId;
16+
this.deviceIdentifier = deviceIdentifier;
17+
this.name = name;
18+
inspectionKey = String.format("%s-%s-%s", appId, deviceIdentifier, inspector);
19+
}
20+
21+
public static PerformanceInspection createAndroidBatteryInfoSpec(String appId, String deviceIdentifier) {
22+
return new PerformanceInspection(getNameByParam(PerformanceInspector.INSPECTOR_ANDROID_BATTERY_INFO, appId, deviceIdentifier),
23+
PerformanceInspector.INSPECTOR_ANDROID_BATTERY_INFO, appId, deviceIdentifier);
24+
}
25+
26+
private static String getNameByParam(String inspector, String appId, String deviceId) {
27+
return String.format("PerfTesting: get %s for %s on %s", inspector, appId, deviceId);
28+
}
29+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.microsoft.hydralab.performance;
2+
3+
public class PerformanceInspectionResult {
4+
}

0 commit comments

Comments
 (0)