1/* |
2 * Copyright (c) 2019 Arm Limited 3 * All rights reserved. 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated 11 * unmodified and in its entirety in all distributions of the software, 12 * modified or unmodified, in source code or in binary form. 13 * |
14 * Copyright (c) 2003-2005 The Regents of The University of Michigan 15 * Copyright (c) 2017, Centre National de la Recherche Scientifique 16 * All rights reserved. 17 * 18 * Redistribution and use in source and binary forms, with or without 19 * modification, are permitted provided that the following conditions are 20 * met: redistributions of source code must retain the above copyright 21 * notice, this list of conditions and the following disclaimer; --- 48 unchanged lines hidden (view full) --- 70#include <functional> 71#include <iosfwd> 72#include <list> 73#include <map> 74#include <memory> 75#include <string> 76#include <vector> 77 |
78#include "base/stats/group.hh" |
79#include "base/stats/info.hh" 80#include "base/stats/output.hh" 81#include "base/stats/types.hh" 82#include "base/cast.hh" 83#include "base/cprintf.hh" 84#include "base/intmath.hh" 85#include "base/str.hh" 86#include "base/types.hh" --- 93 unchanged lines hidden (view full) --- 180 181struct StorageParams 182{ 183 virtual ~StorageParams(); 184}; 185 186class InfoAccess 187{ |
188 private: 189 Info *_info; 190 |
191 protected: 192 /** Set up an info class for this statistic */ |
193 void setInfo(Group *parent, Info *info); |
194 /** Save Storage class parameters if any */ 195 void setParams(const StorageParams *params); 196 /** Save Storage class parameters if any */ 197 void setInit(); 198 199 /** Grab the information class for this statistic */ 200 Info *info(); 201 /** Grab the information class for this statistic */ 202 const Info *info() const; 203 204 public: |
205 InfoAccess() 206 : _info(nullptr) {}; 207 |
208 /** 209 * Reset the stat to the default state. 210 */ 211 void reset() { } 212 213 /** 214 * @return true if this stat has a value and satisfies its 215 * requirement as a prereq --- 26 unchanged lines hidden (view full) --- 242 243 public: 244 const Info * 245 info() const 246 { 247 return safe_cast<const Info *>(InfoAccess::info()); 248 } 249 |
250 public: 251 DataWrap() = delete; 252 DataWrap(const DataWrap &) = delete; 253 DataWrap &operator=(const DataWrap &) = delete; |
254 |
255 |
256 DataWrap(Group *parent, const char *name, const char *desc) |
257 { |
258 auto info = new Info(self()); 259 this->setInfo(parent, info); 260 261 if (parent) 262 parent->addStat(info); 263 264 if (name) { 265 info->setName(name); 266 info->flags.set(display); 267 } 268 269 if (desc) 270 info->desc = desc; |
271 } 272 273 /** 274 * Set the name and marks this stat to print at the end of simulation. 275 * @param name The new name. 276 * @return A reference to this stat. 277 */ 278 Derived & --- 76 unchanged lines hidden (view full) --- 355}; 356 357template <class Derived, template <class> class InfoProxyType> 358class DataWrapVec : public DataWrap<Derived, InfoProxyType> 359{ 360 public: 361 typedef InfoProxyType<Derived> Info; 362 |
363 DataWrapVec(Group *parent = nullptr, const char *name = nullptr, 364 const char *desc = nullptr) 365 : DataWrap<Derived, InfoProxyType>(parent, name, desc) |
366 {} 367 |
368 // The following functions are specific to vectors. If you use them 369 // in a non vector context, you will get a nice compiler error! 370 371 /** 372 * Set the subfield name for the given index, and marks this stat to print 373 * at the end of simulation. 374 * @param index The subfield index. 375 * @param name The new name of the subfield. --- 60 unchanged lines hidden (view full) --- 436}; 437 438template <class Derived, template <class> class InfoProxyType> 439class DataWrapVec2d : public DataWrapVec<Derived, InfoProxyType> 440{ 441 public: 442 typedef InfoProxyType<Derived> Info; 443 |
444 DataWrapVec2d(Group *parent, const char *name, const char *desc) 445 : DataWrapVec<Derived, InfoProxyType>(parent, name, desc) 446 { 447 } 448 |
449 /** 450 * @warning This makes the assumption that if you're gonna subnames a 2d 451 * vector, you're subnaming across all y 452 */ 453 Derived & 454 ysubnames(const char **names) 455 { 456 Derived &self = this->self(); --- 241 unchanged lines hidden (view full) --- 698 public: 699 /** 700 * Return the current value of this stat as its base type. 701 * @return The current value. 702 */ 703 Counter value() const { return data()->value(); } 704 705 public: |
706 ScalarBase(Group *parent = nullptr, const char *name = nullptr, 707 const char *desc = nullptr) 708 : DataWrap<Derived, ScalarInfoProxy>(parent, name, desc) |
709 { 710 this->doInit(); 711 } 712 713 public: 714 // Common operators for stats 715 /** 716 * Increment the stat by 1. This calls the associated storage object inc --- 113 unchanged lines hidden (view full) --- 830 831template <class Derived> 832class ValueBase : public DataWrap<Derived, ScalarInfoProxy> 833{ 834 private: 835 ProxyInfo *proxy; 836 837 public: |
838 ValueBase(Group *parent, const char *name, const char *desc) 839 : DataWrap<Derived, ScalarInfoProxy>(parent, name, desc), 840 proxy(NULL) 841 { 842 } 843 |
844 ~ValueBase() { if (proxy) delete proxy; } 845 846 template <class T> 847 Derived & 848 scalar(T &value) 849 { 850 proxy = new ValueProxy<T>(value); 851 this->setInit(); --- 271 unchanged lines hidden (view full) --- 1123 1124 bool 1125 check() const 1126 { 1127 return storage != NULL; 1128 } 1129 1130 public: |
1131 VectorBase(Group *parent, const char *name, const char *desc) 1132 : DataWrapVec<Derived, VectorInfoProxy>(parent, name, desc), 1133 storage(nullptr), _size(0) |
1134 {} 1135 1136 ~VectorBase() 1137 { 1138 if (!storage) 1139 return; 1140 1141 for (off_type i = 0; i < _size; ++i) --- 122 unchanged lines hidden (view full) --- 1264 size_type _size; 1265 Storage *storage; 1266 1267 protected: 1268 Storage *data(off_type index) { return &storage[index]; } 1269 const Storage *data(off_type index) const { return &storage[index]; } 1270 1271 public: |
1272 Vector2dBase(Group *parent, const char *name, const char *desc) 1273 : DataWrapVec2d<Derived, Vector2dInfoProxy>(parent, name, desc), 1274 x(0), y(0), _size(0), storage(nullptr) |
1275 {} 1276 1277 ~Vector2dBase() 1278 { 1279 if (!storage) 1280 return; 1281 1282 for (off_type i = 0; i < _size; ++i) --- 598 unchanged lines hidden (view full) --- 1881 void 1882 doInit() 1883 { 1884 new (storage) Storage(this->info()); 1885 this->setInit(); 1886 } 1887 1888 public: |
1889 DistBase(Group *parent, const char *name, const char *desc) 1890 : DataWrap<Derived, DistInfoProxy>(parent, name, desc) 1891 { 1892 } |
1893 1894 /** 1895 * Add a value to the distribtion n times. Calls sample on the storage 1896 * class. 1897 * @param v The value to add. 1898 * @param n The number of times to add it, defaults to 1. 1899 */ 1900 template <typename U> --- 77 unchanged lines hidden (view full) --- 1978 Info *info = this->info(); 1979 for (off_type i = 0; i < _size; ++i) 1980 new (&storage[i]) Storage(info); 1981 1982 this->setInit(); 1983 } 1984 1985 public: |
1986 VectorDistBase(Group *parent, const char *name, const char *desc) 1987 : DataWrapVec<Derived, VectorDistInfoProxy>(parent, name, desc), 1988 storage(NULL) |
1989 {} 1990 1991 ~VectorDistBase() 1992 { 1993 if (!storage) 1994 return ; 1995 1996 for (off_type i = 0; i < _size; ++i) --- 509 unchanged lines hidden (view full) --- 2506/** 2507 * This is a simple scalar statistic, like a counter. 2508 * @sa Stat, ScalarBase, StatStor 2509 */ 2510class Scalar : public ScalarBase<Scalar, StatStor> 2511{ 2512 public: 2513 using ScalarBase<Scalar, StatStor>::operator=; |
2514 2515 Scalar(Group *parent = nullptr, const char *name = nullptr, 2516 const char *desc = nullptr) 2517 : ScalarBase<Scalar, StatStor>(parent, name, desc) 2518 { 2519 } |
2520}; 2521 2522/** 2523 * A stat that calculates the per tick average of a value. 2524 * @sa Stat, ScalarBase, AvgStor 2525 */ 2526class Average : public ScalarBase<Average, AvgStor> 2527{ 2528 public: 2529 using ScalarBase<Average, AvgStor>::operator=; |
2530 2531 Average(Group *parent = nullptr, const char *name = nullptr, 2532 const char *desc = nullptr) 2533 : ScalarBase<Average, AvgStor>(parent, name, desc) 2534 { 2535 } |
2536}; 2537 2538class Value : public ValueBase<Value> 2539{ |
2540 public: 2541 Value(Group *parent = nullptr, const char *name = nullptr, 2542 const char *desc = nullptr) 2543 : ValueBase<Value>(parent, name, desc) 2544 { 2545 } |
2546}; 2547 2548/** 2549 * A vector of scalar stats. 2550 * @sa Stat, VectorBase, StatStor 2551 */ 2552class Vector : public VectorBase<Vector, StatStor> 2553{ |
2554 public: 2555 Vector(Group *parent = nullptr, const char *name = nullptr, 2556 const char *desc = nullptr) 2557 : VectorBase<Vector, StatStor>(parent, name, desc) 2558 { 2559 } |
2560}; 2561 2562/** 2563 * A vector of Average stats. 2564 * @sa Stat, VectorBase, AvgStor 2565 */ 2566class AverageVector : public VectorBase<AverageVector, AvgStor> 2567{ |
2568 public: 2569 AverageVector(Group *parent = nullptr, const char *name = nullptr, 2570 const char *desc = nullptr) 2571 : VectorBase<AverageVector, AvgStor>(parent, name, desc) 2572 { 2573 } |
2574}; 2575 2576/** 2577 * A 2-Dimensional vecto of scalar stats. 2578 * @sa Stat, Vector2dBase, StatStor 2579 */ 2580class Vector2d : public Vector2dBase<Vector2d, StatStor> 2581{ |
2582 public: 2583 Vector2d(Group *parent = nullptr, const char *name = nullptr, 2584 const char *desc = nullptr) 2585 : Vector2dBase<Vector2d, StatStor>(parent, name, desc) 2586 { 2587 } |
2588}; 2589 2590/** 2591 * A simple distribution stat. 2592 * @sa Stat, DistBase, DistStor 2593 */ 2594class Distribution : public DistBase<Distribution, DistStor> 2595{ 2596 public: |
2597 Distribution(Group *parent = nullptr, const char *name = nullptr, 2598 const char *desc = nullptr) 2599 : DistBase<Distribution, DistStor>(parent, name, desc) 2600 { 2601 } 2602 |
2603 /** 2604 * Set the parameters of this distribution. @sa DistStor::Params 2605 * @param min The minimum value of the distribution. 2606 * @param max The maximum value of the distribution. 2607 * @param bkt The number of values in each bucket. 2608 * @return A reference to this distribution. 2609 */ 2610 Distribution & --- 15 unchanged lines hidden (view full) --- 2626 2627/** 2628 * A simple histogram stat. 2629 * @sa Stat, DistBase, HistStor 2630 */ 2631class Histogram : public DistBase<Histogram, HistStor> 2632{ 2633 public: |
2634 Histogram(Group *parent = nullptr, const char *name = nullptr, 2635 const char *desc = nullptr) 2636 : DistBase<Histogram, HistStor>(parent, name, desc) 2637 { 2638 } 2639 |
2640 /** 2641 * Set the parameters of this histogram. @sa HistStor::Params 2642 * @param size The number of buckets in the histogram 2643 * @return A reference to this histogram. 2644 */ 2645 Histogram & 2646 init(size_type size) 2647 { --- 10 unchanged lines hidden (view full) --- 2658 * @sa DistBase, SampleStor 2659 */ 2660class StandardDeviation : public DistBase<StandardDeviation, SampleStor> 2661{ 2662 public: 2663 /** 2664 * Construct and initialize this distribution. 2665 */ |
2666 StandardDeviation(Group *parent = nullptr, const char *name = nullptr, 2667 const char *desc = nullptr) 2668 : DistBase<StandardDeviation, SampleStor>(parent, name, desc) |
2669 { 2670 SampleStor::Params *params = new SampleStor::Params; 2671 this->doInit(); 2672 this->setParams(params); 2673 } 2674}; 2675 2676/** 2677 * Calculates the per tick mean and variance of the samples. 2678 * @sa DistBase, AvgSampleStor 2679 */ 2680class AverageDeviation : public DistBase<AverageDeviation, AvgSampleStor> 2681{ 2682 public: 2683 /** 2684 * Construct and initialize this distribution. 2685 */ |
2686 AverageDeviation(Group *parent = nullptr, const char *name = nullptr, 2687 const char *desc = nullptr) 2688 : DistBase<AverageDeviation, AvgSampleStor>(parent, name, desc) |
2689 { 2690 AvgSampleStor::Params *params = new AvgSampleStor::Params; 2691 this->doInit(); 2692 this->setParams(params); 2693 } 2694}; 2695 2696/** 2697 * A vector of distributions. 2698 * @sa VectorDistBase, DistStor 2699 */ 2700class VectorDistribution : public VectorDistBase<VectorDistribution, DistStor> 2701{ 2702 public: |
2703 VectorDistribution(Group *parent = nullptr, const char *name = nullptr, 2704 const char *desc = nullptr) 2705 : VectorDistBase<VectorDistribution, DistStor>(parent, name, desc) 2706 { 2707 } 2708 |
2709 /** 2710 * Initialize storage and parameters for this distribution. 2711 * @param size The size of the vector (the number of distributions). 2712 * @param min The minimum value of the distribution. 2713 * @param max The maximum value of the distribution. 2714 * @param bkt The number of values in each bucket. 2715 * @return A reference to this distribution. 2716 */ --- 14 unchanged lines hidden (view full) --- 2731/** 2732 * This is a vector of StandardDeviation stats. 2733 * @sa VectorDistBase, SampleStor 2734 */ 2735class VectorStandardDeviation 2736 : public VectorDistBase<VectorStandardDeviation, SampleStor> 2737{ 2738 public: |
2739 VectorStandardDeviation(Group *parent = nullptr, const char *name = nullptr, 2740 const char *desc = nullptr) 2741 : VectorDistBase<VectorStandardDeviation, SampleStor>(parent, name, 2742 desc) 2743 { 2744 } 2745 |
2746 /** 2747 * Initialize storage for this distribution. 2748 * @param size The size of the vector. 2749 * @return A reference to this distribution. 2750 */ 2751 VectorStandardDeviation & 2752 init(size_type size) 2753 { --- 7 unchanged lines hidden (view full) --- 2761/** 2762 * This is a vector of AverageDeviation stats. 2763 * @sa VectorDistBase, AvgSampleStor 2764 */ 2765class VectorAverageDeviation 2766 : public VectorDistBase<VectorAverageDeviation, AvgSampleStor> 2767{ 2768 public: |
2769 VectorAverageDeviation(Group *parent = nullptr, const char *name = nullptr, 2770 const char *desc = nullptr) 2771 : VectorDistBase<VectorAverageDeviation, AvgSampleStor>(parent, name, 2772 desc) 2773 { 2774 } 2775 |
2776 /** 2777 * Initialize storage for this distribution. 2778 * @param size The size of the vector. 2779 * @return A reference to this distribution. 2780 */ 2781 VectorAverageDeviation & 2782 init(size_type size) 2783 { --- 75 unchanged lines hidden (view full) --- 2859 void 2860 doInit() 2861 { 2862 new (storage) Storage(this->info()); 2863 this->setInit(); 2864 } 2865 2866 public: |
2867 SparseHistBase(Group *parent, const char *name, const char *desc) 2868 : DataWrap<Derived, SparseHistInfoProxy>(parent, name, desc) 2869 { 2870 } |
2871 2872 /** 2873 * Add a value to the distribtion n times. Calls sample on the storage 2874 * class. 2875 * @param v The value to add. 2876 * @param n The number of times to add it, defaults to 1. 2877 */ 2878 template <typename U> --- 100 unchanged lines hidden (view full) --- 2979 cmap.clear(); 2980 samples = 0; 2981 } 2982}; 2983 2984class SparseHistogram : public SparseHistBase<SparseHistogram, SparseHistStor> 2985{ 2986 public: |
2987 SparseHistogram(Group *parent = nullptr, const char *name = nullptr, 2988 const char *desc = nullptr) 2989 : SparseHistBase<SparseHistogram, SparseHistStor>(parent, name, desc) 2990 { 2991 } 2992 |
2993 /** 2994 * Set the parameters of this histogram. @sa HistStor::Params 2995 * @param size The number of buckets in the histogram 2996 * @return A reference to this histogram. 2997 */ 2998 SparseHistogram & 2999 init(size_type size) 3000 { --- 16 unchanged lines hidden (view full) --- 3017 /** The root of the tree which represents the Formula */ 3018 NodePtr root; 3019 friend class Temp; 3020 3021 public: 3022 /** 3023 * Create and initialize thie formula, and register it with the database. 3024 */ |
3025 Formula(Group *parent = nullptr, const char *name = nullptr, 3026 const char *desc = nullptr); |
3027 |
3028 Formula(Group *parent, const char *name, const char *desc, 3029 const Temp &r); |
3030 3031 /** 3032 * Set an unitialized Formula to the given root. 3033 * @param r The root of the expression tree. 3034 * @return a reference to this formula. 3035 */ |
3036 const Formula &operator=(const Temp &r); |
3037 |
3038 template<typename T> 3039 const Formula &operator=(const T &v) 3040 { 3041 *this = Temp(v); 3042 return *this; 3043 } 3044 |
3045 /** 3046 * Add the given tree to the existing one. 3047 * @param r The root of the expression tree. 3048 * @return a reference to this formula. 3049 */ 3050 const Formula &operator+=(Temp r); 3051 3052 /** --- 351 unchanged lines hidden --- |