MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
logproc.c File Reference
#include "mbconfig.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/user.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sched.h>
#include <errno.h>
Include dependency graph for logproc.c:

Go to the source code of this file.

Macros

#define KEEP_STATIC_INLINE
 

Functions

int main (int argc, char *argv[])
 

Macro Definition Documentation

#define KEEP_STATIC_INLINE

Definition at line 50 of file logproc.c.

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 60 of file logproc.c.

61 {
62  RT_TASK *logtask, *mbdtask;
63  MBX *mbxlog;
64  int i = 0, time = 0;
65  char *mbdynname;
66  char *mbxname;
67  int CpuMap;
68  struct data {
69  int step;
70  int time;
71  };
72  int dim = sizeof(struct data);
73  struct data msg;
74 
75  struct sched_param mysched;
76 
77  mysched.sched_priority = 1;
78 
79  if (argc != 5) {
80  fprintf(stderr, "INVALID NUMBER OF ARGUMENTS: ARGC=%d\n"
81  "\n"
82  "USAGE: logproc <MBDTSK> <MBXLOG> <CPUMAP> <NONROOT>\n",
83  argc);
84  exit(EXIT_FAILURE);
85  }
86 
87  mbdynname = argv[1];
88  mbxname = argv[2];
89  CpuMap = atoi(argv[3]);
90  if (strcasecmp(argv[4], "true") == 0) {
91  rt_allow_nonroot_hrt();
92 
93  } else if (strcasecmp(argv[4], "false" ) != 0) {
94  fprintf(stderr, "INVALID VALUE \"%s\" FOR NONROOT\n", argv[4]);
95  exit(EXIT_FAILURE);
96  }
97 
98  if (sched_setscheduler(0, SCHED_FIFO, &mysched) == -1) {
99  fputs("ERROR IN SETTING THE SCHEDULER UP", stderr);
100  perror("errno");
101  exit( 0 );
102  }
103 
104  mlockall(MCL_CURRENT | MCL_FUTURE);
105 
106  if (!(logtask = rt_task_init_schmod(nam2num("LTSK"), 20, 0, 0,
107  SCHED_FIFO, CpuMap)))
108  {
109  fputs("CANNOT INIT LOG TASK\n", stderr);
110  exit(EXIT_FAILURE);
111  }
112 
113  if (!(mbdtask = rt_get_adr(nam2num(mbdynname)))) {
114  fprintf(stderr, "CANNOT FIND MBDyn TASK \"%s\"\n", mbdynname);
115  exit(EXIT_FAILURE);
116  }
117 
118  rt_task_resume(mbdtask);
119 
120  if (!(mbxlog = rt_get_adr(nam2num(mbxname)))) {
121  fprintf(stderr, "CANNOT FIND LOG MBX\n");
122  exit(EXIT_FAILURE);
123  }
124 
125  printf("\n" "OVERRUNS MONITOR:\n");
126  printf(" step t [ns]\n");
127  while (!rt_mbx_receive(mbxlog, &msg, dim)) {
128  i++;
129  time += msg.time;
130  printf("%8d %8d %10d\n", i, msg.step, msg.time);
131  }
132 
133  rt_sleep(nano2count(1000000000));
134  rt_task_delete(logtask);
135  printf("\n\n" "OVERRUNS MONITOR:\n");
136  printf("Total overruns detected: %d\n", i);
137  printf("Mean overruns time: %6.2lf ns\n",
138  i ? ((double)time)/((double)i) : 0.);
139  printf("End of overruns monitor.\n");
140 
141  return 0;
142 }
struct mbrtai_msg_t msg