File tree Expand file tree Collapse file tree 4 files changed +94
-7
lines changed Expand file tree Collapse file tree 4 files changed +94
-7
lines changed Original file line number Diff line number Diff line change 1818# of the source tree.
1919#
2020
21- PROJECT := examples/trace/demo
21+ PROJECT := examples/trace/01_demo
2222EXE_NAME := ${PROJECT}
2323
2424CPP_SRC_FILES := main.cpp
Original file line number Diff line number Diff line change 1+ /*
2+ * .============.
3+ * // M A K E / \
4+ * // C++ DEV / \
5+ * // E A S Y / \/ \
6+ * ++ ----------. \/\ .
7+ * \\ \ \ /\ /
8+ * \\ \ \ /
9+ * \\ \ \ /
10+ * -============'
11+ *
12+ * Copyright (c) 2024 Hevake and contributors, all rights reserved.
13+ *
14+ * This file is part of cpp-tbox (https://github.com/cpp-main/cpp-tbox)
15+ * Use of this source code is governed by MIT license that can be found
16+ * in the LICENSE file in the root of the source tree. All contributing
17+ * project authors may be found in the CONTRIBUTORS.md file in the root
18+ * of the source tree.
19+ */
20+
21+ #include < iostream>
22+ #include < tbox/base/recorder.h>
23+ #include < tbox/trace/sink.h>
24+
25+ void DoSomething ()
26+ {
27+ RECORD_SCOPE ();
28+ std::cout << " do something" << std::endl;
29+ }
30+
31+ int main (int argc, char **argv)
32+ {
33+ std::cout << " this is trace demo" << std::endl;
34+
35+ auto &ts = tbox::trace::Sink::GetInstance ();
36+ ts.setPathPrefix (" /tmp/trace/01_demo" ); // ! 设置记录文件目录前缀
37+ ts.setRecordFileMaxSize (1 <<20 ); // ! 设置记录文件大小为1MB
38+ ts.enable (); // ! 开始记录
39+
40+ RECORD_EVENT ();
41+
42+ std::cout << " begin" << std::endl;
43+
44+ DoSomething ();
45+
46+ std::cout << " end" << std::endl;
47+
48+ RECORD_EVENT ();
49+
50+ ts.disable (); // ! 停止记录
51+ return 0 ;
52+ }
Original file line number Diff line number Diff line change 1+ #
2+ # .============.
3+ # // M A K E / \
4+ # // C++ DEV / \
5+ # // E A S Y / \/ \
6+ # ++ ----------. \/\ .
7+ # \\ \ \ /\ /
8+ # \\ \ \ /
9+ # \\ \ \ /
10+ # -============'
11+ #
12+ # Copyright (c) 2024 Hevake and contributors, all rights reserved.
13+ #
14+ # This file is part of cpp-tbox (https://github.com/cpp-main/cpp-tbox)
15+ # Use of this source code is governed by MIT license that can be found
16+ # in the LICENSE file in the root of the source tree. All contributing
17+ # project authors may be found in the CONTRIBUTORS.md file in the root
18+ # of the source tree.
19+ #
20+
21+ PROJECT := examples/trace/02_multi_threads
22+ EXE_NAME := ${PROJECT}
23+
24+ CPP_SRC_FILES := main.cpp
25+
26+ CXXFLAGS := -DMODULE_ID='"$(EXE_NAME ) "' $(CXXFLAGS )
27+ LDFLAGS += \
28+ -ltbox_trace \
29+ -ltbox_util \
30+ -ltbox_base \
31+ -lpthread -ldl
32+
33+ include $(TOP_DIR ) /mk/exe_common.mk
Original file line number Diff line number Diff line change 2020
2121#include < thread>
2222#include < mutex>
23+ #include < iostream>
2324#include < tbox/base/recorder.h>
2425#include < tbox/trace/sink.h>
2526
@@ -31,15 +32,15 @@ void Bar()
3132{
3233 std::lock_guard<std::mutex> lg (g_lock);
3334 RECORD_SCOPE ();
34- std::this_thread::sleep_for (std::chrono::milliseconds (10 ));
35+ std::this_thread::sleep_for (std::chrono::microseconds (10 ));
3536 RECORD_SCOPE ();
3637}
3738void Foo ()
3839{
3940 RECORD_SCOPE ();
4041 Bar ();
4142 RECORD_SCOPE ();
42- std::this_thread::sleep_for (std::chrono::milliseconds (5 ));
43+ std::this_thread::sleep_for (std::chrono::microseconds (5 ));
4344}
4445
4546void Do () {
@@ -50,10 +51,11 @@ void Do() {
5051
5152int main (int argc, char **argv)
5253{
53- // ! 配置Track导出方式
54- auto &ts = trace::Sink::GetInstance ();
55- ts.setPathPrefix (" /tmp/test/trace-demo" );
56- ts.setRecordFileMaxSize (1 <<20 );
54+ std::cout << " this is trace multi-threads demo" << std::endl;
55+
56+ auto &ts = tbox::trace::Sink::GetInstance ();
57+ ts.setPathPrefix (" /tmp/trace/02_multi_threads" ); // ! 设置记录文件目录前缀
58+ ts.setRecordFileMaxSize (1 <<20 ); // ! 设置记录文件大小为1MB
5759 ts.enable (); // ! 开始记录
5860
5961 RECORD_EVENT ();
You can’t perform that action at this time.
0 commit comments