-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtiming_analysis.cpp
101 lines (87 loc) · 2.77 KB
/
timing_analysis.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <string.h>
#include "timing_analysis.h"
#define REPORT_COUNT 1000
static void* timing_receive_task(void* c) {
setup_rt_task(30);
timing_analysis* s = (timing_analysis*)c;
s->receive_timing_messages();
}
timing_analysis::timing_analysis() {
// setup message queue attributes
attr.mq_maxmsg = MAX_MSG;
attr.mq_msgsize = MSG_SIZE;
attr.mq_flags = 0;
//set message queue priority default to 90
prio = 90;
clear_queue();
// Open message queue
timing_mq = mq_open((char*)MQ_TIMING, O_RDWR | O_CREAT, 0664, &attr);
if(timing_mq == ERROR){
perror("failed to open timing mq");
exit(-1);
}
if(pthread_create( &tMQTimingReceiver, NULL, &timing_receive_task, (void *)(this)) != 0) {
perror("Failed to create system message receiver task. Will exit now... " );
exit(-1);
}
timing_count = 0;
}
void timing_analysis::clear_queue() {
char message[4];
unsigned int priority;
timing_mq = mq_open((char*)MQ_TIMING, O_RDWR | O_CREAT | O_NONBLOCK, 0664, &attr);
if(timing_mq == ERROR){
perror("failed to open timing mq");
exit(-1);
}
while(mq_receive(timing_mq, message, MSG_SIZE, &priority) != ERROR);
mq_close(timing_mq);
}
timing_analysis::~timing_analysis() {
pthread_cancel(tMQTimingReceiver);
mq_close(timing_mq);
mq_unlink(MQ_TIMING);
}
void timing_analysis::receive_timing_messages(){
char message[4];
unsigned int priority;
ssize_t size;
MESSAGE* mess;
while(1){
if((size = mq_receive(timing_mq, message, MSG_SIZE, &priority)) == ERROR){
perror("System Recieve Failed!");
}else{
memcpy(&mess,message,4);
//mess = (message) ;
switch(mess->command){
case TIM_RELEASE_TIME:
timing_info[mess->from][mess->to].add_release_time((struct timespec*)mess->data);
break;
case TIM_END_TIME:
timing_info[mess->from][mess->to].add_end_time((struct timespec*)mess->data);
break;
default:
break;
}
if(timing_count >= REPORT_COUNT){
timing_count = 0;
std::cout << "Timing Information" << std::endl;
std::cout << "------------------" << std::endl;
for(int i=0;i<NUM_SUBSYSTEMS; i++) {
std::cout << "Subsystem: " << i << std::endl;
for(int j=0;j<NUM_TASKS; j++) {
if(timing_info[i][j].get_max_period() > 0.0){
std::cout << "Task: " << j << std::endl;
std::cout << "Period (avg, min, max): " << timing_info[i][j].get_average_period() << ", " << timing_info[i][j].get_min_period() << ", " << timing_info[i][j].get_max_period() << std::endl;
std::cout << "Execution (avg, min, max): " << timing_info[i][j].get_average_execution() << ", " << timing_info[i][j].get_min_execution() << ", " << timing_info[i][j].get_max_execution() << std::endl;
timing_info[i][j].reset_data();
}
}
}
}
timing_count++;
}
}
}
void timing_analysis::log_timing(char* message){
}