base-stats: Use smart pointer for info's storageParams

Previously the storage params were not being deallocated.
Make sure this happens by managing it with smart pointers.

As a side effect, encapsulate this variable to facilitate
future changes.

Change-Id: I4c2496d08241f155793ed35e3463512d9ea06f83
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/38178
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hoa Nguyen <hoanguyen@ucdavis.edu>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
This commit is contained in:
Daniel R. Carvalho
2020-12-02 16:51:09 +01:00
committed by Daniel Carvalho
parent 70194795c3
commit bb596f55e3
4 changed files with 44 additions and 21 deletions

View File

@@ -46,6 +46,7 @@
#include "base/cprintf.hh"
#include "base/debug.hh"
#include "base/logging.hh"
#include "base/stats/storage.hh"
#include "base/str.hh"
namespace gem5
@@ -69,7 +70,7 @@ nameMap()
}
Info::Info()
: flags(none), precision(-1), prereq(0), storageParams(NULL)
: flags(none), precision(-1), prereq(0), storageParams()
{
id = id_count++;
if (debug_break_id >= 0 and debug_break_id == id)
@@ -80,6 +81,18 @@ Info::~Info()
{
}
StorageParams const*
Info::getStorageParams() const
{
return storageParams.get();
}
void
Info::setStorageParams(const StorageParams *const params)
{
return storageParams.reset(params);
}
bool
validateStatName(const std::string &name)
{

View File

@@ -31,6 +31,7 @@
#include <cstdint>
#include <map>
#include <memory>
#include <string>
#include <vector>
@@ -100,8 +101,8 @@ class Info
static int id_count;
int id;
public:
const StorageParams *storageParams;
private:
std::unique_ptr<const StorageParams> storageParams;
public:
Info();
@@ -118,6 +119,15 @@ class Info
void setSeparator(std::string _sep) { separatorString = _sep;}
/**
* Getter for the storage params. These parameters should only be modified
* using the respective setter.
* @sa setStorageParams
*/
StorageParams const* getStorageParams() const;
/** Setter for the storage params. */
void setStorageParams(const StorageParams *const params);
/**
* Check that this stat has been set up properly and is ready for
* use