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

Commit 79fa423

Browse files
Implement app profiling functionality for android tests (#31)
1 parent d815c64 commit 79fa423

26 files changed

+981
-38
lines changed

migrations/001_create_table.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ var createSessionTable = function (queryInterface, Sequelize) {
5151
browser_name: { type: Sequelize.TEXT, allowNull: true },
5252
udid: { type: Sequelize.TEXT, allowNull: false },
5353
capabilities: { type: Sequelize.TEXT, allowNull: false },
54+
device_info: { type: Sequelize.TEXT, allowNull: true },
5455
is_completed: { type: Sequelize.BOOLEAN, defaultValue: false },
5556
start_time: { type: Sequelize.DATE, allowNull: false },
5657
end_time: { type: Sequelize.DATE, defaultValue: null },
5758
is_test_passed: { type: Sequelize.BOOLEAN, allowNull: true },
5859
is_paused: { type: Sequelize.BOOLEAN, allowNull: true, default: false },
60+
is_profiling_available: { type: Sequelize.BOOLEAN, allowNull: true, default: false },
5961
session_status: {
6062
type: Sequelize.ENUM,
6163
values: ["PASSED", "FAILED", "TIMEOUT", "RUNNING"],
@@ -99,17 +101,40 @@ var createCommandLogsTable = function (queryInterface, Sequelize) {
99101
});
100102
};
101103

104+
var createAppProfileTable = function (queryInterface, Sequelize) {
105+
return queryInterface.createTable("profiling", {
106+
session_id: { type: Sequelize.TEXT, references: { model: "session", key: "session_id" }, onDelete: "CASCADE" },
107+
id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true },
108+
timestamp: Sequelize.DATE,
109+
cpu: { type: Sequelize.TEXT, allowNull: false, defaultValue: "0" },
110+
memory: { type: Sequelize.TEXT, allowNull: false, defaultValue: "0" },
111+
total_cpu_used: { type: Sequelize.TEXT, allowNull: false, defaultValue: "0" },
112+
total_memory_used: { type: Sequelize.TEXT, allowNull: false, defaultValue: "0" },
113+
raw_cpu_log: { type: Sequelize.TEXT },
114+
raw_memory_log: { type: Sequelize.TEXT },
115+
created_at: Sequelize.DATE,
116+
updated_at: Sequelize.DATE,
117+
});
118+
};
119+
102120
module.exports = {
103121
up: (queryInterface, Sequelize) => {
104122
return promise.each(
105-
[createProjetsTable, createBuildsTable, createSessionTable, createLogsTable, createCommandLogsTable],
123+
[
124+
createProjetsTable,
125+
createBuildsTable,
126+
createSessionTable,
127+
createLogsTable,
128+
createCommandLogsTable,
129+
createAppProfileTable,
130+
],
106131
function (table) {
107132
return table(queryInterface, Sequelize);
108133
}
109134
);
110135
},
111136
down: (queryInterface, Sequelize) => {
112-
return promise.each(["logs", "command_logs", "projects", "build", "session"], function (table) {
137+
return promise.each(["profiling", "logs", "command_logs", "projects", "build", "session"], function (table) {
113138
return queryInterface.dropTable(table);
114139
});
115140
},

package-lock.json

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

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@ffmpeg-installer/ffmpeg": "^1.1.0",
3333
"@mui/icons-material": "^5.0.4",
3434
"@mui/material": "^5.0.4",
35+
"appium-adb": "^9.0.0",
3536
"appium-base-driver": "^7.10.1",
3637
"async-lock": "^1.3.0",
3738
"async-wait-until": "^2.0.12",
@@ -55,12 +56,14 @@
5556
},
5657
"devDependencies": {
5758
"@types/async-lock": "^1.1.3",
59+
"@types/bluebird": "^3.5.36",
5860
"@types/express": "^4.17.13",
5961
"@types/lodash": "^4.14.178",
6062
"@types/lokijs": "^1.5.7",
6163
"@types/node": "^16.10.2",
62-
"@types/uuid": "^8.3.1",
6364
"@types/node-fetch": "^3.0.3",
65+
"@types/teen_process": "^1.16.0",
66+
"@types/uuid": "^8.3.1",
6467
"typescript": "^4.4.4"
6568
}
6669
}

src/app/controllers/session-controller.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Session } from "../../models/session";
33
import { Op, Sequelize } from "sequelize";
44
import { BaseController } from "../commons/base-controller";
55
import fs from "fs";
6-
import { CommandLogs, Logs } from "../../models";
6+
import { CommandLogs, Logs, Profiling } from "../../models";
77
import * as path from "path";
88

99
export class SessionController extends BaseController {
@@ -16,6 +16,7 @@ export class SessionController extends BaseController {
1616
router.get("/:sessionId/logs/text", this.getTextLogs.bind(this));
1717
router.get("/:sessionId/logs/device", this.getDeviceLogs.bind(this));
1818
router.get("/:sessionId/logs/debug", this.getDebugLogs.bind(this));
19+
router.get("/:sessionId/profiling_data", this.getProfilingData.bind(this));
1920
}
2021

2122
public async getSessions(request: Request, response: Response, next: NextFunction) {
@@ -160,4 +161,24 @@ export class SessionController extends BaseController {
160161
}
161162
this.sendFailureResponse(response, "Screen shot not available");
162163
}
164+
165+
public async getProfilingData(request: Request, response: Response, next: NextFunction) {
166+
let sessionId: string = request.params.sessionId;
167+
let logs = await Profiling.findAll({
168+
attributes: [
169+
"timestamp",
170+
"cpu",
171+
"memory",
172+
"total_cpu_used",
173+
"total_memory_used",
174+
"raw_cpu_log",
175+
"raw_memory_log",
176+
],
177+
where: {
178+
session_id: sessionId,
179+
},
180+
order: [["timestamp", "ASC"]],
181+
});
182+
this.sendSuccessResponse(response, logs);
183+
}
163184
}

src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { config } from "./config";
66
import * as fs from "fs";
77
import { pluginLogger } from "./loggers/plugin-logger";
88
import { EventEmitter } from "events";
9+
import ADB from "appium-adb";
910

1011
const ffmpeg = require("@ffmpeg-installer/ffmpeg").path;
1112
const DebugEventNotifier = new EventEmitter();
@@ -22,6 +23,14 @@ Container.set("expressRouter", getRouter({ config, dependencies: { debugEventEmi
2223
Container.set("config", config);
2324

2425
(async () => {
26+
//Create ADB instance
27+
try {
28+
Container.set("adb", await ADB.createADB({}));
29+
} catch (ignore) {
30+
pluginLogger.error("Unable to create adb instance");
31+
pluginLogger.error(ignore);
32+
}
33+
2534
//Add FFMPEG to path
2635
process.env.PATH = process.env.PATH + ":" + ffmpeg.replace(/ffmpeg$/g, "");
2736

src/models/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export { Logs } from "./logs";
33
export { CommandLogs } from "./command-logs";
44
export { Build } from "./build";
55
export { Project } from "./project";
6+
export { Profiling } from "./profiling";

0 commit comments

Comments
 (0)