python: Don't use Swig to cast stats

Call the stat visitor from the stat itself rather than casting stats
in Python. This reduces the number of ways visitors are called.

Change-Id: Ic4d0b7b32e3ab9897b9a34cd22d353f4da62d738
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Sascha Bischoff <sascha.bischoff@arm.com>
Reviewed-by: Curtis Dunham <curtis.dunham@arm.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-by: Joe Gross <joseph.gross@amd.com>
This commit is contained in:
Andreas Sandberg 2017-01-03 12:03:45 +00:00
parent abe7ef95cb
commit c8b1e8f1cf
2 changed files with 3 additions and 31 deletions

View file

@ -49,25 +49,13 @@ def initSimStats():
names = [] names = []
stats_dict = {} stats_dict = {}
stats_list = [] stats_list = []
raw_stats_list = []
def enable(): def enable():
'''Enable the statistics package. Before the statistics package is '''Enable the statistics package. Before the statistics package is
enabled, all statistics must be created and initialized and once enabled, all statistics must be created and initialized and once
the package is enabled, no more statistics can be created.''' the package is enabled, no more statistics can be created.'''
__dynamic_cast = []
for k, v in internal.stats.__dict__.iteritems():
if k.startswith('dynamic_'):
__dynamic_cast.append(v)
for stat in internal.stats.statsList(): global stats_list
for cast in __dynamic_cast: stats_list = list(internal.stats.statsList())
val = cast(stat)
if val is not None:
stats_list.append(val)
raw_stats_list.append(val)
break
else:
fatal("unknown stat type %s", stat)
for stat in stats_list: for stat in stats_list:
if not stat.check() or not stat.baseCheck(): if not stat.check() or not stat.baseCheck():
@ -116,7 +104,7 @@ def dump():
if output.valid(): if output.valid():
output.begin() output.begin()
for stat in stats_list: for stat in stats_list:
output.visit(stat) stat.visit(output)
output.end() output.end()
def reset(): def reset():

View file

@ -46,12 +46,6 @@
#include "sim/stat_register.hh" #include "sim/stat_register.hh"
namespace Stats { namespace Stats {
template <class T>
inline T
cast_info(Info *info)
{
return dynamic_cast<T>(info);
}
inline FlagsType inline FlagsType
Stats_Info_flags_get(Info *info) Stats_Info_flags_get(Info *info)
@ -124,16 +118,6 @@ namespace std {
namespace Stats { namespace Stats {
template <class T> T cast_info(Info *info);
%template(dynamic_ScalarInfo) cast_info<ScalarInfo *>;
%template(dynamic_VectorInfo) cast_info<VectorInfo *>;
%template(dynamic_DistInfo) cast_info<DistInfo *>;
%template(dynamic_VectorDistInfo) cast_info<VectorDistInfo *>;
%template(dynamic_Vector2dInfo) cast_info<Vector2dInfo *>;
%template(dynamic_FormulaInfo) cast_info<FormulaInfo *>;
%template(dynamic_SparseHistInfo) cast_info<SparseHistInfo *>;
void initSimStats(); void initSimStats();
Output *initText(const std::string &filename, bool desc); Output *initText(const std::string &filename, bool desc);