souffle  2.0.2-371-g6315b36
Data Structures | Public Member Functions | Private Attributes
souffle::profile::Tui Class Reference

#include <Tui.h>

Collaboration diagram for souffle::profile::Tui:
Collaboration graph

Data Structures

struct  Usage
 

Public Member Functions

std::stringstream & genJsonRelations (std::stringstream &ss, const std::string &name, size_t maxRows)
 
std::stringstream & genJsonTop (std::stringstream &ss)
 
void runCommand (std::vector< std::string > c)
 
void runProf ()
 
 Tui ()
 
 Tui (std::string filename, bool live, bool)
 
 ~Tui ()
 

Private Attributes

bool alive = false
 
std::string f_name
 
InputReader linereader
 
bool loaded
 
OutputProcessor out
 
int precision = 3
 
std::shared_ptr< Readerreader
 
Table relationTable
 
size_t resultLimit = 20000
 Limit results shown. Default value chosen to approximate unlimited. More...
 
Table ruleTable
 
int sortColumn = 0
 
std::thread updater
 

Detailed Description

Definition at line 56 of file Tui.h.

Constructor & Destructor Documentation

◆ Tui() [1/2]

souffle::profile::Tui::Tui ( std::string  filename,
bool  live,
bool   
)
inline

Definition at line 83 of file Tui.h.

83  {
84  // Set a friendlier output size if we're being interacted with directly.
85  if (live) {
86  resultLimit = 20;
87  }
88  this->f_name = filename;
89 
90  const std::shared_ptr<ProgramRun>& run = out.getProgramRun();
91 
92  this->reader = std::make_shared<Reader>(filename, run);
93 
94  this->alive = false;
95  updateDB();
96  this->loaded = reader->isLoaded();
97  }

References souffle::profile::OutputProcessor::getProgramRun(), out, reader, resultLimit, and updateDB().

Here is the call graph for this function:

◆ Tui() [2/2]

souffle::profile::Tui::Tui ( )
inline

Definition at line 99 of file Tui.h.

99  {
100  const std::shared_ptr<ProgramRun>& run = out.getProgramRun();
101  this->reader = std::make_shared<Reader>(run);
102  this->loaded = true;
103  this->alive = true;
104  updateDB();
105  updater = std::thread([this]() {
106  // Update the display every 30s. Check for input every 0.5s
107  std::chrono::milliseconds interval(30000);
108  auto nextUpdateTime = std::chrono::high_resolution_clock::now();
109  do {
110  std::this_thread::sleep_for(std::chrono::milliseconds(500));
111  if (nextUpdateTime < std::chrono::high_resolution_clock::now()) {
112  runCommand({});
113  nextUpdateTime = std::chrono::high_resolution_clock::now() + interval;
114  }
115  } while (reader->isLive() && !linereader.hasReceivedInput());
116  });
117  }

References souffle::profile::OutputProcessor::getProgramRun(), souffle::profile::InputReader::hasReceivedInput(), linereader, souffle::now(), out, reader, runCommand(), updateDB(), and updater.

Here is the call graph for this function:

◆ ~Tui()

souffle::profile::Tui::~Tui ( )
inline

Definition at line 119 of file Tui.h.

119  {
120  if (updater.joinable()) {
121  updater.join();
122  }
123  }

References updater.

Member Function Documentation

◆ genJsonRelations()

std::stringstream& souffle::profile::Tui::genJsonRelations ( std::stringstream &  ss,
const std::string &  name,
size_t  maxRows 
)
inline

◆ genJsonTop()

std::stringstream& souffle::profile::Tui::genJsonTop ( std::stringstream &  ss)
inline

Definition at line 258 of file Tui.h.

258  {
259  const std::shared_ptr<ProgramRun>& run = out.getProgramRun();
260 
261  auto beginTime = run->getStarttime();
262  auto endTime = run->getEndtime();
263  ss << R"_({"top":[)_" << (endTime - beginTime).count() / 1000000.0 << "," << run->getTotalSize()
264  << "," << run->getTotalLoadtime().count() / 1000000.0 << ","
265  << run->getTotalSavetime().count() / 1000000.0 << "]";
266  return ss;
267  }

References souffle::test::count(), souffle::profile::OutputProcessor::getProgramRun(), out, and souffle::profile::ss.

Referenced by genJson().

Here is the call graph for this function:

◆ runCommand()

void souffle::profile::Tui::runCommand ( std::vector< std::string >  c)
inline

Definition at line 125 of file Tui.h.

125  {
126  if (linereader.hasReceivedInput() && c.empty()) {
127  return;
128  }
129  if (!loaded) {
130  std::cout << "Error: File cannot be loaded\n";
131  return;
132  }
133 
134  if (alive) {
135  updateDB();
136  // remake tables to get new data
139 
141  }
142 
143  // If we have not received any input yet in live mode then run top.
144  if ((!linereader.hasReceivedInput() && c.empty())) {
145  // Move up n lines and overwrite the previous top output.
146  std::cout << "\x1b[3D";
147  std::cout << "\x1b[27A";
148  top();
149  std::cout << "\x1b[B> ";
150  } else if (c[0] == "top") {
151  top();
152  } else if (c[0] == "rel") {
153  if (c.size() == 2) {
154  relRul(c[1]);
155  } else if (c.size() == 1) {
156  rel(resultLimit);
157  } else {
158  std::cout << "Invalid parameters to rel command.\n";
159  }
160  } else if (c[0] == "rul") {
161  if (c.size() > 1) {
162  if (c.size() == 3 && c[1] == "id") {
163  std::printf("%7s%2s%s\n\n", "ID", "", "NAME");
164  id(c[2]);
165  } else if (c.size() == 2 && c[1] == "id") {
166  id("0");
167  } else if (c.size() == 2) {
168  verRul(c[1]);
169  } else {
170  std::cout << "Invalid parameters to rul command.\n";
171  }
172  } else {
173  rul(resultLimit);
174  }
175  } else if (c[0] == "graph") {
176  if (c.size() == 3 && c[1].find(".") == std::string::npos) {
177  iterRel(c[1], c[2]);
178  } else if (c.size() == 3 && c[1].at(0) == 'C') {
179  iterRul(c[1], c[2]);
180  } else if (c.size() == 4 && c[1] == "ver" && c[2].at(0) == 'C') {
181  verGraph(c[2], c[3]);
182  } else {
183  std::cout << "Invalid parameters to graph command.\n";
184  }
185  } else if (c[0] == "memory") {
186  memoryUsage();
187  } else if (c[0] == "usage") {
188  if (c.size() > 1) {
189  if (c[1][0] == 'R') {
190  usageRelation(c[1]);
191  } else {
192  usageRule(c[1]);
193  }
194  } else {
195  usage();
196  }
197  } else if (c[0] == "help") {
198  help();
199  } else if (c[0] == "limit") {
200  if (c.size() == 1) {
201  setResultLimit(20000);
202  } else {
203  try {
204  setResultLimit(std::stoul(c[1]));
205  } catch (...) {
206  std::cout << "Invalid parameters to limit command.\n";
207  }
208  }
209  } else if (c[0] == "configuration") {
210  configuration();
211  } else {
212  std::cout << "Unknown command. Use \"help\" for a list of commands.\n";
213  }
214  }

References alive, configuration(), souffle::profile::OutputProcessor::getRelTable(), souffle::profile::OutputProcessor::getRulTable(), souffle::profile::InputReader::hasReceivedInput(), help(), id(), iterRel(), iterRul(), linereader, loaded, memoryUsage(), out, tinyformat::printf(), rel(), relationTable, relRul(), resultLimit, rul(), ruleTable, setResultLimit(), setupTabCompletion(), top(), updateDB(), usage(), usageRelation(), usageRule(), verGraph(), and verRul().

Referenced by souffle::profile::Cli::parse(), runProf(), and Tui().

Here is the call graph for this function:

◆ runProf()

void souffle::profile::Tui::runProf ( )
inline

Definition at line 216 of file Tui.h.

216  {
217  if (!loaded && !f_name.empty()) {
218  std::cout << "Error: File cannot be floaded\n";
219  return;
220  }
221  if (loaded) {
222  std::cout << "SouffleProf\n";
223  top();
224  }
225 
226  linereader.setPrompt("\n> ");
228 
229  while (true) {
230  std::string untrimmedInput = linereader.getInput();
231  std::string input = Tools::trimWhitespace(untrimmedInput);
232 
233  std::cout << std::endl;
234  if (input.empty()) {
235  std::cout << "Unknown command. Type help for a list of commands.\n";
236  continue;
237  }
238 
239  linereader.addHistory(input);
240 
241  std::vector<std::string> c = Tools::split(input, " ");
242 
243  if (c[0] == "q" || c[0] == "quit") {
244  quit();
245  break;
246  } else if (c[0] == "sort") {
247  if (c.size() == 2 && std::stoi(c[1]) < 7) {
248  sortColumn = std::stoi(c[1]);
249  } else {
250  std::cout << "Invalid column, please select a number between 0 and 6.\n";
251  }
252  } else {
253  runCommand(c);
254  }
255  }
256  }

References souffle::profile::InputReader::addHistory(), f_name, souffle::profile::InputReader::getInput(), linereader, loaded, quit(), runCommand(), souffle::profile::InputReader::setPrompt(), setupTabCompletion(), sortColumn, souffle::profile::Tools::split(), top(), and souffle::profile::Tools::trimWhitespace().

Referenced by souffle::profile::Cli::parse().

Here is the call graph for this function:

Field Documentation

◆ alive

bool souffle::profile::Tui::alive = false
private

Definition at line 61 of file Tui.h.

Referenced by runCommand(), and top().

◆ f_name

std::string souffle::profile::Tui::f_name
private

Definition at line 60 of file Tui.h.

Referenced by runProf().

◆ linereader

InputReader souffle::profile::Tui::linereader
private

Definition at line 68 of file Tui.h.

Referenced by runCommand(), runProf(), setupTabCompletion(), and Tui().

◆ loaded

bool souffle::profile::Tui::loaded
private

Definition at line 59 of file Tui.h.

Referenced by runCommand(), and runProf().

◆ out

OutputProcessor souffle::profile::Tui::out
private

◆ precision

int souffle::profile::Tui::precision = 3
private

◆ reader

std::shared_ptr<Reader> souffle::profile::Tui::reader
private

Definition at line 67 of file Tui.h.

Referenced by Tui(), and updateDB().

◆ relationTable

Table souffle::profile::Tui::relationTable
private

◆ resultLimit

size_t souffle::profile::Tui::resultLimit = 20000
private

Limit results shown. Default value chosen to approximate unlimited.

Definition at line 70 of file Tui.h.

Referenced by rel(), rul(), runCommand(), setResultLimit(), and Tui().

◆ ruleTable

Table souffle::profile::Tui::ruleTable
private

◆ sortColumn

int souffle::profile::Tui::sortColumn = 0
private

Definition at line 63 of file Tui.h.

Referenced by rel(), relRul(), rul(), runProf(), and verRul().

◆ updater

std::thread souffle::profile::Tui::updater
private

Definition at line 62 of file Tui.h.

Referenced by quit(), Tui(), and ~Tui().


The documentation for this class was generated from the following file:
usageRule
void usageRule(std::string id)
Definition: Tui.h:736
souffle::profile::OutputProcessor::getRulTable
Table getRulTable() const
Definition: OutputProcessor.h:121
tinyformat::printf
void printf(const char *fmt)
Definition: tinyformat.h:1101
souffle::profile::OutputProcessor::getRelTable
Table getRelTable() const
Definition: OutputProcessor.h:77
souffle::profile::Tools::trimWhitespace
std::string trimWhitespace(std::string str)
Definition: StringUtils.h:182
souffle::profile::Tui::sortColumn
int sortColumn
Definition: Tui.h:63
souffle::profile::Tui::updater
std::thread updater
Definition: Tui.h:62
souffle::profile::Tui::relationTable
Table relationTable
Definition: Tui.h:65
souffle::profile::Tui::reader
std::shared_ptr< Reader > reader
Definition: Tui.h:67
verRul
void verRul(std::string str)
Definition: Tui.h:1181
iterRel
void iterRel(std::string c, std::string col)
Definition: Tui.h:1250
updateDB
void updateDB()
Definition: Tui.h:1472
help
static void help()
Definition: Tui.h:685
souffle::profile::InputReader::getInput
std::string getInput()
Definition: UserInputReader.h:80
setResultLimit
void setResultLimit(size_t limit)
Definition: Tui.h:1082
top
void top()
Definition: Tui.h:1023
setupTabCompletion
void setupTabCompletion()
Definition: Tui.h:985
souffle::now
time_point now()
Definition: MiscUtil.h:89
souffle::profile::Tui::alive
bool alive
Definition: Tui.h:61
iterRul
void iterRul(std::string c, std::string col)
Definition: Tui.h:1315
relRul
void relRul(std::string str)
Definition: Tui.h:1142
souffle::profile::Tui::runCommand
void runCommand(std::vector< std::string > c)
Definition: Tui.h:125
souffle::profile::InputReader::setPrompt
void setPrompt(std::string prompt)
Definition: UserInputReader.h:142
souffle::profile::Tui::out
OutputProcessor out
Definition: Tui.h:58
rul
void rul(size_t limit, bool showLimit=true)
Definition: Tui.h:1106
souffle::test::count
int count(const C &c)
Definition: table_test.cpp:40
souffle::profile::Tools::split
std::vector< std::string > split(std::string toSplit, std::string delimiter)
split on the delimiter
Definition: StringUtils.h:162
souffle::ast::DirectiveType::input
@ input
souffle::profile::Tui::f_name
std::string f_name
Definition: Tui.h:60
configuration
void configuration()
Definition: Tui.h:1009
souffle::profile::InputReader::hasReceivedInput
bool hasReceivedInput()
Definition: UserInputReader.h:52
usageRelation
void usageRelation(std::string id)
Definition: Tui.h:715
souffle::profile::Tui::resultLimit
size_t resultLimit
Limit results shown. Default value chosen to approximate unlimited.
Definition: Tui.h:70
souffle::profile::InputReader::addHistory
void addHistory(std::string hist)
Definition: UserInputReader.h:202
souffle::profile::Tui::ruleTable
Table ruleTable
Definition: Tui.h:66
souffle::profile::OutputProcessor::getProgramRun
const std::shared_ptr< ProgramRun > & getProgramRun() const
Definition: OutputProcessor.h:43
souffle::profile::Tui::linereader
InputReader linereader
Definition: Tui.h:68
souffle::profile::Tui::loaded
bool loaded
Definition: Tui.h:59
verGraph
void verGraph(std::string c, std::string col)
Definition: Tui.h:1363
memoryUsage
void memoryUsage(uint32_t height=20)
Definition: Tui.h:940
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086
usage
void usage(uint32_t height=20)
Definition: Tui.h:839
id
void id(std::string col)
Definition: Tui.h:1124
quit
void quit()
Definition: Tui.h:679
souffle::profile::ss
class souffle::profile::Tui ss
Definition: Tui.h:336