forked from LLNL/Caliper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathci_test_thread.cpp
54 lines (35 loc) · 1.51 KB
/
ci_test_thread.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
// --- Caliper continuous integration test app: threads
#include "caliper/cali.h"
#include "caliper/Caliper.h"
#include "caliper/common/RuntimeConfig.h"
#include <pthread.h>
cali_id_t thread_attr_id = CALI_INV_ID;
void* thread_proc(void* arg)
{
CALI_CXX_MARK_FUNCTION;
int thread_id = *(static_cast<int*>(arg));
cali_set_int(thread_attr_id, thread_id);
return NULL;
}
int main()
{
CALI_CXX_MARK_FUNCTION;
thread_attr_id = cali_create_attribute("my_thread_id", CALI_TYPE_INT, CALI_ATTR_SCOPE_THREAD | CALI_ATTR_UNALIGNED);
cali::Caliper c;
cali::RuntimeConfig exp_nopthread_cfg;
exp_nopthread_cfg.set("CALI_SERVICES_ENABLE", "event,trace,recorder");
exp_nopthread_cfg.set("CALI_RECORDER_FILENAME", "stdout");
cali::Channel exp_nopthread = c.create_channel("exp_nopthread", exp_nopthread_cfg);
cali::RuntimeConfig exp_pthread_cfg;
exp_pthread_cfg.set("CALI_SERVICES_ENABLE", "event,trace,pthread,recorder");
exp_pthread_cfg.set("CALI_RECORDER_FILENAME", "stdout");
cali::Channel exp_pthread = c.create_channel("exp_pthread", exp_pthread_cfg);
int thread_ids[4] = { 16, 25, 36, 49 };
pthread_t thread[4];
cali::Annotation("local", CALI_ATTR_SCOPE_THREAD | CALI_ATTR_UNALIGNED).set(99);
cali::Annotation("global", CALI_ATTR_SCOPE_PROCESS | CALI_ATTR_UNALIGNED).set(999);
for (int i = 0; i < 4; ++i)
pthread_create(&thread[i], NULL, thread_proc, &thread_ids[i]);
for (int i = 0; i < 4; ++i)
pthread_join(thread[i], NULL);
}