souffle  2.0.2-371-g6315b36
LogTimer.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 LogTimer.h
12  *
13  ***********************************************************************/
14 
15 #pragma once
16 
17 #include "ram/AbstractLog.h"
18 #include "ram/Node.h"
19 #include "ram/Statement.h"
20 #include "ram/utility/NodeMapper.h"
24 #include <memory>
25 #include <ostream>
26 #include <string>
27 #include <utility>
28 #include <vector>
29 
30 namespace souffle::ram {
31 
32 /**
33  * @class LogTimer
34  * @brief Execution time logger for a statement
35  *
36  * Logs the execution time of a statement. Before and after
37  * the execution of the logging statement the wall-clock time
38  * is taken to compute the time duration for the statement.
39  * Duration and logging message is printed after the execution
40  * of the statement.
41  *
42  * For example:
43  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
44  * START_TIMER "@runtime\;"
45  * BEGIN_STRATUM 0
46  * ...
47  * ...
48  * END_TIMER
49  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
50  */
51 class LogTimer : public Statement, public AbstractLog {
52 public:
53  LogTimer(Own<Statement> stmt, std::string msg) : AbstractLog(std::move(stmt), std::move(msg)) {}
54 
55  std::vector<const Node*> getChildNodes() const override {
57  }
58 
59  LogTimer* clone() const override {
61  }
62 
63  void apply(const NodeMapper& map) override {
65  }
66 
67 protected:
68  void print(std::ostream& os, int tabpos) const override {
69  os << times(" ", tabpos) << "START_TIMER \"" << stringify(message) << "\"" << std::endl;
70  Statement::print(statement.get(), os, tabpos + 1);
71  os << times(" ", tabpos) << "END_TIMER" << std::endl;
72  }
73 };
74 
75 } // namespace souffle::ram
souffle::ram::LogTimer::clone
LogTimer * clone() const override
Create a clone (i.e.
Definition: LogTimer.h:63
souffle::ram::LogTimer::apply
void apply(const NodeMapper &map) override
Apply the mapper to all child nodes.
Definition: LogTimer.h:67
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::LogTimer
Execution time logger for a statement.
Definition: LogTimer.h:55
souffle::ram::AbstractLog::message
const std::string message
Logging message.
Definition: AbstractLog.h:74
souffle::ram
Definition: AstToRamTranslator.h:54
souffle::ram::LogTimer::print
void print(std::ostream &os, int tabpos) const override
Pretty print with indentation.
Definition: LogTimer.h:72
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
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::LogTimer::getChildNodes
std::vector< const Node * > getChildNodes() const override
Obtain list of all embedded child nodes.
Definition: LogTimer.h:59
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::LogTimer::LogTimer
LogTimer(Own< Statement > stmt, std::string msg)
Definition: LogTimer.h:57
souffle::ram::AbstractLog::statement
Own< Statement > statement
Logging statement.
Definition: AbstractLog.h:71