souffle  2.0.2-371-g6315b36
Rule.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 
11 #include <chrono>
12 #include <set>
13 #include <sstream>
14 #include <string>
15 #include <tuple>
16 #include <utility>
17 
18 namespace souffle {
19 namespace profile {
20 
21 /*
22  * Class to hold information about souffle Atom profile information
23  */
24 class Atom {
25 public:
26  const std::string identifier;
27  const std::string rule;
28  const size_t level;
29  const size_t frequency;
30 
31  Atom(std::string identifier, std::string rule, size_t level, size_t frequency)
33 
34  bool operator<(const Atom& other) const {
35  if (rule != other.rule) {
36  return rule < other.rule;
37  } else if (level != other.level) {
38  return level < other.level;
39  }
40  return identifier < other.identifier;
41  }
42 };
43 
44 /*
45  * Class to hold information about souffle Rule profile information
46  */
47 class Rule {
48 protected:
49  const std::string name;
50  std::chrono::microseconds starttime{};
51  std::chrono::microseconds endtime{};
52  long numTuples{0};
53  std::string identifier;
54  std::string locator{};
55  std::set<Atom> atoms;
56 
57 private:
58  bool recursive = false;
59  int version = 0;
60 
61 public:
62  Rule(std::string name, std::string id) : name(std::move(name)), identifier(std::move(id)) {}
63 
64  Rule(std::string name, int version, std::string id)
65  : name(std::move(name)), identifier(std::move(id)), recursive(true), version(version) {}
66 
67  std::string getId() const {
68  return identifier;
69  }
70 
71  std::chrono::microseconds getRuntime() const {
72  return endtime - starttime;
73  }
74 
75  std::chrono::microseconds getStarttime() const {
76  return starttime;
77  }
78 
79  std::chrono::microseconds getEndtime() const {
80  return endtime;
81  }
82 
83  long size() {
84  return numTuples;
85  }
86 
87  void setStarttime(std::chrono::microseconds time) {
88  starttime = time;
89  }
90 
91  void setEndtime(std::chrono::microseconds time) {
92  endtime = time;
93  }
94 
95  void setNumTuples(long numTuples) {
96  this->numTuples = numTuples;
97  }
98 
99  void addAtomFrequency(const std::string& subruleName, std::string atom, size_t level, size_t frequency) {
100  atoms.emplace(atom, subruleName, level, frequency);
101  }
102 
103  const std::set<Atom>& getAtoms() const {
104  return atoms;
105  }
106  std::string getName() const {
107  return name;
108  }
109 
110  void setId(std::string id) {
111  identifier = id;
112  }
113 
114  std::string getLocator() const {
115  return locator;
116  }
117 
118  void setLocator(std::string locator) {
119  this->locator = locator;
120  }
121 
122  bool isRecursive() const {
123  return recursive;
124  }
125 
126  void setRecursive(bool recursive) {
127  this->recursive = recursive;
128  }
129 
130  int getVersion() const {
131  return version;
132  }
133 
134  void setVersion(int version) {
135  this->version = version;
136  }
137 
138  std::string toString() const {
139  std::ostringstream output;
140  if (recursive) {
141  output << "{" << name << "," << version << ":";
142  } else {
143  output << "{" << name << ":";
144  }
145  output << "[" << getRuntime().count() << "," << numTuples << "]}";
146  return output.str();
147  }
148 };
149 
150 } // namespace profile
151 } // namespace souffle
souffle::profile::Rule::setNumTuples
void setNumTuples(long numTuples)
Definition: Rule.h:95
souffle::profile::Rule::locator
std::string locator
Definition: Rule.h:54
souffle::profile::Rule::setRecursive
void setRecursive(bool recursive)
Definition: Rule.h:126
souffle::profile::Rule::endtime
std::chrono::microseconds endtime
Definition: Rule.h:51
souffle::profile::Atom::operator<
bool operator<(const Atom &other) const
Definition: Rule.h:34
souffle::profile::Rule::setStarttime
void setStarttime(std::chrono::microseconds time)
Definition: Rule.h:87
souffle::profile::Rule::setVersion
void setVersion(int version)
Definition: Rule.h:134
souffle::profile::Rule::setEndtime
void setEndtime(std::chrono::microseconds time)
Definition: Rule.h:91
souffle::profile::Rule::getRuntime
std::chrono::microseconds getRuntime() const
Definition: Rule.h:71
souffle::id
A functor representing the identity function for a generic type T.
Definition: StreamUtil.h:136
souffle::profile::Atom::rule
const std::string rule
Definition: Rule.h:27
souffle::profile::Rule::getEndtime
std::chrono::microseconds getEndtime() const
Definition: Rule.h:79
souffle::profile::Rule::toString
std::string toString() const
Definition: Rule.h:138
souffle::profile::Rule::addAtomFrequency
void addAtomFrequency(const std::string &subruleName, std::string atom, size_t level, size_t frequency)
Definition: Rule.h:99
souffle::profile::Rule::numTuples
long numTuples
Definition: Rule.h:52
souffle::profile::Rule::atoms
std::set< Atom > atoms
Definition: Rule.h:55
souffle::profile::Rule::getVersion
int getVersion() const
Definition: Rule.h:130
souffle::profile::Rule
Definition: Rule.h:47
souffle::profile::Rule::setLocator
void setLocator(std::string locator)
Definition: Rule.h:118
souffle::profile::Rule::getStarttime
std::chrono::microseconds getStarttime() const
Definition: Rule.h:75
souffle::profile::Atom::frequency
const size_t frequency
Definition: Rule.h:29
souffle::profile::Atom
Definition: Rule.h:24
souffle::profile::Rule::recursive
bool recursive
Definition: Rule.h:58
souffle::profile::Rule::getId
std::string getId() const
Definition: Rule.h:67
souffle::test::time
long time(const std::string &name, const Op &operation)
Definition: btree_multiset_test.cpp:411
souffle::profile::Rule::Rule
Rule(std::string name, int version, std::string id)
Definition: Rule.h:64
std
Definition: Brie.h:3053
souffle::profile::Rule::Rule
Rule(std::string name, std::string id)
Definition: Rule.h:62
souffle::profile::Atom::level
const size_t level
Definition: Rule.h:28
souffle::profile::Atom::identifier
const std::string identifier
Definition: Rule.h:26
souffle::profile::Rule::version
int version
Definition: Rule.h:59
souffle::profile::Atom::Atom
Atom(std::string identifier, std::string rule, size_t level, size_t frequency)
Definition: Rule.h:31
souffle
Definition: AggregateOp.h:25
souffle::profile::Rule::name
const std::string name
Definition: Rule.h:49
souffle::profile::Rule::isRecursive
bool isRecursive() const
Definition: Rule.h:122
souffle::profile::Rule::getLocator
std::string getLocator() const
Definition: Rule.h:114
souffle::profile::Rule::getName
std::string getName() const
Definition: Rule.h:106
souffle::profile::Rule::getAtoms
const std::set< Atom > & getAtoms() const
Definition: Rule.h:103
souffle::profile::Rule::size
long size()
Definition: Rule.h:83
souffle::profile::Rule::setId
void setId(std::string id)
Definition: Rule.h:110
id
void id(std::string col)
Definition: Tui.h:1124
souffle::profile::Rule::starttime
std::chrono::microseconds starttime
Definition: Rule.h:50
souffle::profile::Rule::identifier
std::string identifier
Definition: Rule.h:53