diff --git a/compiler/src/ark_utils.ts b/compiler/src/ark_utils.ts index aa606a71d..24b4d7571 100644 --- a/compiler/src/ark_utils.ts +++ b/compiler/src/ark_utils.ts @@ -24,7 +24,11 @@ import { nameCacheMap, unobfuscationNamesObj, performancePrinter, - EventList + EventList, + endFilesEvent, + endSingleFileEvent, + startFilesEvent, + startSingleFileEvent, } from 'arkguard'; import { OH_MODULES, @@ -514,11 +518,11 @@ export interface ModuleInfo { export async function writeObfuscatedSourceCode(moduleInfo: ModuleInfo, logger: Object, projectConfig: Object, rollupNewSourceMaps: Object = {}): Promise { if (compileToolIsRollUp() && projectConfig.arkObfuscator) { - performancePrinter?.filesPrinter?.startEvent(moduleInfo.buildFilePath); + startFilesEvent(moduleInfo.buildFilePath); MemoryUtils.tryGC(); await writeArkguardObfuscatedSourceCode(moduleInfo, logger, projectConfig, rollupNewSourceMaps); MemoryUtils.tryGC(); - performancePrinter?.filesPrinter?.endEvent(moduleInfo.buildFilePath, undefined, true); + endFilesEvent(moduleInfo.buildFilePath, undefined, true); return; } mkdirsSync(path.dirname(moduleInfo.buildFilePath)); @@ -576,10 +580,10 @@ export async function writeArkguardObfuscatedSourceCode(moduleInfo: ModuleInfo, } = { packageDir, projectRootPath, localPackageSet, useNormalized, useTsHar }; let filePathObj = { buildFilePath: moduleInfo.buildFilePath, relativeFilePath: moduleInfo.relativeSourceFilePath }; try { - performancePrinter?.singleFilePrinter?.startEvent(EventList.OBFUSCATE, performancePrinter.timeSumPrinter, filePathObj.buildFilePath); + startSingleFileEvent(EventList.OBFUSCATE, performancePrinter.timeSumPrinter, filePathObj.buildFilePath); mixedInfo = await arkObfuscator.obfuscate(moduleInfo.content, filePathObj, previousStageSourceMap, historyNameCache, moduleInfo.originSourceFilePath, projectInfo); - performancePrinter?.singleFilePrinter?.endEvent(EventList.OBFUSCATE, performancePrinter.timeSumPrinter); + endSingleFileEvent(EventList.OBFUSCATE, performancePrinter.timeSumPrinter); } catch (err) { logger.error(red, `ArkTS:INTERNAL ERROR: Failed to obfuscate file '${moduleInfo.relativeSourceFilePath}' with arkguard. ${err}`); } diff --git a/compiler/src/fast_build/ark_compiler/common/ob_config_resolver.ts b/compiler/src/fast_build/ark_compiler/common/ob_config_resolver.ts index 97d1e7a5a..8176dea09 100644 --- a/compiler/src/fast_build/ark_compiler/common/ob_config_resolver.ts +++ b/compiler/src/fast_build/ark_compiler/common/ob_config_resolver.ts @@ -25,7 +25,9 @@ import { deleteLineInfoForNameString, mangleFilePath, unobfuscationNamesObj, - EventList + EventList, + endSingleFileEvent, + startSingleFileEvent } from 'arkguard'; import type { ArkObfuscator, @@ -149,17 +151,6 @@ function getFileNamesForScanningWhitelist(mergedObConfig: MergedConfig, allKeepF return keepFilesAndDependencies; } -/** - * Disable performance printer when the build mode is debug - */ -export function disablePerformancePrinter(): void { - if (performancePrinter !== undefined) { - performancePrinter.filesPrinter = undefined; - performancePrinter.singleFilePrinter = undefined; - performancePrinter.timeSumPrinter = undefined; - } -} - /** * Get namecache by path * @@ -230,8 +221,8 @@ export function setUnobfuscationNames( * Write out obfuscated files */ export function writeObfuscatedFile(newFilePath: string, content: string): void { - performancePrinter?.singleFilePrinter?.startEvent(EventList.WRITE_FILE, performancePrinter.timeSumPrinter); + startSingleFileEvent(EventList.WRITE_FILE, performancePrinter.timeSumPrinter); mkdirsSync(path.dirname(newFilePath)); fs.writeFileSync(newFilePath, content); - performancePrinter?.singleFilePrinter?.endEvent(EventList.WRITE_FILE, performancePrinter.timeSumPrinter, false, true); + endSingleFileEvent(EventList.WRITE_FILE, performancePrinter.timeSumPrinter, false, true); } \ No newline at end of file diff --git a/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts b/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts index c4f0e00e1..dcc25c236 100644 --- a/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts +++ b/compiler/src/fast_build/ark_compiler/common/process_ark_config.ts @@ -20,7 +20,10 @@ import { initObfuscationConfig, readProjectPropertiesByCollectedPaths, performancePrinter, - EventList + EventList, + blockPrinter, + endFilesEvent, + startFilesEvent, } from 'arkguard'; import { @@ -45,7 +48,7 @@ import { import { getArkBuildDir } from '../../../ark_utils'; import { checkAotConfig } from '../../../gen_aot'; import { projectConfig as mainProjectConfig } from '../../../../main'; -import { disablePerformancePrinter, type MergedConfig } from './ob_config_resolver'; +import type { MergedConfig } from './ob_config_resolver'; import type { ReseverdSetForArkguard } from 'arkguard'; type ArkConfig = { @@ -176,12 +179,12 @@ export function initArkProjectConfig(share: Object): Object { if (!isDebug(projectConfig)) { arkProjectConfig.useTsHar = mainProjectConfig.useTsHar; const logger: any = share.getLogger(OBFUSCATION_TOOL); - performancePrinter?.filesPrinter?.startEvent(EventList.OBFUSCATION_INITIALIZATION, performancePrinter.timeSumPrinter); + startFilesEvent(EventList.OBFUSCATION_INITIALIZATION, performancePrinter.timeSumPrinter); initObfuscationConfig(projectConfig, arkProjectConfig, logger); - performancePrinter?.filesPrinter?.endEvent(EventList.OBFUSCATION_INITIALIZATION, performancePrinter.timeSumPrinter); + endFilesEvent(EventList.OBFUSCATION_INITIALIZATION, performancePrinter.timeSumPrinter); } else { // Set performance printer to undefined in case we cannot disable it without obfuscation initialization - disablePerformancePrinter(); + blockPrinter(); } return arkProjectConfig; } diff --git a/compiler/src/fast_build/ark_compiler/module/module_source_file.ts b/compiler/src/fast_build/ark_compiler/module/module_source_file.ts index 86ed1c1ae..0e0cd134f 100644 --- a/compiler/src/fast_build/ark_compiler/module/module_source_file.ts +++ b/compiler/src/fast_build/ark_compiler/module/module_source_file.ts @@ -66,7 +66,14 @@ import { localPackageSet } from '../../../ets_checker'; import { projectConfig } from '../../../../main'; -import { performancePrinter, EventList } from 'arkguard'; +import { + EventList, + endFilesEvent, + performancePrinter, + printTimeSumData, + printTimeSumInfo, + startFilesEvent +} from 'arkguard'; const ROLLUP_IMPORT_NODE: string = 'ImportDeclaration'; const ROLLUP_EXPORTNAME_NODE: string = 'ExportNamedDeclaration'; const ROLLUP_EXPORTALL_NODE: string = 'ExportAllDeclaration'; @@ -305,7 +312,7 @@ export class ModuleSourceFile { } collectAllFiles(undefined, rollupObject.getModuleIds(), rollupObject); - performancePrinter?.filesPrinter?.startEvent(EventList.SCAN_SOURCEFILES, performancePrinter.timeSumPrinter); + startFilesEvent(EventList.SCAN_SOURCEFILES, performancePrinter.timeSumPrinter); let sourceProjectConfig: Object = ModuleSourceFile.projectConfig; // obfuscation initialization, include collect file, resolve denpendency, read source if (compileToolIsRollUp()) { @@ -316,9 +323,9 @@ export class ModuleSourceFile { readProjectAndLibsSource(allSourceFilePaths, obfuscationConfig, sourceProjectConfig.arkObfuscator, sourceProjectConfig.compileHar, keepFilesAndDependencies); } - performancePrinter?.filesPrinter?.endEvent(EventList.SCAN_SOURCEFILES, performancePrinter.timeSumPrinter); + endFilesEvent(EventList.SCAN_SOURCEFILES, performancePrinter.timeSumPrinter); - performancePrinter?.filesPrinter?.startEvent(EventList.ALL_FILES_OBFUSCATION); + startFilesEvent(EventList.ALL_FILES_OBFUSCATION); let byteCodeHar = false; if (Object.prototype.hasOwnProperty.call(sourceProjectConfig, 'byteCodeHar')) { byteCodeHar = sourceProjectConfig.byteCodeHar; @@ -342,9 +349,9 @@ export class ModuleSourceFile { if (compileToolIsRollUp() && rollupObject.share.arkProjectConfig.compileMode === ESMODULE) { await mangleDeclarationFileName(ModuleSourceFile.logger, rollupObject.share.arkProjectConfig, sourceFileBelongProject); } - performancePrinter?.timeSumPrinter?.print('All files obfuscation:'); - performancePrinter?.timeSumPrinter?.summarizeEventDuration(); - performancePrinter?.filesPrinter?.endEvent(EventList.ALL_FILES_OBFUSCATION); + printTimeSumInfo('All files obfuscation:'); + printTimeSumData(); + endFilesEvent(EventList.ALL_FILES_OBFUSCATION); const eventObfuscatedCode = createAndStartEvent(parentEvent, 'write obfuscation name cache'); const needToWriteCache = compileToolIsRollUp() && sourceProjectConfig.arkObfuscator && sourceProjectConfig.obfuscationOptions;