* Copyright (C) 2026 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export const LONG_TRACE_UPLOAD_CHUNK_SIZE_BYTES = 4 * 1024 * 1024;
export const LONG_TRACE_SESSION_BIND_TIMEOUT_MS = 5 * 1000;
export const LONG_TRACE_CLOSE_WAIT_MS = 2 * 1000;
export const LONG_TRACE_PREFETCH_LIMIT = 3;
export const LONG_TRACE_FALLBACK_PATH = '/longtrace-preprocess';
export const LONG_TRACE_FILE_NAME_SEPARATOR = '_';
export const LONG_TRACE_FILE_SUFFIX = '.htrace';
export const LONG_TRACE_HEADER_SIZE_BYTES = 1024;
export const LONG_TRACE_TOTAL_LENGTH_OFFSET_BYTES = 8;
export const LONG_TRACE_UINT32_BYTES = 4;
export const LONG_TRACE_UINT32_SHIFT_BITS = BigInt(32);
export const LONG_TRACE_UINT32_MASK = BigInt(0xffffffff);
export const LONG_TRACE_FIRST_PAGE_NUMBER = 1;
export const LONG_TRACE_PAGE_LOCKED_OPACITY = '0.7';
export const LONG_TRACE_PAGE_READY_OPACITY = '1';
export const LONG_TRACE_POINTER_EVENTS_AUTO = 'auto';
export const LONG_TRACE_POINTER_EVENTS_NONE = 'none';
export const LONG_TRACE_WASM_READ_CHUNK_BYTES = 48 * 1024 * 1024;
export const LONG_TRACE_MAX_FILE_LENGTH_BYTES = 400 * 1024 * 1024;
export const LONG_TRACE_PROGRESS_PERCENT_DECIMALS = 2;
export const LONG_TRACE_MESSAGE_TYPE_HELLO = 'HELLO';
export const LONG_TRACE_MESSAGE_TYPE_TRACE_META = 'TRACE_META';
export const LONG_TRACE_MESSAGE_TYPE_TRACE_END = 'TRACE_END';
export const LONG_TRACE_MESSAGE_TYPE_RESULT = 'RESULT';
export const LONG_TRACE_MESSAGE_TYPE_PATCH_PAYLOAD_END = 'PATCH_PAYLOAD_END';
export const LONG_TRACE_CHANNEL_UPLOAD = 'UPLOAD';
export const LONG_TRACE_CHANNEL_DOWNLOAD = 'DOWNLOAD';
export const LONG_TRACE_STATUS_NO_PATCH = 'NO_PATCH';
export const LONG_TRACE_STATUS_PATCH_READY = 'PATCH_READY';
export const LONG_TRACE_STATUS_ERROR = 'ERROR';
export const LONG_TRACE_REASON_SESSION_BOUND = 'SESSION_BOUND';
export type LongTracePreprocessStatus =
| typeof LONG_TRACE_STATUS_NO_PATCH
| typeof LONG_TRACE_STATUS_PATCH_READY
| typeof LONG_TRACE_STATUS_ERROR;
export type LongTraceChannel = typeof LONG_TRACE_CHANNEL_UPLOAD | typeof LONG_TRACE_CHANNEL_DOWNLOAD;
export const LONG_TRACE_NORMAL_MATCH_PATTERN = /_\d{8}_\d{6}_\d+\.htrace$/;
export const LONG_TRACE_SPECIAL_MATCH_PATTERN = /_(arkts|ebpf|hiperf)\.htrace$/;
export function buildLongTraceProgressMessage(done: number, total: number): string {
return `Extension service converting longtrace... Completed: (${done}/${total})`;
}
export function buildLongTracePageNotReadyMessage(pageNum: number): string {
return `Extension service converting, page ${pageNum} not ready`;
}