mirror of
https://github.com/openharmony/developtools_bytrace_standard.git
synced 2026-07-19 15:03:32 -04:00
add bytrace config file and napi impl
Signed-off-by: chuxuezhe11 <hanjixiao@huawei.com>
This commit is contained in:
@@ -68,6 +68,17 @@ ohos_executable("bytrace") {
|
||||
part_name = "bytrace_standard"
|
||||
}
|
||||
|
||||
ohos_prebuilt_etc("bytrace.cfg") {
|
||||
if (use_musl) {
|
||||
source = "./config/bytrace.cfg"
|
||||
} else {
|
||||
source = "./config/bytrace.rc"
|
||||
}
|
||||
relative_install_dir = "init"
|
||||
subsystem_name = "developtools"
|
||||
part_name = "bytrace_standard"
|
||||
}
|
||||
|
||||
group("bytrace_target") {
|
||||
deps = [ ":bytrace" ]
|
||||
}
|
||||
|
||||
Executable
+99
@@ -0,0 +1,99 @@
|
||||
{
|
||||
"jobs" : [{
|
||||
"name" : "post-init",
|
||||
"cmds" : [
|
||||
"write /proc/sys/kernel/sched_schedstats 1",
|
||||
"write /sys/kernel/debug/tracing/tracing_on 0",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/buffer_size_kb",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/saved_cmdlines_size",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/trace",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/trace_clock",
|
||||
"chmod 0222 /sys/kernel/debug/tracing/trace_marker",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/tracing_on",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_lock/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_locked/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_unlock/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_transaction/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_transaction_received/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_transaction_alloc_buf/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/cgroup/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/cpufreq_interactive/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/dma_fence/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/fence/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/i2c/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/i2c/i2c_read/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/i2c/i2c_write/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/i2c/i2c_result/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/i2c/i2c_reply/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/i2c/smbus_read/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/i2c/smbus_write/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/i2c/smbus_result/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/i2c/smbus_reply/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/kmem/rss_stat/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/kmem/ion_heap_grow/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/kmem/ion_heap_shrink/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/lowmemorykiller/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/lowmemorykiller/lowmemory_kill/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/mm_event/mm_event_record/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/oom/oom_score_adj_update/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/power/cpu_frequency/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/power/cpu_idle/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/power/clock_set_rate/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/power/cpu_frequency_limits/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/power/gpu_frequency/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_switch/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_wakeup/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_blocked_reason/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_cpu_hotplug/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_pi_setprio/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_process_exit/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_waking/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/signal/signal_generate/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/signal/signal_deliver/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/sync/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/task/task_rename/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/task/task_newtask/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/vmscan/mm_vmscan_direct_reclaim_begin/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/vmscan/mm_vmscan_direct_reclaim_end/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/vmscan/mm_vmscan_kswapd_wake/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/vmscan/mm_vmscan_kswapd_sleep/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/block/block_rq_issue/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/block/block_rq_complete/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/ext4/ext4_da_write_begin/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/ext4/ext4_da_write_end/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/ext4/ext4_es_lookup_extent_enter/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/ext4/ext4_es_lookup_extent_exit/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/ext4/ext4_load_inode/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/ext4/ext4_sync_file_enter/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/ext4/ext4_sync_file_exit/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/f2fs/f2fs_get_data_block/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/f2fs/f2fs_iget/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/f2fs/f2fs_sync_file_enter/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/f2fs/f2fs_sync_file_exit/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/f2fs/f2fs_write_begin/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/f2fs/f2fs_write_end/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/filemap/mm_filemap_add_to_page_cache/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/events/filemap/mm_filemap_delete_from_page_cache/enable",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/options/overwrite",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/options/print-tgid",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/options/record-tgid",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu0/trace",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu1/trace",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu2/trace",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu3/trace",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu4/trace",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu5/trace",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu6/trace",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu7/trace",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu8/trace",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu9/trace",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu10/trace",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu11/trace",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu12/trace",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu13/trace",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu14/trace",
|
||||
"chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu15/trace"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Executable
+119
@@ -0,0 +1,119 @@
|
||||
# Copyright (c) 2021 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.
|
||||
|
||||
on late-init
|
||||
write /proc/sys/kernel/sched_schedstats 1
|
||||
|
||||
write /sys/kernel/debug/tracing/tracing_on 0
|
||||
chmod 0666 /sys/kernel/debug/tracing/buffer_size_kb
|
||||
chmod 0666 /sys/kernel/debug/tracing/saved_cmdlines_size
|
||||
chmod 0666 /sys/kernel/debug/tracing/trace
|
||||
chmod 0666 /sys/kernel/debug/tracing/trace_clock
|
||||
chmod 0222 /sys/kernel/debug/tracing/trace_marker
|
||||
chmod 0666 /sys/kernel/debug/tracing/tracing_on
|
||||
|
||||
# ftrace events
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_lock/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_locked/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_unlock/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_transaction/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_transaction_received/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_transaction_alloc_buf/enable
|
||||
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/cgroup/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/cpufreq_interactive/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/dma_fence/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/fence/enable
|
||||
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/i2c/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/i2c/i2c_read/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/i2c/i2c_write/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/i2c/i2c_result/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/i2c/i2c_reply/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/i2c/smbus_read/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/i2c/smbus_write/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/i2c/smbus_result/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/i2c/smbus_reply/enable
|
||||
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/kmem/rss_stat/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/kmem/ion_heap_grow/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/kmem/ion_heap_shrink/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/lowmemorykiller/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/lowmemorykiller/lowmemory_kill/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/mm_event/mm_event_record/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/oom/oom_score_adj_update/enable
|
||||
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/power/cpu_frequency/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/power/cpu_idle/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/power/clock_set_rate/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/power/cpu_frequency_limits/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/power/gpu_frequency/enable
|
||||
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_switch/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_wakeup/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_blocked_reason/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_cpu_hotplug/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_pi_setprio/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_process_exit/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_waking/enable
|
||||
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/signal/signal_generate/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/signal/signal_deliver/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/sync/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/task/task_rename/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/task/task_newtask/enable
|
||||
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/vmscan/mm_vmscan_direct_reclaim_begin/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/vmscan/mm_vmscan_direct_reclaim_end/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/vmscan/mm_vmscan_kswapd_wake/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/vmscan/mm_vmscan_kswapd_sleep/enable
|
||||
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/block/block_rq_issue/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/block/block_rq_complete/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/ext4/ext4_da_write_begin/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/ext4/ext4_da_write_end/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/ext4/ext4_es_lookup_extent_enter/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/ext4/ext4_es_lookup_extent_exit/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/ext4/ext4_load_inode/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/ext4/ext4_sync_file_enter/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/ext4/ext4_sync_file_exit/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/f2fs/f2fs_get_data_block/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/f2fs/f2fs_iget/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/f2fs/f2fs_sync_file_enter/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/f2fs/f2fs_sync_file_exit/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/f2fs/f2fs_write_begin/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/f2fs/f2fs_write_end/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/filemap/mm_filemap_add_to_page_cache/enable
|
||||
chmod 0666 /sys/kernel/debug/tracing/events/filemap/mm_filemap_delete_from_page_cache/enable
|
||||
|
||||
chmod 0666 /sys/kernel/debug/tracing/options/overwrite
|
||||
chmod 0666 /sys/kernel/debug/tracing/options/print-tgid
|
||||
chmod 0666 /sys/kernel/debug/tracing/options/record-tgid
|
||||
|
||||
# percpu
|
||||
chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu0/trace
|
||||
chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu1/trace
|
||||
chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu2/trace
|
||||
chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu3/trace
|
||||
chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu4/trace
|
||||
chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu5/trace
|
||||
chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu6/trace
|
||||
chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu7/trace
|
||||
chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu8/trace
|
||||
chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu9/trace
|
||||
chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu10/trace
|
||||
chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu11/trace
|
||||
chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu12/trace
|
||||
chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu13/trace
|
||||
chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu14/trace
|
||||
chmod 0666 /sys/kernel/debug/tracing/per_cpu/cpu15/trace
|
||||
@@ -81,7 +81,7 @@ uint64_t GetSysParamTags()
|
||||
return 0;
|
||||
}
|
||||
|
||||
tags = IsAppValid() ? (tags | BYTRACE_TAG_APP) : (tags & (~BYTRACE_TAG_APP));
|
||||
IsAppValid();
|
||||
return (tags | BYTRACE_TAG_ALWAYS) & BYTRACE_TAG_VALID_MASK;
|
||||
}
|
||||
|
||||
|
||||
+34
-57
@@ -14,89 +14,66 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides interfaces to generate {@code ByTrace} logs.
|
||||
* Provides interfaces to trace a task for performance measure, the logs can be capture by the
|
||||
* bytrace cmdline available on the device.
|
||||
*
|
||||
* <p>This class traces the start, end, and value changes of key processes that last for at least 3 ms.
|
||||
* <p>This interfaces trace the start, end, and value changes of key processes that last for at least 3 ms.
|
||||
*
|
||||
* <p>Example:
|
||||
* To trace a name verification that is expected to complete within 5 ms:
|
||||
* <pre>{@code
|
||||
* Bytrace.startTrace("checkName", "5");
|
||||
* Bytrace.finishTrace("checkName");
|
||||
* bytrace.startTrace("checkName", 111, 5);
|
||||
* //your process
|
||||
* bytrace.finishTrace("checkName", 111);
|
||||
* }</pre>
|
||||
* To trace the number of layers, which is 3:
|
||||
* <pre>{@code
|
||||
* Bytrace.count("curLayer", 3);
|
||||
* bytrace.traceByValue("curLayer", 3);
|
||||
* }</pre>
|
||||
*
|
||||
* <p>Each {@code startTrace} matches one {@code finishTrace}, and they must have the same value.
|
||||
* <p>Each {@code startTrace} matches one {@code finishTrace}, and they must have the same name
|
||||
* and taskId.
|
||||
*
|
||||
* @since 1
|
||||
* @SysCap SystemCapability.Developtools.Bytrace
|
||||
* @devices phone, tablet
|
||||
* @since 7
|
||||
*/
|
||||
declare namespace bytrace {
|
||||
/**
|
||||
* Updates the trace label when your process has started.
|
||||
*/
|
||||
function updateTraceLabel(): void;
|
||||
|
||||
/**
|
||||
* Records a trace with the expected completion time and marks it as the start of a task.
|
||||
* Records a trace marking it as the start of a task, can with the expected completion time between
|
||||
* startTrace and finishTrace.
|
||||
*
|
||||
* This method is invoked at the start of a transaction to indicate that a task whose name is specified by
|
||||
* {@code value} has started. The {@link #finishTrace(String)} method using the same {@code value} must be
|
||||
* invoked at the end of the transaction.
|
||||
* This method is invoked at the start of a transaction to indicate that a task has started, whose name
|
||||
* is specified by {@code name}, and the taskId is used to distinguish the tasks. It must be followed by
|
||||
* {@link #finishTrace}, the name and taskId need to be the same.
|
||||
*
|
||||
* @param value Indicates the operation name.
|
||||
* @param limit Indicates the expected time required for completing the operation, in milliseconds.
|
||||
* @param name Indicates the task name.
|
||||
* @param taskId The unique id used to distinguish the tasks and match with the id in follow finishTrace.
|
||||
* @param expectedTime Indicates the expected time required for completing the task, in milliseconds.
|
||||
* @since 7
|
||||
*/
|
||||
function startTrace(value: string, limit: number): void;
|
||||
|
||||
/**
|
||||
* Track the middle of a context. Match the previous function of StartTrace before it.
|
||||
*
|
||||
* @param beforeValue Indicates the matched startTrace vlaue.
|
||||
* @param afterValue Indicates the matched finishTrace value.
|
||||
*/
|
||||
function middleTrace(beforeValue: string, afterValue: string): void;
|
||||
function startTrace(name: string, taskId: number, expectedTime?: number): void;
|
||||
|
||||
/**
|
||||
* Records a trace and marks it as the end of a task.
|
||||
*
|
||||
* This method is invoked at the end of a transaction to indicate that a task whose name is specified by
|
||||
* {@code value} has ended. This method must be invoked after the {@link #startTrace(String, float)} or
|
||||
* {@link #startTrace(String)} method is invoked.
|
||||
*
|
||||
* @param value Indicates the operation name. It must be the same as the {@code value} of
|
||||
* {@link #startTrace(String, float)} or {@link #startTrace(String)}.
|
||||
* This method is invoked at the end of a transaction to indicate that a task has ended, whose name
|
||||
* is specified by {@code name}. This method must be invoked after the the startTrace.
|
||||
*
|
||||
* @param name Indicates the task name. It must be the same whith the {@code name} of startTrace.
|
||||
* @param taskId The unique id used to distinguish the tasks and must be the same whith the .
|
||||
* {@code taskId} of startTrace.
|
||||
* @since 7
|
||||
*/
|
||||
function finishTrace(value: string): void;
|
||||
|
||||
/**
|
||||
* Writes a async trace message and mark as start spot. The name and cookie
|
||||
* used to begin an event must be used to end it.
|
||||
*
|
||||
* @param value Message content.
|
||||
* @param taskId Unique identifier for distinguishing simultaneous events.
|
||||
* @param limit It is expected that the operation will be completed within the specified time period.
|
||||
*/
|
||||
function startAsyncTrace(value: string, taskId: number, limit: number): void;
|
||||
|
||||
/**
|
||||
* Writes a async trace message and mark as start spot. The name and cookie
|
||||
* used to begin an event must be used to end it.
|
||||
*
|
||||
* @param value Message content.
|
||||
* @param taskId Unique identifier for distinguishing simultaneous events.
|
||||
*/
|
||||
function finishAsyncTrace(value: string, taskId: number): void;
|
||||
function finishTrace(name: string, taskId: number): void;
|
||||
|
||||
/**
|
||||
* Records a trace for generating a count, such as clock pulse and the number of layers.
|
||||
*
|
||||
* @param name Indicates the operation name.
|
||||
* @param count Indicates the count of the operation.
|
||||
* @param name Indicates the name used to identify the count.
|
||||
* @param count Indicates the number of the count.
|
||||
* @since 7
|
||||
*/
|
||||
function countTrace(name: string, count: number): void;
|
||||
function traceByValue(name: string, count: number): void;
|
||||
}
|
||||
export default bytrace;
|
||||
export default bytrace;
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
# Copyright (c) 2021 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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//developtools/bytrace_standard/bytrace.gni")
|
||||
|
||||
ohos_shared_library("bytrace") {
|
||||
sources = [ "bytrace.cpp" ]
|
||||
deps = [
|
||||
"//foundation/ace/napi:ace_napi",
|
||||
"${innerkits_path}/native:bytrace_core",
|
||||
]
|
||||
external_deps = [
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
]
|
||||
|
||||
relative_install_dir = "module"
|
||||
|
||||
subsystem_name = "developtools"
|
||||
part_name = "bytrace_standard"
|
||||
}
|
||||
Executable
+146
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <hilog/log.h>
|
||||
#include "bytrace.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "napi/native_node_api.h"
|
||||
|
||||
using namespace OHOS::HiviewDFX;
|
||||
namespace {
|
||||
constexpr int ARGC_NUMBER_TWO = 2;
|
||||
constexpr int NAME_MAX_SIZE = 1024;
|
||||
}
|
||||
|
||||
static napi_value JSTraceStart(napi_env env, napi_callback_info info)
|
||||
{
|
||||
constexpr int ARGC_NUMBER_THREE = 3;
|
||||
size_t argc = ARGC_NUMBER_THREE;
|
||||
napi_value argv[ARGC_NUMBER_THREE];
|
||||
napi_value thisVar;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc == ARGC_NUMBER_TWO || argc == ARGC_NUMBER_THREE, "Wrong number of arguments");
|
||||
|
||||
napi_valuetype valueType;
|
||||
NAPI_CALL(env, napi_typeof(env, argv[0], &valueType));
|
||||
NAPI_ASSERT(env, valueType == napi_string, "First arg type error, should is string");
|
||||
char buf[NAME_MAX_SIZE] = {0};
|
||||
size_t len = 0;
|
||||
napi_get_value_string_utf8(env, argv[0], buf, NAME_MAX_SIZE, &len);
|
||||
std::string name = std::string{buf};
|
||||
|
||||
NAPI_CALL(env, napi_typeof(env, argv[1], &valueType));
|
||||
NAPI_ASSERT(env, valueType == napi_number, "Second arg type error, should is number");
|
||||
int taskId = 0;
|
||||
napi_get_value_int32(env, argv[1], &taskId);
|
||||
if (argc == ARGC_NUMBER_TWO) {
|
||||
StartAsyncTrace(BYTRACE_TAG_APP, name, taskId);
|
||||
} else {
|
||||
NAPI_CALL(env, napi_typeof(env, argv[ARGC_NUMBER_TWO], &valueType));
|
||||
NAPI_ASSERT(env, valueType == napi_number, "Third arg type error, should is number");
|
||||
double limit = 0;
|
||||
napi_get_value_double(env, argv[ARGC_NUMBER_TWO], &limit);
|
||||
StartAsyncTrace(BYTRACE_TAG_APP, name, taskId, limit);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static napi_value JSTraceFinish(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = ARGC_NUMBER_TWO;
|
||||
napi_value argv[ARGC_NUMBER_TWO];
|
||||
napi_value thisVar;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc == ARGC_NUMBER_TWO, "Wrong number of arguments");
|
||||
|
||||
napi_valuetype valueType;
|
||||
NAPI_CALL(env, napi_typeof(env, argv[0], &valueType));
|
||||
NAPI_ASSERT(env, valueType == napi_string, "First arg type error, should is string");
|
||||
char buf[NAME_MAX_SIZE] = {0};
|
||||
size_t len = 0;
|
||||
napi_get_value_string_utf8(env, argv[0], buf, NAME_MAX_SIZE, &len);
|
||||
std::string name = std::string{buf};
|
||||
|
||||
NAPI_CALL(env, napi_typeof(env, argv[1], &valueType));
|
||||
NAPI_ASSERT(env, valueType == napi_number, "Second arg type error, should is number");
|
||||
int taskId = 0;
|
||||
napi_get_value_int32(env, argv[1], &taskId);
|
||||
FinishAsyncTrace(BYTRACE_TAG_APP, name, taskId);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static napi_value JSTraceCount(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = ARGC_NUMBER_TWO;
|
||||
napi_value argv[ARGC_NUMBER_TWO];
|
||||
napi_value thisVar;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL));
|
||||
NAPI_ASSERT(env, argc == ARGC_NUMBER_TWO, "Wrong number of arguments");
|
||||
|
||||
napi_valuetype valueType;
|
||||
NAPI_CALL(env, napi_typeof(env, argv[0], &valueType));
|
||||
NAPI_ASSERT(env, valueType == napi_string, "First arg type error, should is string");
|
||||
char buf[NAME_MAX_SIZE] = {0};
|
||||
size_t len = 0;
|
||||
napi_get_value_string_utf8(env, argv[0], buf, NAME_MAX_SIZE, &len);
|
||||
std::string name = std::string{buf};
|
||||
|
||||
NAPI_CALL(env, napi_typeof(env, argv[1], &valueType));
|
||||
NAPI_ASSERT(env, valueType == napi_number, "Second arg type error, should is number");
|
||||
int64_t count = 0;
|
||||
napi_get_value_int64(env, argv[1], &count);
|
||||
CountTrace(BYTRACE_TAG_APP, name, count);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
EXTERN_C_START
|
||||
/*
|
||||
* function for module exports
|
||||
*/
|
||||
static napi_value BytraceInit(napi_env env, napi_value exports)
|
||||
{
|
||||
static napi_property_descriptor desc[] = {
|
||||
DECLARE_NAPI_FUNCTION("startTrace", JSTraceStart),
|
||||
DECLARE_NAPI_FUNCTION("finishTrace", JSTraceFinish),
|
||||
DECLARE_NAPI_FUNCTION("traceByValue", JSTraceCount),
|
||||
};
|
||||
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
|
||||
return exports;
|
||||
}
|
||||
EXTERN_C_END
|
||||
|
||||
/*
|
||||
* Module definition
|
||||
*/
|
||||
static napi_module bytrace_module = {
|
||||
.nm_version = 1,
|
||||
.nm_flags = 0,
|
||||
.nm_filename = "bytrace",
|
||||
.nm_register_func = BytraceInit,
|
||||
.nm_modname = "bytrace",
|
||||
.nm_priv = ((void *)0),
|
||||
.reserved = {0}
|
||||
};
|
||||
|
||||
/*
|
||||
* Module registration
|
||||
*/
|
||||
extern "C" __attribute__((constructor)) void RegisterModule(void)
|
||||
{
|
||||
napi_module_register(&bytrace_module);
|
||||
}
|
||||
+3
-1
@@ -4,7 +4,9 @@
|
||||
"bytrace_standard": {
|
||||
"module_list": [
|
||||
"//developtools/bytrace_standard/interfaces/innerkits/native:bytrace_core",
|
||||
"//developtools/bytrace_standard/bin:bytrace_target"
|
||||
"//developtools/bytrace_standard/bin:bytrace_target",
|
||||
"//developtools/bytrace_standard/bin:bytrace.cfg",
|
||||
"//developtools/bytrace_standard/interfaces/kits/js/napi:bytrace"
|
||||
],
|
||||
"inner_kits": [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user