1 /* This file is part of the program psim.
3 Copyright (C) 1994-1995, Andrew Cagney <cagney@highland.com.au>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #ifndef STATIC_INLINE_MON
26 #define STATIC_INLINE_MON STATIC_INLINE
49 #ifdef HAVE_SYS_TIMES_H
50 #include <sys/times.h>
53 #ifdef HAVE_SYS_RESOURCE_H
54 #include <sys/resource.h>
58 unsigned issue_count
[nr_itable_entries
];
65 cpu_mon cpu_monitor
[MAX_NR_PROCESSORS
];
72 mon
*monitor
= ZALLOC(mon
);
81 if (cpu_nr
< 0 || cpu_nr
>= MAX_NR_PROCESSORS
)
82 error("mon_cpu() - invalid cpu number\n");
83 return &monitor
->cpu_monitor
[cpu_nr
];
88 mon_init(mon
*monitor
,
91 bzero(monitor
, sizeof(*monitor
));
92 monitor
->nr_cpus
= nr_cpus
;
97 mon_issue(itable_index index
,
101 cpu_mon
*monitor
= cpu_monitor(processor
);
102 ASSERT(index
<= nr_itable_entries
);
103 monitor
->issue_count
[index
] += 1;
108 mon_read(unsigned_word ea
,
114 cpu_mon
*monitor
= cpu_monitor(processor
);
115 monitor
->read_count
+= 1;
120 mon_write(unsigned_word ea
,
126 cpu_mon
*monitor
= cpu_monitor(processor
);
127 monitor
->write_count
+= 1;
131 STATIC_INLINE_MON
unsigned
132 mon_get_number_of_insns(cpu_mon
*monitor
)
135 unsigned total_insns
= 0;
136 for (index
= 0; index
< nr_itable_entries
; index
++)
137 total_insns
+= monitor
->issue_count
[index
];
141 STATIC_INLINE_MON
char *
142 mon_add_commas(char *buf
,
147 char *endbuf
= buf
+ sizeof_buf
- 1;
157 *--endbuf
= (value
% 10) + '0';
158 } while ((value
/= 10) != 0);
160 ASSERT(endbuf
>= buf
);
166 mon_print_info(mon
*monitor
,
174 long total_insns
= 0;
175 long cpu_insns_second
;
176 double cpu_time
= 0.0;
178 for (cpu_nr
= 0; cpu_nr
< monitor
->nr_cpus
; cpu_nr
++) {
179 unsigned num_insns
= mon_get_number_of_insns(&monitor
->cpu_monitor
[cpu_nr
]);
181 total_insns
+= num_insns
;
182 len
= strlen (mon_add_commas(buffer
, sizeof(buffer
), num_insns
));
187 sprintf (buffer
, "%d", (int)monitor
->nr_cpus
+ 1);
188 len_cpu
= strlen (buffer
);
190 #ifdef HAVE_GETRUSAGE
191 if (total_insns
&& verbose
> 1)
193 struct rusage mytime
;
194 if (getrusage (RUSAGE_SELF
, &mytime
) == 0
195 && (mytime
.ru_utime
.tv_sec
> 0 || mytime
.ru_utime
.tv_usec
> 0)) {
197 cpu_time
= (double)mytime
.ru_utime
.tv_sec
+ (((double)mytime
.ru_utime
.tv_usec
) / 1000000.0);
198 cpu_insns_second
= (long)(((double)total_insns
/ cpu_time
) + 0.5);
203 for (cpu_nr
= 0; cpu_nr
< monitor
->nr_cpus
; cpu_nr
++) {
209 printf_filtered ("\n");
211 for (index
= 0; index
< nr_itable_entries
; index
++) {
212 if (monitor
->cpu_monitor
[cpu_nr
].issue_count
[index
])
213 printf_filtered("CPU #%*d executed %*s %s instruction%s.\n",
215 len_num
, mon_add_commas(buffer
,
217 monitor
->cpu_monitor
[cpu_nr
].issue_count
[index
]),
219 (monitor
->cpu_monitor
[cpu_nr
].issue_count
[index
] == 1) ? "" : "s");
222 if (monitor
->cpu_monitor
[cpu_nr
].read_count
)
223 printf_filtered ("CPU #%*d executed %*s data reads.\n",
225 len_num
, mon_add_commas(buffer
,
227 monitor
->cpu_monitor
[cpu_nr
].read_count
));
229 if (monitor
->cpu_monitor
[cpu_nr
].write_count
)
230 printf_filtered ("CPU #%*d executed %*s data writes.\n",
232 len_num
, mon_add_commas(buffer
,
234 monitor
->cpu_monitor
[cpu_nr
].write_count
));
237 printf_filtered("CPU #%*d executed %*s instructions in total.\n",
239 len_num
, mon_add_commas(buffer
,
241 mon_get_number_of_insns(&monitor
->cpu_monitor
[cpu_nr
])));
244 if (monitor
->nr_cpus
> 1)
245 printf_filtered("\nAll CPUs executed %s instructions in total.\n",
246 mon_add_commas(buffer
, sizeof(buffer
), total_insns
));
248 if (cpu_insns_second
)
249 printf_filtered ("\nSimulator speed was %s instructions/second\n",
250 mon_add_commas(buffer
, sizeof(buffer
), cpu_insns_second
));
This page took 0.038894 seconds and 5 git commands to generate.