souffle  2.0.2-371-g6315b36
LogRelationTimer.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2017, 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 /************************************************************************
10  *
11  * @file LogRelationTimer.h
12  *
13  ***********************************************************************/
14 
15 #pragma once
16 
17 #include "ram/AbstractLog.h"
18 #include "ram/Node.h"
19 #include "ram/Relation.h"
20 #include "ram/RelationStatement.h"
21 #include "ram/Statement.h"
22 #include "ram/utility/NodeMapper.h"
26 #include <memory>
27 #include <ostream>
28 #include <string>
29 #include <utility>
30 #include <vector>
31 
32 namespace souffle::ram {
33 
34 /**
35  * @class LogRelationTimer
36  * @brief Execution time logger for a statement
37  *
38  * Logs the execution time of a statement. Before and after
39  * the execution of the logging statement the wall-clock time
40  * is taken to compute the time duration for the statement.
41  * Duration and logging message is printed after the execution
42  * of the statement.
43  *
44  * For example:
45  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
46  * START_TIMER ON A "file.dl [8:1-8:8]\;"
47  * ...
48  * END_TIMER
49  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
50  */
51 class LogRelationTimer : public RelationStatement, public AbstractLog {
52 public:
53  LogRelationTimer(Own<Statement> stmt, std::string msg, std::string relRef)
54  : RelationStatement(std::move(relRef)), AbstractLog(std::move(stmt), std::move(msg)) {}
55 
56  std::vector<const Node*> getChildNodes() const override {
57  std::vector<const Node*> res = RelationStatement::getChildNodes();
58  res.push_back(AbstractLog::getChildNodes().at(0));
59  return res;
60  }
61 
62  LogRelationTimer* clone() const override {
64  }
65 
66  void apply(const NodeMapper& map) override {
69  }
70 
71 protected:
72  void print(std::ostream& os, int tabpos) const override {
73  os << times(" ", tabpos) << "START_TIMER ON " << relation << " \"" << stringify(message) << "\""
74  << std::endl;
75  Statement::print(statement.get(), os, tabpos + 1);
76  os << times(" ", tabpos) << "END_TIMER" << std::endl;
77  }
78 };
79 
80 } // namespace souffle::ram
souffle::ram::LogRelationTimer::print
void print(std::ostream &os, int tabpos) const override
Pretty print with indentation.
Definition: LogRelationTimer.h:76
RelationStatement.h
souffle::ram::Node::apply
virtual void apply(const NodeMapper &)
Apply the mapper to all child nodes.
Definition: Node.h:71
souffle::ram::RelationStatement::RelationStatement
RelationStatement(std::string rel)
Definition: RelationStatement.h:39
souffle::ram::LogRelationTimer::clone
LogRelationTimer * clone() const override
Create a clone (i.e.
Definition: LogRelationTimer.h:66
souffle::ram::RelationStatement::relation
std::string relation
Relation.
Definition: RelationStatement.h:54
souffle::map
auto map(const std::vector< A > &xs, F &&f)
Applies a function to each element of a vector and returns the results.
Definition: ContainerUtil.h:158
MiscUtil.h
souffle::ram::AbstractLog::apply
void apply(const NodeMapper &map)
Definition: AbstractLog.h:59
souffle::ram::AbstractLog::message
const std::string message
Logging message.
Definition: AbstractLog.h:74
souffle::ram::Node::getChildNodes
virtual std::vector< const Node * > getChildNodes() const
Obtain list of all embedded child nodes.
Definition: Node.h:93
souffle::ram
Definition: AstToRamTranslator.h:54
souffle::stringify
std::string stringify(const std::string &input)
Stringify a string using escapes for escape, newline, tab, double-quotes and semicolons.
Definition: StringUtil.h:334
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
NodeMapper.h
souffle::ram::NodeMapper
An abstract class for manipulating RAM Nodes by substitution.
Definition: NodeMapper.h:38
souffle::times
detail::multiplying_printer< T > times(const T &value, unsigned num)
A utility printing a given value multiple times.
Definition: StreamUtil.h:322
souffle::ram::LogRelationTimer::apply
void apply(const NodeMapper &map) override
Apply the mapper to all child nodes.
Definition: LogRelationTimer.h:70
Relation.h
StringUtil.h
souffle::ram::Statement::print
void print(std::ostream &os) const override
Print RAM node.
Definition: Statement.h:42
souffle::ram::AbstractLog::AbstractLog
AbstractLog(Own< Statement > stmt, std::string msg)
Definition: AbstractLog.h:41
souffle::ram::LogRelationTimer::LogRelationTimer
LogRelationTimer(Own< Statement > stmt, std::string msg, std::string relRef)
Definition: LogRelationTimer.h:57
AbstractLog.h
Node.h
std
Definition: Brie.h:3053
StreamUtil.h
Statement.h
souffle::ram::AbstractLog::getChildNodes
std::vector< const Node * > getChildNodes() const
Definition: AbstractLog.h:45
souffle::ram::LogRelationTimer::getChildNodes
std::vector< const Node * > getChildNodes() const override
Obtain list of all embedded child nodes.
Definition: LogRelationTimer.h:60
souffle::ram::LogRelationTimer
Execution time logger for a statement.
Definition: LogRelationTimer.h:55
souffle::ram::AbstractLog::statement
Own< Statement > statement
Logging statement.
Definition: AbstractLog.h:71