forked from markparticle/WebServer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
56 lines (51 loc) · 1.44 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* @Author : mark
* @Date : 2020-06-20
* @copyleft Apache 2.0
*/
#include "../code/log/log.h"
#include "../code/pool/threadpool.h"
#include <features.h>
#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30
#include <sys/syscall.h>
#define gettid() syscall(SYS_gettid)
#endif
void TestLog() {
int cnt = 0, level = 0;
Log::Instance()->init(level, "./testlog1", ".log", 0);
for(level = 3; level >= 0; level--) {
Log::Instance()->SetLevel(level);
for(int j = 0; j < 10000; j++ ){
for(int i = 0; i < 4; i++) {
LOG_BASE(i,"%s 111111111 %d ============= ", "Test", cnt++);
}
}
}
cnt = 0;
Log::Instance()->init(level, "./testlog2", ".log", 5000);
for(level = 0; level < 4; level++) {
Log::Instance()->SetLevel(level);
for(int j = 0; j < 10000; j++ ){
for(int i = 0; i < 4; i++) {
LOG_BASE(i,"%s 222222222 %d ============= ", "Test", cnt++);
}
}
}
}
void ThreadLogTask(int i, int cnt) {
for(int j = 0; j < 10000; j++ ){
LOG_BASE(i,"PID:[%04d]======= %05d ========= ", gettid(), cnt++);
}
}
void TestThreadPool() {
Log::Instance()->init(0, "./testThreadpool", ".log", 5000);
ThreadPool threadpool(6);
for(int i = 0; i < 18; i++) {
threadpool.AddTask(std::bind(ThreadLogTask, i % 4, i * 10000));
}
getchar();
}
int main() {
TestLog();
TestThreadPool();
}