2012-04-13 01:08:20 +00:00
|
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//*************************************************************************
|
|
|
|
|
// DESCRIPTION: Verilator: Collect and print statistics
|
|
|
|
|
//
|
2008-04-25 12:14:27 +00:00
|
|
|
|
// Code available from: http://www.veripool.org/verilator
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2019-01-04 00:17:22 +00:00
|
|
|
|
// Copyright 2005-2019 by Wilson Snyder. This program is free software; you can
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// redistribute it and/or modify it under the terms of either the GNU
|
2009-05-04 21:07:57 +00:00
|
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
|
// Version 2.0.
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//
|
|
|
|
|
// Verilator is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
2006-12-18 19:20:45 +00:00
|
|
|
|
#include "config_build.h"
|
|
|
|
|
#include "verilatedos.h"
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
#include "V3Global.h"
|
|
|
|
|
#include "V3Stats.h"
|
|
|
|
|
#include "V3Ast.h"
|
|
|
|
|
#include "V3File.h"
|
2017-09-18 02:52:57 +00:00
|
|
|
|
#include "V3Os.h"
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
2018-10-14 17:43:24 +00:00
|
|
|
|
#include <cstdarg>
|
|
|
|
|
#include <iomanip>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include VL_INCLUDE_UNORDERED_MAP
|
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//######################################################################
|
|
|
|
|
// Stats dumping
|
|
|
|
|
|
|
|
|
|
class StatsReport {
|
|
|
|
|
// TYPES
|
2018-02-02 02:24:41 +00:00
|
|
|
|
typedef std::vector<V3Statistic> StatColl;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
// STATE
|
2018-02-02 02:24:41 +00:00
|
|
|
|
std::ofstream& os; ///< Output stream
|
2006-08-26 11:35:28 +00:00
|
|
|
|
static StatColl s_allStats; ///< All statistics
|
|
|
|
|
|
|
|
|
|
void header() {
|
|
|
|
|
os<<"Verilator Statistics Report\n";
|
|
|
|
|
os<<endl;
|
|
|
|
|
|
|
|
|
|
os<<"Information:"<<endl;
|
2018-10-14 22:39:33 +00:00
|
|
|
|
os<<" "<<V3Options::version()<<endl;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
os<<" Arguments: "<<v3Global.opt.allArgsString()<<endl;
|
|
|
|
|
os<<endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void sumit() {
|
|
|
|
|
// If sumit is set on a statistic, combine with others of same name
|
2018-02-02 02:24:41 +00:00
|
|
|
|
typedef std::multimap<string,V3Statistic*> ByName;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
ByName byName;
|
|
|
|
|
// * is always first
|
|
|
|
|
for (StatColl::iterator it = s_allStats.begin(); it!=s_allStats.end(); ++it) {
|
|
|
|
|
V3Statistic* repp = &(*it);
|
|
|
|
|
byName.insert(make_pair(repp->name(), repp));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Process duplicates
|
|
|
|
|
V3Statistic* lastp = NULL;
|
|
|
|
|
for (ByName::iterator it = byName.begin(); it!=byName.end(); ++it) {
|
|
|
|
|
V3Statistic* repp = it->second;
|
|
|
|
|
if (lastp && lastp->sumit() && lastp->printit()
|
|
|
|
|
&& lastp->name() == repp->name() && lastp->stage() == repp->stage()) {
|
|
|
|
|
repp->combineWith(lastp);
|
|
|
|
|
}
|
|
|
|
|
lastp = repp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void stars() {
|
|
|
|
|
// Find all stages
|
|
|
|
|
size_t maxWidth = 0;
|
2018-02-02 02:24:41 +00:00
|
|
|
|
typedef std::multimap<string,const V3Statistic*> ByName;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
ByName byName;
|
|
|
|
|
// * is always first
|
|
|
|
|
for (StatColl::iterator it = s_allStats.begin(); it!=s_allStats.end(); ++it) {
|
|
|
|
|
const V3Statistic* repp = &(*it);
|
|
|
|
|
if (repp->stage() == "*" && repp->printit()) {
|
|
|
|
|
if (maxWidth < repp->name().length()) maxWidth = repp->name().length();
|
|
|
|
|
byName.insert(make_pair(repp->name(), repp));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Print organized by stage
|
2017-09-18 02:52:57 +00:00
|
|
|
|
os<<"Global Statistics:\n";
|
|
|
|
|
os<<endl;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
for (ByName::iterator it = byName.begin(); it!=byName.end(); ++it) {
|
|
|
|
|
const V3Statistic* repp = it->second;
|
2017-09-18 02:52:57 +00:00
|
|
|
|
if (repp->perf()) continue;
|
2018-02-02 02:24:41 +00:00
|
|
|
|
os<<" "<<std::left<<std::setw(maxWidth)<<repp->name();
|
2017-09-18 02:52:57 +00:00
|
|
|
|
repp->dump(os);
|
|
|
|
|
os<<endl;
|
|
|
|
|
}
|
|
|
|
|
os<<endl;
|
|
|
|
|
|
|
|
|
|
// Print organized by stage
|
2017-10-17 01:57:55 +00:00
|
|
|
|
os<<"Performance Statistics:\n";
|
2017-09-18 02:52:57 +00:00
|
|
|
|
os<<endl;
|
|
|
|
|
for (ByName::iterator it = byName.begin(); it!=byName.end(); ++it) {
|
|
|
|
|
const V3Statistic* repp = it->second;
|
|
|
|
|
if (!repp->perf()) continue;
|
2018-02-02 02:24:41 +00:00
|
|
|
|
os<<" "<<std::left<<std::setw(maxWidth)<<repp->name();
|
2006-08-26 11:35:28 +00:00
|
|
|
|
repp->dump(os);
|
|
|
|
|
os<<endl;
|
|
|
|
|
}
|
|
|
|
|
os<<endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void stages() {
|
|
|
|
|
os<<"Stage Statistics:\n";
|
|
|
|
|
|
|
|
|
|
// Find all stages
|
|
|
|
|
int stage=0;
|
|
|
|
|
size_t maxWidth = 0;
|
2018-02-02 02:24:41 +00:00
|
|
|
|
typedef std::vector<string> Stages;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
Stages stages;
|
2017-10-18 22:22:58 +00:00
|
|
|
|
vl_unordered_map<string,int> stageInt;
|
2018-02-02 02:24:41 +00:00
|
|
|
|
typedef std::multimap<string,const V3Statistic*> ByName;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
ByName byName;
|
|
|
|
|
// * is always first
|
|
|
|
|
for (StatColl::iterator it = s_allStats.begin(); it!=s_allStats.end(); ++it) {
|
|
|
|
|
const V3Statistic* repp = &(*it);
|
|
|
|
|
if (repp->stage() != "*" && repp->printit()) {
|
|
|
|
|
if (maxWidth < repp->name().length()) maxWidth = repp->name().length();
|
|
|
|
|
if (stageInt.find(repp->stage()) == stageInt.end()) {
|
|
|
|
|
stageInt.insert(make_pair(repp->stage(), stage++));
|
|
|
|
|
stages.push_back(repp->stage());
|
|
|
|
|
}
|
|
|
|
|
byName.insert(make_pair(repp->name(), repp));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Header
|
2018-02-02 02:24:41 +00:00
|
|
|
|
os<<" Stat "<<std::left<<std::setw(maxWidth-5-2)<<"";
|
2006-08-26 11:35:28 +00:00
|
|
|
|
for (Stages::iterator it = stages.begin(); it!=stages.end(); ++it) {
|
2018-02-02 02:24:41 +00:00
|
|
|
|
os<<" "<<std::left<<std::setw(9)<<*it;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
os<<endl;
|
2018-02-02 02:24:41 +00:00
|
|
|
|
os<<" -------- "<<std::left<<std::setw(maxWidth-5-2)<<"";
|
2006-08-26 11:35:28 +00:00
|
|
|
|
for (Stages::iterator it = stages.begin(); it!=stages.end(); ++it) {
|
2018-02-02 02:24:41 +00:00
|
|
|
|
os<<" "<<std::left<<std::setw(9)<<"-------";
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
//os<<endl;
|
|
|
|
|
|
|
|
|
|
// Print organized by stage
|
|
|
|
|
string lastName = "__NONE__";
|
|
|
|
|
string lastCommaName = "__NONE__";
|
|
|
|
|
unsigned col=0;
|
|
|
|
|
for (ByName::iterator it = byName.begin(); it!=byName.end(); ++it) {
|
|
|
|
|
const V3Statistic* repp = it->second;
|
|
|
|
|
if (lastName != repp->name()) {
|
|
|
|
|
lastName = repp->name();
|
|
|
|
|
{
|
|
|
|
|
string commaName = lastName;
|
|
|
|
|
string::size_type pos;
|
2018-10-14 02:28:59 +00:00
|
|
|
|
if ((pos = commaName.find(',')) != string::npos) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
commaName.erase(pos);
|
|
|
|
|
}
|
|
|
|
|
if (lastCommaName != commaName) {
|
|
|
|
|
lastCommaName = commaName;
|
|
|
|
|
os<<endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
os<<endl;
|
|
|
|
|
col = 0;
|
2018-02-02 02:24:41 +00:00
|
|
|
|
os<<" "<<std::left<<std::setw(maxWidth)<<repp->name();
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
while (col<stages.size() && stages.at(col) != repp->stage()) {
|
2018-02-02 02:24:41 +00:00
|
|
|
|
os<<std::setw(11)<<"";
|
2006-08-26 11:35:28 +00:00
|
|
|
|
col++;
|
|
|
|
|
}
|
|
|
|
|
repp->dump(os);
|
|
|
|
|
col++;
|
|
|
|
|
}
|
|
|
|
|
os<<endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
// METHODS
|
|
|
|
|
static void addStat(const V3Statistic& stat) {
|
|
|
|
|
s_allStats.push_back(stat);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CONSTRUCTORS
|
2018-02-02 02:24:41 +00:00
|
|
|
|
explicit StatsReport(std::ofstream* aofp)
|
2006-08-26 11:35:28 +00:00
|
|
|
|
: os(*aofp) {
|
|
|
|
|
header();
|
|
|
|
|
sumit();
|
|
|
|
|
stars();
|
|
|
|
|
stages();
|
|
|
|
|
}
|
|
|
|
|
~StatsReport() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
StatsReport::StatColl StatsReport::s_allStats;
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// V3Statstic class
|
|
|
|
|
|
2018-08-23 09:09:12 +00:00
|
|
|
|
void V3Statistic::dump(std::ofstream& os) const {
|
2017-09-18 02:52:57 +00:00
|
|
|
|
if (perf()) {
|
2018-02-02 02:24:41 +00:00
|
|
|
|
os<<" "<<std::right<<std::fixed<<std::setprecision(6)<<std::setw(9)<<count();
|
2017-09-18 02:52:57 +00:00
|
|
|
|
} else {
|
2018-02-02 02:24:41 +00:00
|
|
|
|
os<<" "<<std::right<<std::fixed<<std::setprecision(0)<<std::setw(9)<<count();
|
2017-09-18 02:52:57 +00:00
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// Top Stats class
|
|
|
|
|
|
|
|
|
|
void V3Stats::addStat(const V3Statistic& stat) {
|
|
|
|
|
StatsReport::addStat(stat);
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-18 02:52:57 +00:00
|
|
|
|
void V3Stats::statsStage(const string& name) {
|
|
|
|
|
static double lastWallTime = -1;
|
|
|
|
|
static int fileNumber = 0;
|
|
|
|
|
|
|
|
|
|
char digits[100]; sprintf(digits, "%03d", ++fileNumber);
|
|
|
|
|
const string digitName = string(digits)+"_"+name;
|
|
|
|
|
|
|
|
|
|
double wallTime = V3Os::timeUsecs() / 1.0e6;
|
|
|
|
|
if (lastWallTime<0) lastWallTime = wallTime;
|
|
|
|
|
double wallTimeDelta = wallTime - lastWallTime;
|
|
|
|
|
lastWallTime = wallTime;
|
|
|
|
|
V3Stats::addStatPerf("Stage, Elapsed time (sec), "+digitName, wallTimeDelta);
|
|
|
|
|
|
|
|
|
|
double memory = V3Os::memUsageBytes()/1024.0/1024.0;
|
|
|
|
|
V3Stats::addStatPerf("Stage, Memory (MB), "+digitName, memory);
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
void V3Stats::statsReport() {
|
|
|
|
|
UINFO(2,__FUNCTION__<<": "<<endl);
|
|
|
|
|
|
|
|
|
|
// Open stats file
|
|
|
|
|
string filename = v3Global.opt.makeDir()+"/"+v3Global.opt.prefix()+"__stats.txt";
|
2018-02-02 02:24:41 +00:00
|
|
|
|
std::ofstream* ofp (V3File::new_ofstream(filename));
|
2018-07-14 23:22:50 +00:00
|
|
|
|
if (ofp->fail()) v3fatal("Can't write "<<filename);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
StatsReport reporter (ofp);
|
|
|
|
|
|
|
|
|
|
// Cleanup
|
2015-10-04 17:16:35 +00:00
|
|
|
|
ofp->close(); delete ofp; VL_DANGLING(ofp);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|