LCOV - code coverage report
Current view: top level - ugbase/common - progress.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 14 0
Test Date: 2025-09-21 23:31:46 Functions: 0.0 % 2 0

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2013-2015:  G-CSC, Goethe University Frankfurt
       3              :  * Author: Martin Rupp
       4              :  * 
       5              :  * This file is part of UG4.
       6              :  * 
       7              :  * UG4 is free software: you can redistribute it and/or modify it under the
       8              :  * terms of the GNU Lesser General Public License version 3 (as published by the
       9              :  * Free Software Foundation) with the following additional attribution
      10              :  * requirements (according to LGPL/GPL v3 §7):
      11              :  * 
      12              :  * (1) The following notice must be displayed in the Appropriate Legal Notices
      13              :  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
      14              :  * 
      15              :  * (2) The following notice must be displayed at a prominent place in the
      16              :  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
      17              :  * 
      18              :  * (3) The following bibliography is recommended for citation and must be
      19              :  * preserved in all covered files:
      20              :  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
      21              :  *   parallel geometric multigrid solver on hierarchically distributed grids.
      22              :  *   Computing and visualization in science 16, 4 (2013), 151-164"
      23              :  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
      24              :  *   flexible software system for simulating pde based models on high performance
      25              :  *   computers. Computing and visualization in science 16, 4 (2013), 165-179"
      26              :  * 
      27              :  * This program is distributed in the hope that it will be useful,
      28              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      29              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      30              :  * GNU Lesser General Public License for more details.
      31              :  */
      32              : 
      33              : #ifndef PROGRESS_H_
      34              : #define PROGRESS_H_
      35              : 
      36              : #include <iostream>
      37              : #include "common/util/string_util.h"
      38              : #include "common/log.h"
      39              : #include <ctime>
      40              : #include <string>
      41              : #include <sstream>
      42              : 
      43              : #include "stopwatch.h"
      44              : #include "util/ostream_util.h"
      45              : 
      46              : namespace ug
      47              : {
      48              : 
      49              : class Progress
      50              : {
      51              : public:
      52              :         Progress(int minSecondsUntilProgress=-1);
      53              : 
      54            0 :         ~Progress()
      55              :         {
      56            0 :                 stop();
      57            0 :                 totalDepth--;
      58            0 :         }
      59              :         void set_length(int l)
      60              :         {
      61              :                 m_length = l;
      62              :         }
      63              : 
      64              :         void calc_next_value()
      65              :         {
      66            0 :                 dNextValueToUpdate = (posNow+1)*m_total/m_length;
      67            0 :                 iNextValueToUpdate = (int) dNextValueToUpdate;
      68            0 :         }
      69              :         void start(double total, std::string msg="");
      70              : 
      71              :         inline void set(size_t now)
      72              :         {
      73            0 :                 if(now < iNextValueToUpdate) return;
      74            0 :                 setD(now);
      75              :         }
      76              :         inline void set(int now)
      77              :         {
      78            0 :                 if(now < 0 || (size_t)now < iNextValueToUpdate) return;
      79            0 :                 setD(now);
      80              :         }
      81              : 
      82            0 :         inline void set(double now)
      83              :         {
      84            0 :                 if(now < dNextValueToUpdate) return;
      85            0 :                 setD(now);
      86              :         }
      87              :         void setD(double now);
      88              : 
      89              :         void stop();
      90              :         
      91              : private:
      92              : 
      93              :         int m_minSecondsUntilProgress;
      94              :         double startS;
      95              :         double dNextValueToUpdate;
      96              :         size_t iNextValueToUpdate;
      97              :         int posNow;
      98              :         bool bStarted;
      99              :         double m_total;
     100              :         double m_now;
     101              :         int m_length;
     102              :         std::string m_msg;
     103              : 
     104              :         static int totalDepth;
     105              :         static int lastUpdateDepth;
     106              :         int myDepth;
     107              : };
     108              : 
     109              : }
     110              : 
     111              : #define PROGRESS_START(progVarName, dSize, msg) \
     112              :         ug::Progress progVarName; { std::stringstream ss; ss << msg; progVarName.start(dSize, ss.str()); }
     113              : 
     114              : #define PROGRESS_START_WITH(progVarName, dSize, msg) \
     115              :         { std::stringstream ss; ss << msg; progVarName.start(dSize, ss.str()); }
     116              : 
     117              : #define PROGRESS_UPDATE(progVarName, d) progVarName.set(d);
     118              : #define PROGRESS_FINISH(progVarName) progVarName.stop();
     119              : 
     120              : 
     121              : #endif /* PROCESS_H_ */
        

Generated by: LCOV version 2.0-1