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