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
50 #ifdef HAVE_SYS_TIMES_H
51 #include <sys/times.h>
54 #ifdef HAVE_SYS_RESOURCE_H
55 #include <sys/resource.h>
59 unsigned issue_count
[nr_itable_entries
];
62 function_unit_print
*func_unit_print
;
67 cpu_mon cpu_monitor
[MAX_NR_PROCESSORS
];
74 mon
*monitor
= ZALLOC(mon
);
83 if (cpu_nr
< 0 || cpu_nr
>= MAX_NR_PROCESSORS
)
84 error("mon_cpu() - invalid cpu number\n");
85 return &monitor
->cpu_monitor
[cpu_nr
];
90 mon_init(mon
*monitor
,
93 bzero(monitor
, sizeof(*monitor
));
94 monitor
->nr_cpus
= nr_cpus
;
99 mon_issue(itable_index index
,
103 cpu_mon
*monitor
= cpu_monitor(processor
);
104 ASSERT(index
<= nr_itable_entries
);
105 monitor
->issue_count
[index
] += 1;
107 if (WITH_FUNCTION_UNIT
)
108 function_unit_issue(index
, cpu_function_unit(processor
), cia
);
113 mon_read(unsigned_word ea
,
119 cpu_mon
*monitor
= cpu_monitor(processor
);
120 monitor
->read_count
+= 1;
125 mon_write(unsigned_word ea
,
131 cpu_mon
*monitor
= cpu_monitor(processor
);
132 monitor
->write_count
+= 1;
135 STATIC_INLINE_MON
unsigned
136 mon_get_number_of_insns(cpu_mon
*monitor
)
139 unsigned total_insns
= 0;
140 for (index
= 0; index
< nr_itable_entries
; index
++)
141 total_insns
+= monitor
->issue_count
[index
];
145 STATIC_INLINE_MON
char *
146 mon_add_commas(char *buf
,
151 char *endbuf
= buf
+ sizeof_buf
- 1;
161 *--endbuf
= (value
% 10) + '0';
162 } while ((value
/= 10) != 0);
164 ASSERT(endbuf
>= buf
);
170 mon_print_info(psim
*system
,
179 long total_insns
= 0;
180 long cpu_insns_second
= 0;
181 double cpu_time
= 0.0;
183 for (cpu_nr
= 0; cpu_nr
< monitor
->nr_cpus
; cpu_nr
++) {
184 unsigned num_insns
= mon_get_number_of_insns(&monitor
->cpu_monitor
[cpu_nr
]);
186 total_insns
+= num_insns
;
187 len
= strlen (mon_add_commas(buffer
, sizeof(buffer
), num_insns
));
192 sprintf (buffer
, "%d", (int)monitor
->nr_cpus
+ 1);
193 len_cpu
= strlen (buffer
);
195 #ifdef HAVE_GETRUSAGE
196 if (total_insns
&& verbose
> 1)
198 struct rusage mytime
;
199 if (getrusage (RUSAGE_SELF
, &mytime
) == 0
200 && (mytime
.ru_utime
.tv_sec
> 0 || mytime
.ru_utime
.tv_usec
> 0)) {
202 cpu_time
= (double)mytime
.ru_utime
.tv_sec
+ (((double)mytime
.ru_utime
.tv_usec
) / 1000000.0);
203 cpu_insns_second
= (long)(((double)total_insns
/ cpu_time
) + 0.5);
208 for (cpu_nr
= 0; cpu_nr
< monitor
->nr_cpus
; cpu_nr
++) {
214 printf_filtered ("\n");
216 for (index
= 0; index
< nr_itable_entries
; index
++) {
217 if (monitor
->cpu_monitor
[cpu_nr
].issue_count
[index
])
218 printf_filtered("CPU #%*d executed %*s %s instruction%s.\n",
220 len_num
, mon_add_commas(buffer
,
222 monitor
->cpu_monitor
[cpu_nr
].issue_count
[index
]),
224 (monitor
->cpu_monitor
[cpu_nr
].issue_count
[index
] == 1) ? "" : "s");
227 printf_filtered ("\n");
230 if (WITH_FUNCTION_UNIT
)
232 function_unit
*func_unit
= cpu_function_unit(psim_cpu(system
, cpu_nr
));
233 function_unit_print
*ptr
= function_unit_mon_info(func_unit
);
234 function_unit_print
*orig_ptr
= ptr
;
238 printf_filtered("CPU #%*d executed %*s %s%s.\n",
240 len_num
, mon_add_commas(buffer
,
245 ? ptr
->suffix_singular
246 : ptr
->suffix_plural
));
251 function_unit_mon_free(func_unit
, orig_ptr
);
254 if (monitor
->cpu_monitor
[cpu_nr
].read_count
)
255 printf_filtered ("CPU #%*d executed %*s data read%s.\n",
257 len_num
, mon_add_commas(buffer
,
259 monitor
->cpu_monitor
[cpu_nr
].read_count
),
260 (monitor
->cpu_monitor
[cpu_nr
].read_count
== 1) ? "" : "s");
262 if (monitor
->cpu_monitor
[cpu_nr
].write_count
)
263 printf_filtered ("CPU #%*d executed %*s data write%s.\n",
265 len_num
, mon_add_commas(buffer
,
267 monitor
->cpu_monitor
[cpu_nr
].write_count
),
268 (monitor
->cpu_monitor
[cpu_nr
].write_count
== 1) ? "" : "s");
270 printf_filtered("CPU #%*d executed %*s instructions in total.\n",
272 len_num
, mon_add_commas(buffer
,
274 mon_get_number_of_insns(&monitor
->cpu_monitor
[cpu_nr
])));
278 if (monitor
->nr_cpus
> 1)
279 printf_filtered("\nAll CPUs executed %s instructions in total.\n",
280 mon_add_commas(buffer
, sizeof(buffer
), total_insns
));
282 if (cpu_insns_second
)
283 printf_filtered ("%sSimulator speed was %s instructions/second\n",
284 (monitor
->nr_cpus
<= 1 && verbose
<= 1) ? "" : "\n",
285 mon_add_commas(buffer
, sizeof(buffer
), cpu_insns_second
));