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
|
|
|
|
//
|
2019-11-08 03:33:59 +00:00
|
|
|
// Code available from: https://verilator.org
|
2006-08-26 11:35:28 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
|
|
|
//
|
2022-01-01 13:26:40 +00:00
|
|
|
// Copyright 2005-2022 by Wilson Snyder. This program is free software; you
|
2020-03-21 15:24:24 +00:00
|
|
|
// can 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.
|
2020-03-21 15:24:24 +00:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
2006-08-26 11:35:28 +00:00
|
|
|
//
|
|
|
|
//*************************************************************************
|
2019-10-05 00:17:11 +00:00
|
|
|
|
2021-03-04 02:57:07 +00:00
|
|
|
#ifndef VERILATOR_V3STATS_H_
|
|
|
|
#define VERILATOR_V3STATS_H_
|
2018-10-14 17:43:24 +00:00
|
|
|
|
2006-12-18 19:20:45 +00:00
|
|
|
#include "config_build.h"
|
|
|
|
#include "verilatedos.h"
|
2018-10-14 17:43:24 +00:00
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
#include "V3Error.h"
|
2014-11-22 16:48:39 +00:00
|
|
|
|
|
|
|
class AstNetlist;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
2020-11-19 02:32:16 +00:00
|
|
|
class VDouble0 final {
|
2006-08-26 11:35:28 +00:00
|
|
|
// Double counter, initializes to zero for easy use
|
2020-11-15 20:40:35 +00:00
|
|
|
double m_d = 0.0; ///< Count of occurrences/ value
|
2006-08-26 11:35:28 +00:00
|
|
|
public:
|
|
|
|
// METHODS
|
2020-11-15 20:40:35 +00:00
|
|
|
VDouble0() = default;
|
|
|
|
~VDouble0() = default;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
// Implicit conversion operators:
|
2020-06-02 03:16:02 +00:00
|
|
|
explicit VDouble0(const vluint64_t v)
|
2020-08-16 13:55:36 +00:00
|
|
|
: m_d{static_cast<double>(v)} {}
|
2020-06-02 03:16:02 +00:00
|
|
|
operator double() const { return m_d; }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
// Explicit operators:
|
2020-06-02 03:16:02 +00:00
|
|
|
VDouble0& operator++() { // prefix
|
2020-04-14 02:51:35 +00:00
|
|
|
++m_d;
|
|
|
|
return *this;
|
|
|
|
}
|
2020-06-02 03:16:02 +00:00
|
|
|
VDouble0 operator++(int) { // postfix
|
2020-04-14 02:51:35 +00:00
|
|
|
VDouble0 old = *this;
|
|
|
|
m_d++;
|
|
|
|
return old;
|
|
|
|
}
|
2020-06-02 03:16:02 +00:00
|
|
|
VDouble0& operator=(const double v) {
|
2020-04-14 02:51:35 +00:00
|
|
|
m_d = v;
|
|
|
|
return *this;
|
|
|
|
}
|
2020-06-02 03:16:02 +00:00
|
|
|
VDouble0& operator+=(const double v) {
|
2020-04-14 02:51:35 +00:00
|
|
|
m_d += v;
|
|
|
|
return *this;
|
|
|
|
}
|
2020-06-02 03:16:02 +00:00
|
|
|
VDouble0& operator-=(const double v) {
|
2020-04-14 02:51:35 +00:00
|
|
|
m_d -= v;
|
|
|
|
return *this;
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
2020-11-19 02:32:16 +00:00
|
|
|
class V3Statistic final {
|
2006-08-26 11:35:28 +00:00
|
|
|
// A statistical entry we want published into the database
|
2021-11-26 22:55:36 +00:00
|
|
|
const string m_name; ///< Name of this statistic
|
2020-04-14 02:51:35 +00:00
|
|
|
double m_count; ///< Count of occurrences/ value
|
2021-11-26 22:55:36 +00:00
|
|
|
const string m_stage; ///< Runtime stage
|
|
|
|
const bool m_sumit; ///< Do summation of similar stats
|
|
|
|
const bool m_perf; ///< Performance section
|
2020-11-15 20:40:35 +00:00
|
|
|
bool m_printit = true; ///< Print the results
|
2006-08-26 11:35:28 +00:00
|
|
|
public:
|
|
|
|
// METHODS
|
|
|
|
string stage() const { return m_stage; }
|
|
|
|
string name() const { return m_name; }
|
|
|
|
double count() const { return m_count; }
|
|
|
|
bool sumit() const { return m_sumit; }
|
2017-09-18 02:52:57 +00:00
|
|
|
bool perf() const { return m_perf; }
|
2006-08-26 11:35:28 +00:00
|
|
|
bool printit() const { return m_printit; }
|
2018-02-02 02:24:41 +00:00
|
|
|
virtual void dump(std::ofstream& os) const;
|
2006-08-26 11:35:28 +00:00
|
|
|
void combineWith(V3Statistic* otherp) {
|
2019-05-19 20:13:13 +00:00
|
|
|
m_count += otherp->count();
|
|
|
|
otherp->m_printit = false;
|
2006-08-26 11:35:28 +00:00
|
|
|
}
|
|
|
|
// CONSTRUCTORS
|
2020-04-14 02:51:35 +00:00
|
|
|
V3Statistic(const string& stage, const string& name, double count, bool sumit = false,
|
|
|
|
bool perf = false)
|
2020-08-16 13:55:36 +00:00
|
|
|
: m_name{name}
|
|
|
|
, m_count{count}
|
|
|
|
, m_stage{stage}
|
|
|
|
, m_sumit{sumit}
|
2020-11-15 20:40:35 +00:00
|
|
|
, m_perf{perf} {}
|
2020-11-17 00:56:16 +00:00
|
|
|
virtual ~V3Statistic() = default;
|
2006-08-26 11:35:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
2020-11-19 02:32:16 +00:00
|
|
|
class V3Stats final {
|
2006-08-26 11:35:28 +00:00
|
|
|
public:
|
|
|
|
static void addStat(const V3Statistic&);
|
|
|
|
static void addStat(const string& stage, const string& name, double count) {
|
2020-04-14 02:51:35 +00:00
|
|
|
addStat(V3Statistic(stage, name, count));
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
static void addStat(const string& name, double count) {
|
2020-04-14 02:51:35 +00:00
|
|
|
addStat(V3Statistic("*", name, count));
|
|
|
|
}
|
2006-08-26 11:35:28 +00:00
|
|
|
static void addStatSum(const string& name, double count) {
|
2020-04-14 02:51:35 +00:00
|
|
|
addStat(V3Statistic("*", name, count, true));
|
|
|
|
}
|
2017-09-18 02:52:57 +00:00
|
|
|
static void addStatPerf(const string& name, double count) {
|
2020-04-14 02:51:35 +00:00
|
|
|
addStat(V3Statistic("*", name, count, true, true));
|
|
|
|
}
|
2017-09-18 02:52:57 +00:00
|
|
|
/// Called each stage
|
|
|
|
static void statsStage(const string& name);
|
2006-08-26 11:35:28 +00:00
|
|
|
/// Called by the top level to collect statistics
|
2020-04-14 02:51:35 +00:00
|
|
|
static void statsStageAll(AstNetlist* nodep, const string& stage, bool fast = false);
|
2006-08-26 11:35:28 +00:00
|
|
|
static void statsFinalAll(AstNetlist* nodep);
|
|
|
|
/// Called by the top level to dump the statistics
|
|
|
|
static void statsReport();
|
|
|
|
};
|
|
|
|
|
2019-05-19 20:13:13 +00:00
|
|
|
#endif // Guard
|