xref: /base/hiviewdfx/hitrace/cmd/example/rust/main.rs (revision b0e7dd80)
1b0e7dd80Sopenharmony_ci/*
2b0e7dd80Sopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd.
3b0e7dd80Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4b0e7dd80Sopenharmony_ci * you may not use this file except in compliance with the License.
5b0e7dd80Sopenharmony_ci * You may obtain a copy of the License at
6b0e7dd80Sopenharmony_ci *
7b0e7dd80Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8b0e7dd80Sopenharmony_ci *
9b0e7dd80Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10b0e7dd80Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11b0e7dd80Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12b0e7dd80Sopenharmony_ci * See the License for the specific language governing permissions and
13b0e7dd80Sopenharmony_ci * limitations under the License.
14b0e7dd80Sopenharmony_ci */
15b0e7dd80Sopenharmony_ci
16b0e7dd80Sopenharmony_ci//! hitrace_meter example_crate for rust.
17b0e7dd80Sopenharmony_ciextern crate hitrace_meter_rust;
18b0e7dd80Sopenharmony_ciuse hitrace_meter_rust::{start_trace, finish_trace, start_trace_async, finish_trace_async, count_trace};
19b0e7dd80Sopenharmony_ciconst HITRACE_TAG_OHOS : u64 = 1 << 30;
20b0e7dd80Sopenharmony_ciconst HITRACE_TASK_ID : i32 = 666;
21b0e7dd80Sopenharmony_ci
22b0e7dd80Sopenharmony_ci/// example function A
23b0e7dd80Sopenharmony_cifn func_a() {
24b0e7dd80Sopenharmony_ci    println!("funcA!!!");
25b0e7dd80Sopenharmony_ci}
26b0e7dd80Sopenharmony_ci
27b0e7dd80Sopenharmony_ci/// example function B
28b0e7dd80Sopenharmony_cifn func_b() {
29b0e7dd80Sopenharmony_ci    println!("funcB!!!");
30b0e7dd80Sopenharmony_ci}
31b0e7dd80Sopenharmony_ci
32b0e7dd80Sopenharmony_ci/// trace example for rust
33b0e7dd80Sopenharmony_cifn main() {
34b0e7dd80Sopenharmony_ci    start_trace(HITRACE_TAG_OHOS, "rust test start trace funcA!!!!!!");
35b0e7dd80Sopenharmony_ci    func_a();
36b0e7dd80Sopenharmony_ci    count_trace(HITRACE_TAG_OHOS, "rust test count trace funcA!!!!!!", 0);
37b0e7dd80Sopenharmony_ci    finish_trace(HITRACE_TAG_OHOS);
38b0e7dd80Sopenharmony_ci
39b0e7dd80Sopenharmony_ci    start_trace_async(HITRACE_TAG_OHOS, "rust test start trace async funcB!!!!!!", HITRACE_TASK_ID);
40b0e7dd80Sopenharmony_ci    func_b();
41b0e7dd80Sopenharmony_ci    count_trace(HITRACE_TAG_OHOS, "rust test count trace funcB!!!!!!", 1);
42b0e7dd80Sopenharmony_ci    finish_trace_async(HITRACE_TAG_OHOS, "rust finish trace async funcB!!!!!!", HITRACE_TASK_ID);
43b0e7dd80Sopenharmony_ci}
44