diff --git a/record/record.js b/record/record.js index f98d2c5e68f908df746d27c7dfb4a74ab0787203..72d3f4a650e45f1ec735197c482213f656222138 100644 --- a/record/record.js +++ b/record/record.js @@ -127,15 +127,13 @@ function process(session_id, cmd, message) { output = params.output; traceName = output.split('/').reverse()[0]; configText = params.htraceCmd.split('< { @@ -285,7 +283,7 @@ function process(session_id, cmd, message) { } }; -function delLongDir() { +function delLongTrace() { return new Promise((resolve, reject) => { exec(`hdc shell ${killCmd}`, (error, stdout, stderr) => { if (error || (stderr && stderr.length > 0) || stdout.includes('[Fail]')) { @@ -298,51 +296,21 @@ function delLongDir() { resolve(0); logger.info(`Succeeded in killing the plug-in service`); }); - exec(`hdc shell rm -r /${ltOutput}/*`, (error, stdout, stderr) => { - logger.info(`delLongDir : ${error, stdout, stderr}`) + exec(`hdc shell rm -r /${ltOutput}/hiprofiler_data_*`, (error, stdout, stderr) => { + logger.info(`delLongTrace : ${error, stdout, stderr}`) if (error || (stderr && stderr.length > 0) || stdout.includes('[Fail]')) { const errorMsg = new Uint8Array(encoder.encode(stdout || error || stderr)); sendMsg(errorMsg, 3); reject(-1); - logger.error(`Failed to deleted long_trace folder`); + logger.error(`Failed to deleted long_trace file`); return; }; resolve(0); - logger.info(`Successfully deleted long_trace folder`); + logger.info(`Successfully deleted long_trace file`); }); }); } -function makeLongDir() { - return new Promise((resolve, reject) => { - exec(`hdc shell mkdir /${ltOutput}/`, (error, stdout, stderr) => { - if (error || (stderr && stderr.length > 0) || stdout.includes('[Fail]')) { - const errorMsg = new Uint8Array(encoder.encode(stdout || error || stderr)); - sendMsg(errorMsg, 3); - reject(-1); - logger.error(`Failed to created long_trace folder`); - return; - }; - resolve(0); - logger.info(`Successfully created long_trace folder`); - }); - - exec(`hdc shell ${chmodCmd} /${ltOutput}/`, (error, stdout, stderr) => { - logger.info(`delAndMakeDir : ${error, stdout, stderr}`) - if (error || (stderr && stderr.length > 0) || stdout.includes('[Fail]')) { - const errorMsg = new Uint8Array(encoder.encode(stdout || error || stderr)); - sendMsg(errorMsg, 3); - reject(-1); - logger.error(`Failed chmod longtrace`); - return; - }; - resolve(0); - logger.info(`successfully chmod longtrace`); - }); - }); -} - - function recordLongtrace() { return new Promise((resolve, reject) => { const hdc = spawn('hdc', ['-t', `${serialNum}`, 'shell', `${recordHitraceCmd}`]); @@ -368,7 +336,7 @@ function recordLongtrace() { function listLongtraceFiles() { return new Promise((resolve, reject) => { - const command = `hdc -t ${serialNum} shell ls ${ltOutput}`; + const command = `hdc -t ${serialNum} shell ls ${ltOutput}hiprofiler_data_*`; exec(command, (error, stdout, stderr) => { if (error) { reject(`列出失败: ${stderr}`); @@ -376,7 +344,7 @@ function listLongtraceFiles() { } const files = stdout.split('\n').filter(file => file.trim() !== ''); resolve(files); - logger.info(`列出成功:${files}`) + logger.info(`列出成功: ${files}`); }); }); } @@ -389,23 +357,17 @@ function sendLongtrace() { .then(() => { return listLongtraceFiles() .then(files => { - const savePath = `${directoryPath}/long_trace`; - if (fs.existsSync(savePath)) { - fs.rmSync(savePath, { recursive: true }); - } - fs.mkdirSync(savePath, { recursive: true }); - const allFiles = files.filter(file => file.trim() !== '' && file !== 'config.text\r'); - totalLength = allFiles.length; + const savePath = `${directoryPath}`; + totalLength = files.length; const transferPromises = files.map(fileName => { - const remoteFilePath = `${ltOutput}/${fileName}`; + const remoteFilePath = `${fileName}`; + const baseName = path.basename(remoteFilePath); return transferFile(serialNum, remoteFilePath, savePath) .then(() => { - if (fileName !== 'config.text\r') { - longtraceFiles.push({ - fileName: fileName, - localFilePath: `${directoryPath}\\long_trace\\${fileName}` - }); - } + longtraceFiles.push({ + fileName: baseName, + localFilePath: `${directoryPath}\\${baseName}` + }); }); }); return Promise.all(transferPromises); @@ -416,9 +378,7 @@ function sendLongtrace() { fileName: file.fileName.replace(/\r$/, ''), localFilePath: file.localFilePath.replace(/\r$/, '') })); - const readPromises = cleanedFiles.map(({ fileName, localFilePath }, index) => { - console.log('totalLength=>',totalLength) return readAndSendFile(fileName, localFilePath, totalLength); }); @@ -854,7 +814,7 @@ function pushConfigText() { }); // 将config文件推入手机里 logger.info(`config.text 文件推入手机开始`); - let cmd = isLongTrace ? `hdc -t ${serialNum} file send ${filePath} /${ltOutput}/config.text` : `hdc -t ${serialNum} file send ${filePath} /data/local/tmp/config.text` + let cmd = `hdc -t ${serialNum} file send ${filePath} /data/local/tmp/config.text`; exec(cmd, (error, stdout, stderr) => { if (stdout.includes('FileTransfer finish')) { logger.info(`config.text 文件推入手机结束`);