Skip to content
This repository was archived by the owner on Jul 10, 2024. It is now read-only.

Commit 1e411c8

Browse files
fix:app profiling issue for android API 28 and adb initialisation error (#50)
Fix #49, Fix #47
1 parent 036d43a commit 1e411c8

File tree

7 files changed

+123
-16
lines changed

7 files changed

+123
-16
lines changed

package-lock.json

Lines changed: 97 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"sequelize:migrate": "sequelize-cli db:migrate",
99
"sequelize:migrate:undo": "sequelize-cli db:migrate:undo",
1010
"clean:cache": "node ./scripts/cleanup-cache-dir.js",
11-
"postinstall": "(node ./scripts/is-prod.js || tsc) && npm run clean:cache && npm run sequelize:migrate",
11+
"postinstall": "(node ./scripts/is-prod.js || tsc) && npm run sequelize:migrate",
1212
"i": "tsc && (appium plugin uninstall appium-dashboard || exit 0) && appium plugin install --source=local $(pwd)",
1313
"start-appium": "appium --use-plugins=appium-dashboard --relaxed-security"
1414
},
@@ -29,6 +29,7 @@
2929
},
3030
"dependencies": {
3131
"@appium/base-plugin": "^1.8.0",
32+
"@appium/support": "^2.55.4",
3233
"@ffmpeg-installer/ffmpeg": "^1.1.0",
3334
"appium-adb": "^9.0.0",
3435
"appium-base-driver": "^7.10.1",

src/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ Container.set("config", config);
2424

2525
(async () => {
2626
//Create ADB instance
27+
let adb = null;
2728
try {
28-
Container.set("adb", await ADB.createADB({}));
29-
} catch (ignore) {
30-
pluginLogger.error("Unable to create adb instance");
31-
pluginLogger.error(ignore);
29+
adb = await ADB.createADB({});
30+
} catch (err) {
31+
pluginLogger.error("Unable to create adb instance.");
3232
}
3333

34+
Container.set("adb", adb);
3435
//Add FFMPEG to path
3536
process.env.PATH = process.env.PATH + ":" + ffmpeg.replace(/ffmpeg$/g, "");
3637

src/loggers/plugin-logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { logger } from "appium-support";
1+
import { logger } from "@appium/support";
22
const pluginLogger = logger.getLogger("appium-dashboard");
33
export { pluginLogger };

src/plugin/app-profiler/android-app-profiler.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,15 @@ class AndroidAppProfiler extends EventEmitter {
4545
"%CPU,RSS,ARGS",
4646
"-s",
4747
"1",
48-
"-m",
49-
"20",
5048
"-d",
5149
"1",
5250
];
51+
52+
/* -m argument is only suppoted after api level 28 */
53+
if (_.isNumber(this.deviceInfo.api_level) && this.deviceInfo.api_level >= 28) {
54+
cmd.push("-m", "20");
55+
}
56+
5357
this.proc = new SubProcess(this.adb.path, cmd);
5458
this.proc.on("exit", (code, signal) => {
5559
this.proc = null;
@@ -124,9 +128,17 @@ class AndroidAppProfiler extends EventEmitter {
124128
return {
125129
total_cpu: await this.getTotalCpus(),
126130
total_memory: await this.getTotalMemory(),
131+
api_level: await this.getAndroidApiLevel(),
127132
};
128133
}
129134

135+
private async getAndroidApiLevel() {
136+
//"-m","20",
137+
const args = [...this.adb.defaultArgs, "-s", this.deviceUDID, "shell", "getprop", "ro.build.version.sdk"];
138+
let out = await exec(this.adb.path, args);
139+
return Number(out.stdout.trim());
140+
}
141+
130142
private async getTotalCpus() {
131143
const args = [...this.adb.defaultArgs, "-s", this.deviceUDID, "shell", "cat", "/proc/cpuinfo"];
132144
let out = await exec(this.adb.path, args);

typings/appium-support/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
declare module "appium-support";
1+
declare module "@appium/support";

web/src/components/UI/organisms/session-app-profiling.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ function getCpuChartData(
135135

136136
/* Memory usage data */
137137
function getMemoryUsageChartOptions(session: Session) {
138+
const totalMemoryInMB = toMegaByte(session.device_info.total_memory);
138139
return {
139140
responsive: true,
140141
plugins: {
@@ -146,7 +147,7 @@ function getMemoryUsageChartOptions(session: Session) {
146147
},
147148
title: {
148149
display: true,
149-
text: "MEMORY",
150+
text: `MEMORY [${totalMemoryInMB} MB]`,
150151
},
151152
tooltip: {
152153
callbacks: {
@@ -164,9 +165,7 @@ function getMemoryUsageChartOptions(session: Session) {
164165
scales: {
165166
y: {
166167
min: 0,
167-
max:
168-
Math.round(toMegaByte(session.device_info.total_memory) / 1000) *
169-
1000,
168+
max: Math.ceil(totalMemoryInMB / 500) * 500, //round to nearest five hundred
170169
ticks: {
171170
stepSize: 500,
172171
},

0 commit comments

Comments
 (0)