souffle  2.0.2-371-g6315b36
Public Member Functions | Data Fields | Protected Member Functions | Private Attributes
souffle::profile::Reader Class Reference

#include <Reader.h>

Collaboration diagram for souffle::profile::Reader:
Collaboration graph

Public Member Functions

void addRelation (const DirectoryEntry &relation)
 
std::string createId ()
 
bool isLive ()
 
bool isLoaded ()
 
void processFile ()
 Read the contents from file into the class. More...
 
 Reader (std::shared_ptr< ProgramRun > run)
 
 Reader (std::string filename, std::shared_ptr< ProgramRun > run)
 
std::string RelationcreateId ()
 
void save (std::string f_name)
 

Data Fields

std::shared_ptr< ProgramRunrun
 

Protected Member Functions

std::string cleanRelationName (const std::string &relationName)
 
std::string extractRelationNameFromAtom (const Atom &atom)
 

Private Attributes

const ProfileDatabase & db = ProfileEventSingleton::instance().getDB()
 
std::string file_loc
 
std::streampos gpos
 
bool loaded = false
 
bool online {true}
 
int rel_id {0}
 
std::unordered_map< std::string, std::shared_ptr< Relation > > relationMap {}
 

Detailed Description

Definition at line 271 of file Reader.h.

Constructor & Destructor Documentation

◆ Reader() [1/2]

souffle::profile::Reader::Reader ( std::string  filename,
std::shared_ptr< ProgramRun run 
)
inline

Definition at line 285 of file Reader.h.

286  : file_loc(std::move(filename)), run(std::move(run)) {
287  try {
289  } catch (const std::exception& e) {
290  fatal("exception whilst reading profile DB: %s", e.what());
291  }
292  }

References e, souffle::fatal(), file_loc, souffle::ProfileEventSingleton::instance(), and souffle::ProfileEventSingleton::setDBFromFile().

Here is the call graph for this function:

◆ Reader() [2/2]

souffle::profile::Reader::Reader ( std::shared_ptr< ProgramRun run)
inline

Definition at line 294 of file Reader.h.

294 : run(std::move(run)) {}

Member Function Documentation

◆ addRelation()

void souffle::profile::Reader::addRelation ( const DirectoryEntry &  relation)
inline

Definition at line 355 of file Reader.h.

355  {
356  const std::string& name = cleanRelationName(relation.getKey());
357 
358  relationMap.emplace(name, std::make_shared<Relation>(name, createId()));
359  auto& rel = *relationMap[name];
360  RelationVisitor relationVisitor(rel);
361 
362  for (const auto& key : relation.getKeys()) {
363  relation.readEntry(key)->accept(relationVisitor);
364  }
365  }

References cleanRelationName(), createId(), rel(), relation, and relationMap.

Referenced by processFile().

Here is the call graph for this function:

◆ cleanRelationName()

std::string souffle::profile::Reader::cleanRelationName ( const std::string &  relationName)
inlineprotected

Definition at line 380 of file Reader.h.

380  {
381  std::string cleanName = relationName;
382  for (auto& cur : cleanName) {
383  if (cur == '-') {
384  cur = '.';
385  }
386  }
387  return cleanName;
388  }

Referenced by addRelation(), and extractRelationNameFromAtom().

◆ createId()

std::string souffle::profile::Reader::createId ( )
inline

Definition at line 375 of file Reader.h.

375  {
376  return "R" + std::to_string(++rel_id);
377  }

References rel_id.

Referenced by addRelation().

◆ extractRelationNameFromAtom()

std::string souffle::profile::Reader::extractRelationNameFromAtom ( const Atom atom)
inlineprotected

Definition at line 389 of file Reader.h.

389  {
390  return cleanRelationName(atom.identifier.substr(0, atom.identifier.find('(')));
391  }

References cleanRelationName(), and souffle::profile::Atom::identifier.

Referenced by processFile().

Here is the call graph for this function:

◆ isLive()

bool souffle::profile::Reader::isLive ( )
inline

Definition at line 351 of file Reader.h.

351  {
352  return online;
353  }

References online.

◆ isLoaded()

bool souffle::profile::Reader::isLoaded ( )
inline

Definition at line 367 of file Reader.h.

367  {
368  return loaded;
369  }

References loaded.

◆ processFile()

void souffle::profile::Reader::processFile ( )
inline

Read the contents from file into the class.

Definition at line 298 of file Reader.h.

298  {
299  rel_id = 0;
300  relationMap.clear();
301  auto programDuration = dynamic_cast<DurationEntry*>(db.lookupEntry({"program", "runtime"}));
302  if (programDuration == nullptr) {
303  auto startTimeEntry = dynamic_cast<TimeEntry*>(db.lookupEntry({"program", "starttime"}));
304  if (startTimeEntry != nullptr) {
305  run->setStarttime(startTimeEntry->getTime());
306  run->setEndtime(std::chrono::duration_cast<microseconds>(now().time_since_epoch()));
307  }
308  } else {
309  run->setStarttime(programDuration->getStart());
310  run->setEndtime(programDuration->getEnd());
311  online = false;
312  }
313 
314  auto relations = dynamic_cast<DirectoryEntry*>(db.lookupEntry({"program", "relation"}));
315  if (relations == nullptr) {
316  // Souffle hasn't generated any profiling information yet.
317  return;
318  }
319  for (const auto& cur : relations->getKeys()) {
320  auto relation = dynamic_cast<DirectoryEntry*>(db.lookupEntry({"program", "relation", cur}));
321  if (relation != nullptr) {
323  }
324  }
325  for (const auto& relation : relationMap) {
326  for (const auto& rule : relation.second->getRuleMap()) {
327  for (const auto& atom : rule.second->getAtoms()) {
328  std::string relationName = extractRelationNameFromAtom(atom);
329  relationMap[relationName]->addReads(atom.frequency);
330  }
331  }
332  for (const auto& iteration : relation.second->getIterations()) {
333  for (const auto& rule : iteration->getRules()) {
334  for (const auto& atom : rule.second->getAtoms()) {
335  std::string relationName = extractRelationNameFromAtom(atom);
336  if (relationName.substr(0, 6) == "@delta") {
337  relationName = relationName.substr(7);
338  }
339  assert(relationMap.count(relationName) > 0 || "Relation name for atom not found");
340  relationMap[relationName]->addReads(atom.frequency);
341  }
342  }
343  }
344  }
345  run->setRelationMap(this->relationMap);
346  loaded = true;
347  }

References addRelation(), db, extractRelationNameFromAtom(), iteration, loaded, souffle::now(), online, rel_id, relation, relationMap, relations, rule, and run.

Here is the call graph for this function:

◆ RelationcreateId()

std::string souffle::profile::Reader::RelationcreateId ( )
inline

Definition at line 371 of file Reader.h.

371  {
372  return "R" + std::to_string(++rel_id);
373  }

References rel_id.

◆ save()

void souffle::profile::Reader::save ( std::string  f_name)

Field Documentation

◆ db

const ProfileDatabase& souffle::profile::Reader::db = ProfileEventSingleton::instance().getDB()
private

Definition at line 275 of file Reader.h.

Referenced by processFile().

◆ file_loc

std::string souffle::profile::Reader::file_loc
private

Definition at line 273 of file Reader.h.

Referenced by Reader().

◆ gpos

std::streampos souffle::profile::Reader::gpos
private

Definition at line 274 of file Reader.h.

◆ loaded

bool souffle::profile::Reader::loaded = false
private

Definition at line 276 of file Reader.h.

Referenced by isLoaded(), and processFile().

◆ online

bool souffle::profile::Reader::online {true}
private

Definition at line 277 of file Reader.h.

Referenced by isLive(), and processFile().

◆ rel_id

int souffle::profile::Reader::rel_id {0}
private

Definition at line 280 of file Reader.h.

Referenced by createId(), processFile(), and RelationcreateId().

◆ relationMap

std::unordered_map<std::string, std::shared_ptr<Relation> > souffle::profile::Reader::relationMap {}
private

Definition at line 279 of file Reader.h.

Referenced by addRelation(), and processFile().

◆ run

std::shared_ptr<ProgramRun> souffle::profile::Reader::run

Definition at line 283 of file Reader.h.

Referenced by processFile().


The documentation for this class was generated from the following file:
souffle::profile::Reader::online
bool online
Definition: Reader.h:277
souffle::profile::Reader::cleanRelationName
std::string cleanRelationName(const std::string &relationName)
Definition: Reader.h:380
souffle::ProfileEventSingleton::instance
static ProfileEventSingleton & instance()
get instance
Definition: ProfileEvent.h:70
e
l j a showGridBackground &&c b raw series this eventEmitter e
Definition: htmlJsChartistMin.h:15
relation
Relation & relation
Definition: Reader.h:130
relations
std::vector< Own< Relation > > relations
Definition: ComponentInstantiation.cpp:65
iteration
Iteration & iteration
Definition: Reader.h:129
souffle::profile::Reader::loaded
bool loaded
Definition: Reader.h:276
souffle::profile::Reader::createId
std::string createId()
Definition: Reader.h:375
souffle::profile::Reader::extractRelationNameFromAtom
std::string extractRelationNameFromAtom(const Atom &atom)
Definition: Reader.h:389
souffle::now
time_point now()
Definition: MiscUtil.h:89
souffle::profile::Reader::rel_id
int rel_id
Definition: Reader.h:280
souffle::profile::Reader::file_loc
std::string file_loc
Definition: Reader.h:273
souffle::profile::Reader::addRelation
void addRelation(const DirectoryEntry &relation)
Definition: Reader.h:355
souffle::profile::Reader::db
const ProfileDatabase & db
Definition: Reader.h:275
rule
Rule & rule
Definition: Reader.h:85
souffle::fatal
void fatal(const char *format, const Args &... args)
Definition: MiscUtil.h:198
souffle::ProfileEventSingleton::setDBFromFile
void setDBFromFile(const std::string &databaseFilename)
Definition: ProfileEvent.h:172
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086
souffle::profile::Reader::run
std::shared_ptr< ProgramRun > run
Definition: Reader.h:283
souffle::profile::Reader::relationMap
std::unordered_map< std::string, std::shared_ptr< Relation > > relationMap
Definition: Reader.h:279