version 0.5.2
[fw/sdcc] / sim / ucsim / cmd.src / cmdstat.cc
1 /*
2  * Simulator of microcontrollers (cmd.src/cmdstat.cc)
3  *
4  * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
5  * 
6  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
7  *
8  */
9
10 /* This file is part of microcontroller simulator: ucsim.
11
12 UCSIM is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 UCSIM is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with UCSIM; see the file COPYING.  If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA. */
26 /*@1@*/
27
28 #include "ddconfig.h"
29
30 // prj
31 #include "globals.h"
32
33 // sim
34 #include "simcl.h"
35
36 // local
37 #include "cmdstatcl.h"
38
39
40 #ifdef STATISTIC
41 /*
42  * Command: statistic
43  *----------------------------------------------------------------------------
44  */
45
46 //int
47 //cl_stat_cmd::do_work(class cl_sim *sim,
48 //                     class cl_cmdline *cmdline, class cl_console *con)
49 COMMAND_DO_WORK_UC(cl_statistic_cmd)
50 {
51   class cl_hw *hw;
52   class cl_address_space *mem;
53   t_addr start= 0, end= 0;
54   bool addresses= DD_FALSE;
55   class cl_cmd_arg *params[4]= { cmdline->param(0),
56                                  cmdline->param(1),
57                                  cmdline->param(2),
58                                  cmdline->param(3) };
59
60   if (cmdline->syntax_match(uc, HW)) {
61     hw= params[0]->value.hw;
62   }
63   else {
64     mem= 0;
65     if (cmdline->syntax_match(uc, MEMORY ADDRESS ADDRESS)) {
66       mem= params[0]->value.memory.address_space;
67       start= params[1]->value.address;
68       end= params[2]->value.address;
69       addresses= DD_TRUE;
70     }
71     else if (cmdline->syntax_match(uc, MEMORY ADDRESS)) {
72       mem= params[0]->value.memory.address_space;
73       start= end= params[1]->value.address;
74       addresses= DD_TRUE;
75     }
76     else if (cmdline->syntax_match(uc, MEMORY)) {
77       mem= params[0]->value.memory.address_space;
78       addresses= DD_FALSE;
79     }
80     else
81       {
82         /*con->dd_printf("Error: wrong syntax\n"
83           "%s\n", short_help?short_help:"no help");*/
84         int i;
85         unsigned long wr, ww;
86         for (i= 0; i < uc->address_spaces->count; i++)
87           {
88             mem= (class cl_address_space *)(uc->address_spaces->at(i));
89             wr= mem->get_nuof_reads();
90             ww= mem->get_nuof_writes();
91             con->dd_printf("%s writes= %10lu "
92                            "reads= %10lu "
93                            "(%10lu operations)\n",
94                            mem->get_name("mem"), ww, wr, ww+wr);
95           }
96       }
97     if (mem)
98       {
99         t_addr i;
100         unsigned long wr, ww;
101         wr= mem->get_nuof_reads();
102         ww= mem->get_nuof_writes();
103         if (!addresses)
104           con->dd_printf("%s writes= %10lu "
105                          "reads= %10lu\n", mem->get_name("mem"), ww, wr);
106         else
107           for (i= start; i <= end; i++)
108             {
109               class cl_memory_cell *c= mem->get_cell(i);
110               unsigned long w= c->nuof_writes, r= c->nuof_reads;
111               double dr= wr?((double(r)*100.0)/double(wr)):0.0;
112               double dw= ww?((double(w)*100.0)/double(ww)):0.0;
113               con->dd_printf("%s[0x%06x] writes= %10lu (%6.2lf%%) "
114                              "reads= %10lu (%6.2lf%%)\n",
115                              mem->get_name("mem"), i, w, dw, r, dr);
116             }
117       }
118   }
119
120   return(DD_FALSE);;
121 }
122 #endif
123
124
125 /* End of cmd.src/cmdstat.cc */