MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
logproc.c
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/utils/logproc.c,v 1.23 2017/01/12 15:10:27 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 
32 /*
33  * Author: Michele Attolico <attolico@aero.polimi.it>
34  */
35 
36 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
37 
38 #include <stdio.h>
39 #include <stdlib.h>
40 
41 #include <unistd.h>
42 #include <sys/types.h>
43 #include <sys/user.h>
44 #include <sys/mman.h>
45 #include <sys/stat.h>
46 #include <fcntl.h>
47 #include <sched.h>
48 #include <errno.h>
49 
50 #define KEEP_STATIC_INLINE
51 
52 #if defined (HAVE_RTAI_LXRT_H)
53 #include <rtai_lxrt.h>
54 #include <rtai_mbx.h>
55 #else
56 #error "No rtai_lxrt_user and no rtai_lxrt within rtai"
57 #endif
58 
59 int
60 main(int argc, char* argv[])
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 }
143 
int main(int argc, char *argv[])
Definition: logproc.c:60