Skip to content

Commit 53b0e22

Browse files
committed
Merge branch 'master' into develop
2 parents c0c8383 + d23ba61 commit 53b0e22

File tree

4 files changed

+94
-7
lines changed

4 files changed

+94
-7
lines changed

examples/trace/demo/Makefile renamed to examples/trace/01_demo/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# of the source tree.
1919
#
2020

21-
PROJECT := examples/trace/demo
21+
PROJECT := examples/trace/01_demo
2222
EXE_NAME := ${PROJECT}
2323

2424
CPP_SRC_FILES := main.cpp

examples/trace/01_demo/main.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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

examples/trace/demo/main.cpp renamed to examples/trace/02_multi_threads/main.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
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
}
3738
void 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

4546
void Do() {
@@ -50,10 +51,11 @@ void Do() {
5051

5152
int 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();

0 commit comments

Comments
 (0)