LCOV - code coverage report
Current view: top level - conffwk/test/apps - config_time_test.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 84 0
Test Date: 2025-12-21 13:07:08 Functions: 0.0 % 19 0

            Line data    Source code
       1              : #include <stdlib.h>
       2              : #include <time.h>
       3              : #include <sys/resource.h>
       4              : 
       5              : #include <chrono>
       6              : #include <iostream>
       7              : #include <fstream>
       8              : #include <string>
       9              : 
      10              : #include "conffwk/Configuration.hpp"
      11              : #include "conffwk/ConfigObject.hpp"
      12              : #include "conffwk/Schema.hpp"
      13              : 
      14              : using namespace dunedaq::conffwk;
      15              : 
      16            0 : ERS_DECLARE_ISSUE(
      17              :   conffwk_time_test,
      18              :   BadCommandLine,
      19              :   "bad command line: " << reason,
      20              :   ((const char*)reason)
      21              : )
      22              : 
      23            0 : ERS_DECLARE_ISSUE(
      24              :   conffwk_time_test,
      25              :   ConfigException,
      26              :   "caught dunedaq::conffwk::Exception exception",
      27              : )
      28              : 
      29              : static void
      30            0 : no_param(const char * s)
      31              : {
      32            0 :   std::ostringstream text;
      33            0 :   text << "no parameter for " << s << " provided";
      34            0 :   ers::fatal(conffwk_time_test::BadCommandLine(ERS_HERE, text.str().c_str()));
      35            0 :   exit(EXIT_FAILURE);
      36            0 : }
      37              : 
      38              : template <class T>
      39              : void
      40            0 : stop_and_report(T& tp, const char * fname)
      41              : {
      42            0 :   std::cout << "TEST \"" << fname << "\" => " << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now()-tp).count() / 1000. << " ms\n";
      43            0 : }
      44              : 
      45              : 
      46            0 : int main(int argc, char *argv[])
      47              : {
      48            0 :   const char * db_name = 0;
      49            0 :   bool verbose = false;
      50              : 
      51            0 :   for(int i = 1; i < argc; i++) {
      52            0 :     const char * cp = argv[i];
      53              : 
      54            0 :     if(!strcmp(cp, "-h") || !strcmp(cp, "--help")) {
      55            0 :       std::cout << 
      56              :         "Usage: conffwk_time_test -d dbspec [-c | -C [class_name]] [-o | -O [object_id]] [-n]\n"
      57              :         "\n"
      58              :         "Options/Arguments:\n"
      59              :         "  -d | --database dbspec        database specification in format plugin-name:parameters\n"
      60              :         "  -v | --verbose                print details\n"
      61              :         "\n"
      62              :         "Description:\n"
      63              :         "  The utility reports results of time tests.\n"
      64            0 :         "  When no -c or -o options are provided, utility lists all classes.\n\n";
      65              :     }
      66            0 :     else if(!strcmp(cp, "-d") || !strcmp(cp, "--database")) {
      67            0 :       if(++i == argc) { no_param(cp); } else { db_name = argv[i]; }
      68              :     }
      69            0 :     else if(!strcmp(cp, "-v") || !strcmp(cp, "--verbose")) {
      70            0 :       verbose = true;
      71              :     }
      72              :   }
      73              : 
      74            0 :   if(!db_name) {
      75            0 :     ers::fatal(conffwk_time_test::BadCommandLine(ERS_HERE, "no database name given"));
      76            0 :     return (EXIT_FAILURE);
      77              :   }
      78              : 
      79            0 :   try {
      80              :   
      81              :     
      82              :     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      83              : 
      84            0 :     auto tp = std::chrono::steady_clock::now();
      85              : 
      86            0 :     Configuration conf(db_name);
      87              : 
      88            0 :     if(verbose) {
      89            0 :       std::cout << "load database \"" << conf.get_impl_spec() << '\"' << std::endl;
      90              :     }
      91              : 
      92            0 :     stop_and_report(tp, "loading database");
      93              : 
      94              :     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
      95              : 
      96            0 :     tp = std::chrono::steady_clock::now();
      97              : 
      98            0 :     std::set<std::string> classes;
      99              : 
     100            0 :     for(fmap<fset>::const_iterator i = conf.superclasses().begin(); i != conf.superclasses().end(); ++i) {
     101            0 :       classes.insert(*i->first);
     102              :     }
     103              : 
     104            0 :     if(verbose) {
     105            0 :       std::cout << "The database schema has " << classes.size() << " class(es):\n";
     106              :     }
     107              : 
     108            0 :     for(std::set<std::string>::const_iterator i = classes.begin(); i != classes.end(); ++i) {
     109            0 :       const dunedaq::conffwk::class_t& d(conf.get_class_info(*i));
     110            0 :       if(verbose) {
     111            0 :         d.print(std::cout, "  ");
     112              :       }
     113              :     }
     114              : 
     115            0 :     stop_and_report(tp, "reading schema meta-information");
     116              : 
     117              :     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     118              : 
     119            0 :     tp = std::chrono::steady_clock::now();
     120              : 
     121            0 :     std::vector<ConfigObject> all_objects;
     122              : 
     123            0 :     for(std::set<std::string>::const_iterator i = classes.begin(); i != classes.end(); ++i) {
     124            0 :       std::vector<ConfigObject> objects;
     125            0 :       conf.get(*i, objects);
     126              : 
     127            0 :       unsigned int count = 0;
     128              : 
     129            0 :       for(std::vector<ConfigObject>::const_iterator j = objects.begin(); j != objects.end(); ++j) {
     130            0 :         if((*j).class_name() == *i) {
     131            0 :           count++;
     132            0 :           all_objects.push_back(*j);
     133              :         }
     134              :       }
     135              :       
     136            0 :       if(verbose) {
     137            0 :         std::cout << "Class " << *i << " has " << count << " objects (" << objects.size() << " with derived classes)\n";
     138              :       }
     139            0 :     }
     140              :     
     141            0 :     if(verbose) {
     142            0 :       std::cout << "Total number of objects: " << all_objects.size() << std::endl;
     143              :     }
     144              : 
     145            0 :     stop_and_report(tp, "reading names of objects");
     146              : 
     147              :     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     148              : 
     149            0 :     tp = std::chrono::steady_clock::now();
     150              : 
     151            0 :     std::set<std::string> files;
     152              :     
     153            0 :     for(std::vector<ConfigObject>::const_iterator i = all_objects.begin(); i != all_objects.end(); ++i) {
     154            0 :       files.insert((*i).contained_in());
     155              :     }
     156              :     
     157            0 :     if(verbose) {
     158            0 :       std::cout << "There are " << files.size() << " data files:\n";
     159              :       
     160            0 :       for(std::set<std::string>::const_iterator i = files.begin(); i != files.end(); ++i) {
     161            0 :         std::cout << " - \"" << *i << "\"\n";
     162              :       }
     163              :     }
     164              :     
     165            0 :     stop_and_report(tp, "reading names of files");
     166              : 
     167              :     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     168              :     
     169            0 :     tp = std::chrono::steady_clock::now();
     170              : 
     171            0 :     if(verbose) {
     172            0 :       std::cout << "Details of objects:\n";
     173              : 
     174            0 :       for(std::vector<ConfigObject>::const_iterator i = all_objects.begin(); i != all_objects.end(); ++i) {
     175            0 :         (*i).print_ref(std::cout, conf, "  ");
     176              :       }
     177              :     }
     178              :     else {
     179            0 :       std::ofstream null("/dev/null", std::ios::out);
     180            0 :       for(std::vector<ConfigObject>::const_iterator i = all_objects.begin(); i != all_objects.end(); ++i) {
     181            0 :         (*i).print_ref(null, conf);
     182              :       }
     183            0 :     }
     184              : 
     185            0 :     stop_and_report(tp, "reading all attributes and relationships");
     186              : 
     187              :     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     188              : 
     189            0 :     return 0;
     190            0 :   }
     191            0 :   catch (dunedaq::conffwk::Exception & ex) {
     192            0 :     ers::fatal(conffwk_time_test::ConfigException(ERS_HERE, ex));
     193            0 :   }
     194              : 
     195            0 :   return (EXIT_FAILURE);
     196              : }
        

Generated by: LCOV version 2.0-1