souffle  2.0.2-371-g6315b36
ProgramRun.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2016, The Souffle Developers. All rights reserved
4  * Licensed under the Universal Permissive License v 1.0 as shown at:
5  * - https://opensource.org/licenses/UPL
6  * - <souffle root>/licenses/SOUFFLE-UPL.txt
7  */
8 
9 #pragma once
10 
13 #include "souffle/profile/Table.h"
14 #include <chrono>
15 #include <cstddef>
16 #include <memory>
17 #include <set>
18 #include <sstream>
19 #include <string>
20 #include <unordered_map>
21 #include <utility>
22 #include <vector>
23 
24 namespace souffle {
25 namespace profile {
26 
27 /*
28  * Stores the relations of the program
29  * ProgramRun -> Relations -> Iterations/Rules
30  */
31 class ProgramRun {
32 private:
33  std::unordered_map<std::string, std::shared_ptr<Relation>> relationMap;
34  std::chrono::microseconds startTime{0};
35  std::chrono::microseconds endTime{0};
36 
37 public:
39 
40  inline void setStarttime(std::chrono::microseconds time) {
41  startTime = time;
42  }
43 
44  inline void setEndtime(std::chrono::microseconds time) {
45  endTime = time;
46  }
47 
48  inline void setRelationMap(std::unordered_map<std::string, std::shared_ptr<Relation>>& relationMap) {
49  this->relationMap = relationMap;
50  }
51 
52  std::string toString() {
53  std::ostringstream output;
54  output << "ProgramRun:" << getRuntime() << "\nRelations:\n";
55  for (auto& r : relationMap) {
56  output << r.second->toString() << "\n";
57  }
58  return output.str();
59  }
60 
61  inline const std::unordered_map<std::string, std::shared_ptr<Relation>>& getRelationMap() const {
62  return relationMap;
63  }
64 
65  std::string getRuntime() const {
66  if (startTime == endTime) {
67  return "--";
68  }
69  return formatTime(endTime - startTime);
70  }
71 
72  std::chrono::microseconds getStarttime() const {
73  return startTime;
74  }
75 
76  std::chrono::microseconds getEndtime() const {
77  return endTime;
78  }
79 
80  std::chrono::microseconds getTotalLoadtime() const {
81  std::chrono::microseconds result{0};
82  for (auto& item : relationMap) {
83  result += item.second->getLoadtime();
84  }
85  return result;
86  }
87 
88  std::chrono::microseconds getTotalSavetime() const {
89  std::chrono::microseconds result{0};
90  for (auto& item : relationMap) {
91  result += item.second->getSavetime();
92  }
93  return result;
94  }
95 
96  size_t getTotalSize() const {
97  size_t result = 0;
98  for (auto& item : relationMap) {
99  result += item.second->size();
100  }
101  return result;
102  }
103 
104  size_t getTotalRecursiveSize() const {
105  size_t result = 0;
106  for (auto& item : relationMap) {
107  result += item.second->getTotalRecursiveRuleSize();
108  }
109  return result;
110  }
111 
112  std::chrono::microseconds getTotalCopyTime() const {
113  std::chrono::microseconds result{0};
114  for (auto& item : relationMap) {
115  result += item.second->getCopyTime();
116  }
117  return result;
118  }
119 
120  std::chrono::microseconds getTotalTime() const {
121  std::chrono::microseconds result{0};
122  for (auto& item : relationMap) {
123  result += item.second->getRecTime();
124  }
125  return result;
126  }
127 
128  const Relation* getRelation(const std::string& name) const {
129  if (relationMap.find(name) != relationMap.end()) {
130  return &(*relationMap.at(name));
131  }
132  return nullptr;
133  }
134 
135  std::set<std::shared_ptr<Relation>> getRelationsAtTime(
136  std::chrono::microseconds start, std::chrono::microseconds end) const {
137  std::set<std::shared_ptr<Relation>> result;
138  for (auto& cur : relationMap) {
139  if (cur.second->getStarttime() <= end && cur.second->getEndtime() >= start) {
140  result.insert(cur.second);
141  }
142  }
143  return result;
144  }
145 
146  inline std::string formatTime(std::chrono::microseconds runtime) const {
147  return Tools::formatTime(runtime);
148  }
149 
150  inline std::string formatNum(int precision, long number) const {
151  return Tools::formatNum(precision, number);
152  }
153 
154  inline std::vector<std::vector<std::string>> formatTable(Table& table, int precision) const {
155  return Tools::formatTable(table, precision);
156  }
157 };
158 
159 } // namespace profile
160 } // namespace souffle
Table.h
souffle::profile::ProgramRun
Definition: ProgramRun.h:31
souffle::profile::Tools::formatTable
std::vector< std::vector< std::string > > formatTable(Table table, int precision)
Definition: StringUtils.h:145
souffle::profile::ProgramRun::getTotalLoadtime
std::chrono::microseconds getTotalLoadtime() const
Definition: ProgramRun.h:80
souffle::profile::ProgramRun::getTotalTime
std::chrono::microseconds getTotalTime() const
Definition: ProgramRun.h:120
souffle::profile::ProgramRun::getStarttime
std::chrono::microseconds getStarttime() const
Definition: ProgramRun.h:72
souffle::profile::ProgramRun::formatTime
std::string formatTime(std::chrono::microseconds runtime) const
Definition: ProgramRun.h:146
souffle::profile::ProgramRun::getRelationMap
const std::unordered_map< std::string, std::shared_ptr< Relation > > & getRelationMap() const
Definition: ProgramRun.h:61
souffle::profile::ProgramRun::setEndtime
void setEndtime(std::chrono::microseconds time)
Definition: ProgramRun.h:44
souffle::profile::ProgramRun::formatTable
std::vector< std::vector< std::string > > formatTable(Table &table, int precision) const
Definition: ProgramRun.h:154
souffle::profile::ProgramRun::endTime
std::chrono::microseconds endTime
Definition: ProgramRun.h:35
souffle::profile::Tools::formatNum
std::string formatNum(double amount)
Definition: StringUtils.h:40
souffle::profile::ProgramRun::ProgramRun
ProgramRun()
Definition: ProgramRun.h:38
souffle::profile::ProgramRun::getTotalCopyTime
std::chrono::microseconds getTotalCopyTime() const
Definition: ProgramRun.h:112
souffle::profile::ProgramRun::getTotalSavetime
std::chrono::microseconds getTotalSavetime() const
Definition: ProgramRun.h:88
souffle::profile::ProgramRun::getTotalSize
size_t getTotalSize() const
Definition: ProgramRun.h:96
souffle::profile::ProgramRun::getRelation
const Relation * getRelation(const std::string &name) const
Definition: ProgramRun.h:128
souffle::profile::ProgramRun::getTotalRecursiveSize
size_t getTotalRecursiveSize() const
Definition: ProgramRun.h:104
souffle::profile::ProgramRun::setRelationMap
void setRelationMap(std::unordered_map< std::string, std::shared_ptr< Relation >> &relationMap)
Definition: ProgramRun.h:48
StringUtils.h
souffle::profile::ProgramRun::toString
std::string toString()
Definition: ProgramRun.h:52
souffle::profile::ProgramRun::setStarttime
void setStarttime(std::chrono::microseconds time)
Definition: ProgramRun.h:40
souffle::profile::Tools::formatTime
std::string formatTime(std::chrono::microseconds number)
Definition: StringUtils.h:108
souffle::test::time
long time(const std::string &name, const Op &operation)
Definition: btree_multiset_test.cpp:411
souffle::profile::ProgramRun::getRelationsAtTime
std::set< std::shared_ptr< Relation > > getRelationsAtTime(std::chrono::microseconds start, std::chrono::microseconds end) const
Definition: ProgramRun.h:135
souffle::profile::ProgramRun::formatNum
std::string formatNum(int precision, long number) const
Definition: ProgramRun.h:150
souffle::profile::ProgramRun::startTime
std::chrono::microseconds startTime
Definition: ProgramRun.h:34
souffle::profile::ProgramRun::getEndtime
std::chrono::microseconds getEndtime() const
Definition: ProgramRun.h:76
souffle
Definition: AggregateOp.h:25
souffle::profile::ProgramRun::getRuntime
std::string getRuntime() const
Definition: ProgramRun.h:65
souffle::profile::ProgramRun::relationMap
std::unordered_map< std::string, std::shared_ptr< Relation > > relationMap
Definition: ProgramRun.h:33
souffle::profile::Relation
Definition: Relation.h:29
Relation.h
souffle::profile::Table
Definition: Table.h:24