source: src/Common/Stats/Counter.h@ 675716e

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr persistent-indexer pthread-emulation qualifiedEnum
Last change on this file since 675716e was 675716e, checked in by tdelisle <tdelisle@…>, 7 years ago

Instrumented PassVisitor to print average/max depth

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[8f74a6a]1//
2// Cforall Version 1.0.0 Copyright (C) 2019 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[675716e]7// Counter.h --
[8f74a6a]8//
9// Author : Thierry Delisle
10// Created On : Thu Feb 28 12::05:10 2019
11// Last Modified By :
12// Last Modified On :
13// Update Count :
14//
15
16#pragma once
17
18#include <cstdint>
19#include <iostream>
[8e70823]20#include <string>
21
22#include "Common/Stats/Base.h"
[8f74a6a]23
24namespace Stats {
25 namespace Counters {
26 void print();
27
[8e70823]28 extern Base::TreeImpl::Top top;
[8f74a6a]29
[8e70823]30 class CounterGroup : public Base::Tree<top> {
[8f74a6a]31 public:
[8e70823]32 CounterGroup(const std::string & name ) : Base::Tree<top>(name) {}
33 CounterGroup(const std::string & name, Base::Tree<top> * parent) : Base::Tree<top>(name, parent) {}
[8f74a6a]34
[8e70823]35 virtual void print(std::ostream & os) override { os << ""; }
[8f74a6a]36 protected:
37 virtual ~CounterGroup() = default;
38 };
39
[8e70823]40 class SimpleCounter : public Base::Tree<top> {
[8f74a6a]41 public:
[8e70823]42 SimpleCounter(const std::string & name ) : Base::Tree<top>(name) {}
43 SimpleCounter(const std::string & name, Base::Tree<top> * parent) : Base::Tree<top>(name, parent) {}
44
45 virtual void print(std::ostream & os) override { os << count; }
[8f74a6a]46
47 inline void operator++(int) { count++; }
48 inline void operator+=(size_t value) { count += value; }
49 protected:
50 virtual ~SimpleCounter() = default;
51
52 private:
53 size_t count = 0;
54 };
55
56 template<typename T>
[8e70823]57 class AverageCounter : public Base::Tree<top> {
[8f74a6a]58 public:
[8e70823]59 AverageCounter(const std::string & name ) : Base::Tree<top>(name), sum{} {}
60 AverageCounter(const std::string & name, Base::Tree<top> * parent) : Base::Tree<top>(name, parent), sum{} {}
61
62 virtual void print(std::ostream & os) { os << sum / count; }
[8f74a6a]63
64 inline void push(T value) {
65 sum += value;
66 count++;
67 }
68
69 protected:
70 virtual ~AverageCounter() = default;
71
72 private:
73 T sum;
74 size_t count = 1;
75 };
[351c519]76
77 template<typename T>
[8e70823]78 class MaxCounter : public Base::Tree<top> {
[351c519]79 public:
[8e70823]80 MaxCounter(const std::string & name ) : Base::Tree<top>(name), max{} {}
81 MaxCounter(const std::string & name, Base::Tree<top> * parent) : Base::Tree<top>(name, parent), max{} {}
[351c519]82
[8e70823]83 virtual void print(std::ostream & os) { os << max; }
[351c519]84
[8e70823]85 inline void push(T value) { max = std::max(max, value); }
[351c519]86 protected:
87 virtual ~MaxCounter() = default;
88
89 private:
90 T max;
91 };
[8f74a6a]92 }
93}
Note: See TracBrowser for help on using the repository browser.