Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed Jul 4, 2024
1 parent a1b6c01 commit 29e9d80
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 9 additions & 3 deletions lib/device-log/ios-crash-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const REAL_DEVICE_MAGIC = '3620bbb0-fb9f-4b62-a668-896f2edc4d88';
const MAGIC_SEP = '/';
// The file format has been changed from '.crash' to '.ips' since Monterey.
const CRASH_REPORTS_GLOB_PATTERN = '**/*.@(crash|ips)';
// The size of a single diagnostic report might be hundreds of kilobytes.
// Thus we do not want to store too many items in the memory at once.
const MAX_RECENT_ITEMS = 20;

type TSerializedEntry = [string, number];

Expand All @@ -34,7 +37,10 @@ export class IOSCrashLog extends IOSLog<TSerializedEntry, TSerializedEntry> {
private _started: boolean;

constructor(opts: IOSCrashLogOptions) {
super({log: opts.log});
super({
log: opts.log,
maxBufferSize: MAX_RECENT_ITEMS,
});
this._udid = opts.udid;
this._realDeviceClient = this._udid
? new Pyidevice({
Expand Down Expand Up @@ -65,7 +71,7 @@ export class IOSCrashLog extends IOSLog<TSerializedEntry, TSerializedEntry> {
}

override async getLogs(): Promise<LogEntry[]> {
const crashFiles = await this.listCrashFiles();
const crashFiles = (await this.listCrashFiles()).slice(-MAX_RECENT_ITEMS);
const diffFiles = _.difference(crashFiles, this._recentCrashFiles);
if (_.isEmpty(diffFiles)) {
return [];
Expand Down Expand Up @@ -118,7 +124,7 @@ export class IOSCrashLog extends IOSLog<TSerializedEntry, TSerializedEntry> {
}

private async _gatherFromRealDevice(): Promise<string[]> {
if (!this._realDeviceClient || !this._realDeviceClient.assertExists(false)) {
if (!this._realDeviceClient || !await this._realDeviceClient.assertExists(false)) {
return [];
}

Expand Down
9 changes: 8 additions & 1 deletion lib/real-device-clients/py-ios-device-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { CertificateList } from '../commands/types';
// https://github.com/YueChen-C/py-ios-device

const BINARY_NAME = 'pyidevice';
const CRASH_REPORT_EXT = '.ips';

export interface PyideviceOptions extends BaseDeviceClientOptions {
udid: string;
Expand Down Expand Up @@ -92,7 +93,13 @@ export class Pyidevice extends BaseDeviceClient {

override async listCrashes(): Promise<string[]> {
const {stdout} = await this.execute(['crash', 'list']) as TeenProcessExecResult<string>;
return JSON.parse(stdout.replace(/'/g, '"')).filter((x: string) => !['.', '..'].includes(x));
// Example output:
// ['.', '..', 'SiriSearchFeedback-2023-12-06-144043.ips', '
// SiriSearchFeedback-2024-05-22-194219.ips', 'JetsamEvent-2024-05-23-225056.ips',
// 'JetsamEvent-2023-09-18-090920.ips', 'JetsamEvent-2024-05-16-054529.ips',
// 'Assistant']
return JSON.parse(stdout.replace(/'/g, '"'))
.filter((x: string) => x.endsWith(CRASH_REPORT_EXT));
}

override async exportCrash(name: string, dstFolder: string): Promise<void> {
Expand Down

0 comments on commit 29e9d80

Please sign in to comment.