2012-04-13 03:08:20 +02:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
2006-08-26 13:35:28 +02:00
|
|
|
//*************************************************************************
|
|
|
|
|
// DESCRIPTION: Verilator: Collect and print statistics
|
|
|
|
|
//
|
2019-11-08 04:33:59 +01:00
|
|
|
// Code available from: https://verilator.org
|
2006-08-26 13:35:28 +02:00
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2023-01-01 16:18:39 +01:00
|
|
|
// Copyright 2005-2023 by Wilson Snyder. This program is free software; you
|
2020-03-21 16:24:24 +01:00
|
|
|
// can redistribute it and/or modify it under the terms of either the GNU
|
2009-05-04 23:07:57 +02:00
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
|
// Version 2.0.
|
2020-03-21 16:24:24 +01:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
2006-08-26 13:35:28 +02:00
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
2019-10-05 02:17:11 +02:00
|
|
|
|
2021-03-04 03:57:07 +01:00
|
|
|
#ifndef VERILATOR_V3STATS_H_
|
|
|
|
|
#define VERILATOR_V3STATS_H_
|
2018-10-14 19:43:24 +02:00
|
|
|
|
2006-12-18 20:20:45 +01:00
|
|
|
#include "config_build.h"
|
|
|
|
|
#include "verilatedos.h"
|
2018-10-14 19:43:24 +02:00
|
|
|
|
2006-08-26 13:35:28 +02:00
|
|
|
#include "V3Error.h"
|
2014-11-22 17:48:39 +01:00
|
|
|
|
|
|
|
|
class AstNetlist;
|
2006-08-26 13:35:28 +02:00
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
2020-11-19 03:32:16 +01:00
|
|
|
class VDouble0 final {
|
2006-08-26 13:35:28 +02:00
|
|
|
// Double counter, initializes to zero for easy use
|
2020-11-15 21:40:35 +01:00
|
|
|
double m_d = 0.0; ///< Count of occurrences/ value
|
2006-08-26 13:35:28 +02:00
|
|
|
public:
|
|
|
|
|
// METHODS
|
2020-11-15 21:40:35 +01:00
|
|
|
VDouble0() = default;
|
|
|
|
|
~VDouble0() = default;
|
2006-08-26 13:35:28 +02:00
|
|
|
|
|
|
|
|
// Implicit conversion operators:
|
2022-03-27 21:27:40 +02:00
|
|
|
explicit VDouble0(const uint64_t v)
|
2020-08-16 15:55:36 +02:00
|
|
|
: m_d{static_cast<double>(v)} {}
|
2020-06-02 05:16:02 +02:00
|
|
|
operator double() const { return m_d; }
|
2006-08-26 13:35:28 +02:00
|
|
|
|
|
|
|
|
// Explicit operators:
|
2020-06-02 05:16:02 +02:00
|
|
|
VDouble0& operator++() { // prefix
|
2020-04-14 04:51:35 +02:00
|
|
|
++m_d;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2020-06-02 05:16:02 +02:00
|
|
|
VDouble0 operator++(int) { // postfix
|
2020-04-14 04:51:35 +02:00
|
|
|
VDouble0 old = *this;
|
|
|
|
|
m_d++;
|
|
|
|
|
return old;
|
|
|
|
|
}
|
2020-06-02 05:16:02 +02:00
|
|
|
VDouble0& operator=(const double v) {
|
2020-04-14 04:51:35 +02:00
|
|
|
m_d = v;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2020-06-02 05:16:02 +02:00
|
|
|
VDouble0& operator+=(const double v) {
|
2020-04-14 04:51:35 +02:00
|
|
|
m_d += v;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2020-06-02 05:16:02 +02:00
|
|
|
VDouble0& operator-=(const double v) {
|
2020-04-14 04:51:35 +02:00
|
|
|
m_d -= v;
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2006-08-26 13:35:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
2020-11-19 03:32:16 +01:00
|
|
|
class V3Statistic final {
|
2006-08-26 13:35:28 +02:00
|
|
|
// A statistical entry we want published into the database
|
2021-11-26 23:55:36 +01:00
|
|
|
const string m_name; ///< Name of this statistic
|
2020-04-14 04:51:35 +02:00
|
|
|
double m_count; ///< Count of occurrences/ value
|
2021-11-26 23:55:36 +01: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 21:40:35 +01:00
|
|
|
bool m_printit = true; ///< Print the results
|
2006-08-26 13:35:28 +02:00
|
|
|
public:
|
|
|
|
|
// METHODS
|
2022-10-18 23:07:09 +02:00
|
|
|
string stage() const VL_MT_SAFE { return m_stage; }
|
|
|
|
|
string name() const VL_MT_SAFE { return m_name; }
|
|
|
|
|
double count() const VL_MT_SAFE { return m_count; }
|
|
|
|
|
bool sumit() const VL_MT_SAFE { return m_sumit; }
|
|
|
|
|
bool perf() const VL_MT_SAFE { return m_perf; }
|
|
|
|
|
bool printit() const VL_MT_SAFE { return m_printit; }
|
|
|
|
|
virtual void dump(std::ofstream& os) const VL_MT_SAFE;
|
2006-08-26 13:35:28 +02:00
|
|
|
void combineWith(V3Statistic* otherp) {
|
2019-05-19 22:13:13 +02:00
|
|
|
m_count += otherp->count();
|
|
|
|
|
otherp->m_printit = false;
|
2006-08-26 13:35:28 +02:00
|
|
|
}
|
|
|
|
|
// CONSTRUCTORS
|
2020-04-14 04:51:35 +02:00
|
|
|
V3Statistic(const string& stage, const string& name, double count, bool sumit = false,
|
|
|
|
|
bool perf = false)
|
2020-08-16 15:55:36 +02:00
|
|
|
: m_name{name}
|
|
|
|
|
, m_count{count}
|
|
|
|
|
, m_stage{stage}
|
|
|
|
|
, m_sumit{sumit}
|
2020-11-15 21:40:35 +01:00
|
|
|
, m_perf{perf} {}
|
2020-11-17 01:56:16 +01:00
|
|
|
virtual ~V3Statistic() = default;
|
2006-08-26 13:35:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
2020-11-19 03:32:16 +01:00
|
|
|
class V3Stats final {
|
2006-08-26 13:35:28 +02:00
|
|
|
public:
|
|
|
|
|
static void addStat(const V3Statistic&);
|
|
|
|
|
static void addStat(const string& stage, const string& name, double count) {
|
2022-11-20 19:11:01 +01:00
|
|
|
addStat(V3Statistic{stage, name, count});
|
2020-04-14 04:51:35 +02:00
|
|
|
}
|
2006-08-26 13:35:28 +02:00
|
|
|
static void addStat(const string& name, double count) {
|
2022-11-20 19:11:01 +01:00
|
|
|
addStat(V3Statistic{"*", name, count});
|
2020-04-14 04:51:35 +02:00
|
|
|
}
|
2006-08-26 13:35:28 +02:00
|
|
|
static void addStatSum(const string& name, double count) {
|
2022-11-20 19:11:01 +01:00
|
|
|
addStat(V3Statistic{"*", name, count, true});
|
2020-04-14 04:51:35 +02:00
|
|
|
}
|
2017-09-18 04:52:57 +02:00
|
|
|
static void addStatPerf(const string& name, double count) {
|
2022-11-20 19:11:01 +01:00
|
|
|
addStat(V3Statistic{"*", name, count, true, true});
|
2020-04-14 04:51:35 +02:00
|
|
|
}
|
2017-09-18 04:52:57 +02:00
|
|
|
/// Called each stage
|
|
|
|
|
static void statsStage(const string& name);
|
2006-08-26 13:35:28 +02:00
|
|
|
/// Called by the top level to collect statistics
|
Simplify and fix code stats
V3Stats for "fast" code have bit-rotted a little and is causing some
problems with tests that rely on stats outputs. The problem is that not
all code is necessarily reachable from eval() any more (due to the
complexity of some the features added over the past few years), so it
might miss some things, as for measuring the "fast" code, it is trying
to trace the execution paths via calls, starting from eval(). It also
appears the fast code can also contain calls to slow code in some
circumstances.
To avoid all that, removed trying to trace dynamic execution, and simply
report the static node counts, which is enough for testing.
Similarly, the variable counts are somewhat dubious, as they don't
include all data types, or all instances of a module in some stages.
Removing these as they are not widely used nor dependable. More specific
stats can be added if required and can be well defined.
2023-10-21 15:45:30 +02:00
|
|
|
static void statsStageAll(AstNetlist* nodep, const string& stage, bool fastOnly = false);
|
2006-08-26 13:35:28 +02:00
|
|
|
static void statsFinalAll(AstNetlist* nodep);
|
|
|
|
|
/// Called by the top level to dump the statistics
|
|
|
|
|
static void statsReport();
|
2023-05-07 23:58:14 +02:00
|
|
|
/// Called by debug dumps
|
|
|
|
|
static void infoHeader(std::ofstream& os, const string& prefix);
|
2006-08-26 13:35:28 +02:00
|
|
|
};
|
|
|
|
|
|
2019-05-19 22:13:13 +02:00
|
|
|
#endif // Guard
|