python: Add AbstractStat for PyStats

Previously all PyStats inheritted from JsonSerializable. The
AbstractStat class has been added to give a cleaner, clearer Base class
for PyStats.

Change-Id: I7e1808c4b4dcd6110fd524ad3553a9dc19f72e24
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/63691
Reviewed-by: Bobby Bruce <bbruce@ucdavis.edu>
Maintainer: Bobby Bruce <bbruce@ucdavis.edu>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Bobby R. Bruce
2022-09-15 13:40:49 -07:00
committed by Bobby Bruce
parent 68f8c2946d
commit b65fa9e0d8
6 changed files with 46 additions and 6 deletions

View File

@@ -284,6 +284,7 @@ PySource('m5.ext.pyfdt', 'm5/ext/pyfdt/__init__.py')
PySource('m5.ext.pystats', 'm5/ext/pystats/__init__.py')
PySource('m5.ext.pystats', 'm5/ext/pystats/serializable_stat.py')
PySource('m5.ext.pystats', 'm5/ext/pystats/abstract_stat.py')
PySource('m5.ext.pystats', 'm5/ext/pystats/group.py')
PySource('m5.ext.pystats', 'm5/ext/pystats/simstat.py')
PySource('m5.ext.pystats', 'm5/ext/pystats/statistic.py')

View File

@@ -24,6 +24,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from .abstract_stat import AbstractStat
from .serializable_stat import SerializableStat
from .group import Group
from .simstat import SimStat
@@ -33,6 +34,7 @@ from .timeconversion import TimeConversion
from .jsonloader import JsonLoader
__all__ = [
"AbstractStat",
"Group",
"SimStat",
"Statistic",

View File

@@ -0,0 +1,37 @@
# Copyright (c) 2022 The Regents of The University of California
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met: redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer;
# redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution;
# neither the name of the copyright holders nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from .serializable_stat import SerializableStat
class AbstractStat(SerializableStat):
"""
An abstract class which all PyStats inherit from.
All PyStats are JsonSerializable.
"""
pass

View File

@@ -36,12 +36,12 @@ from typing import (
Union,
)
from .serializable_stat import SerializableStat
from .abstract_stat import AbstractStat
from .statistic import Scalar, Statistic
from .timeconversion import TimeConversion
class Group(SerializableStat):
class Group(AbstractStat):
"""
Used to create the heirarchical stats structure. A Group object contains a
map of labeled Groups, Statistics, Lists of Groups, or List of Statistics.

View File

@@ -27,13 +27,13 @@
from datetime import datetime
from typing import Dict, List, Optional, Union
from .serializable_stat import SerializableStat
from .abstract_stat import AbstractStat
from .group import Group
from .statistic import Statistic
from .timeconversion import TimeConversion
class SimStat(SerializableStat):
class SimStat(AbstractStat):
"""
Contains all the statistics for a given simulation.
"""

View File

@@ -27,11 +27,11 @@
from abc import ABC
from typing import Any, Iterable, Optional, Union, List
from .serializable_stat import SerializableStat
from .abstract_stat import AbstractStat
from .storagetype import StorageType
class Statistic(ABC, SerializableStat):
class Statistic(ABC, AbstractStat):
"""
The abstract base class for all Python statistics.
"""