LCOV - code coverage report
Current view: top level - ugbase/common - progress.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 55 0
Test Date: 2025-09-21 23:31:46 Functions: 0.0 % 5 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              : #include "progress.h"
      34              : namespace ug{
      35              : 
      36              : int Progress::totalDepth = 0;
      37              : int Progress::lastUpdateDepth = -1;
      38              : 
      39              : size_t g_minSecondUntilProgress = 3;
      40              : 
      41            0 : Progress::Progress(int minSecondsUntilProgress)
      42              : {
      43            0 :         if(minSecondsUntilProgress == -1)
      44            0 :                 minSecondsUntilProgress = g_minSecondUntilProgress;
      45            0 :         m_minSecondsUntilProgress = minSecondsUntilProgress;
      46            0 :         m_length=100;
      47            0 :         bStarted=false;
      48            0 :         posNow=-1;
      49            0 :         myDepth = totalDepth++;
      50            0 : }
      51              : /*
      52              : 
      53              : void Progress::setD(double now)
      54              : {
      55              :         if(now < 0 && now > m_total) return;
      56              :         if(bStarted)
      57              :         {
      58              :                 if(myDepth == lastUpdateDepth)
      59              :                 {
      60              :                         int i2=(int)(m_length*now/m_total);
      61              :                         if(i2 != posNow)
      62              :                         {
      63              :                                 for(; posNow<i2; posNow++) { UG_LOG("-"); }
      64              :                                 GetLogAssistant().flush();
      65              :                                 calc_next_value();
      66              :                         }
      67              :                         m_now = now;
      68              :                 }
      69              :         }
      70              :         else if(get_clock_s() - startS > m_minSecondsUntilProgress)
      71              :         {
      72              :                 if(m_msg.length() > 0)
      73              :                         {UG_LOG("\n" << m_msg);}
      74              :                 UG_LOG("\n." << repeat('_', m_length) << ".\n");
      75              :                 UG_LOG("[");
      76              :                 bStarted = true;
      77              :                 posNow = 0;
      78              :                 lastUpdateDepth = myDepth;
      79              :                 set(now);
      80              :         }
      81              :         else
      82              :         {
      83              :                 posNow++;
      84              :                 calc_next_value();
      85              :         }
      86              : }
      87              : 
      88              : */
      89              : 
      90            0 : static inline void print_mark(int &posNow, int length)
      91              : {
      92            0 :         if(posNow%(length/4)==0 )
      93              :         {
      94            0 :                 switch(posNow / (length/4))
      95              :                 {
      96              :                 case 0: UG_LOG("-"); break;
      97            0 :                 case 1: UG_LOG("25%");posNow+=2; break;
      98            0 :                 case 2: UG_LOG("50%");posNow+=2; break;
      99            0 :                 case 3: UG_LOG("75%");posNow+=2; break;
     100              :                 }
     101              :         }
     102              :         else {UG_LOG("-");}
     103            0 : }
     104              : 
     105            0 : void Progress::setD(double now)
     106              : {
     107            0 :         if(now < 0 && now > m_total) return;
     108            0 :         if(bStarted)
     109              :         {
     110            0 :                 if(myDepth == lastUpdateDepth)
     111              :                 {
     112            0 :                         int i2=(int)(m_length*now/m_total);
     113            0 :                         if(i2 != posNow)
     114              :                         {
     115            0 :                                 for(; posNow<i2; posNow++)
     116            0 :                                         print_mark(posNow, m_length);
     117            0 :                                 GetLogAssistant().flush();
     118              :                                 calc_next_value();
     119              :                         }
     120            0 :                         m_now = now;
     121              :                 }
     122              :         }
     123            0 :         else if(get_clock_s() - startS > m_minSecondsUntilProgress)
     124              :         {
     125            0 :                 if(m_msg.length() > 0)
     126              :                         {UG_LOG("\n" << m_msg);}
     127              :                 UG_LOG("\n");
     128              : //              UG_LOG("." << repeat('_', m_length) << ".\n");
     129              :                 UG_LOG("[");
     130            0 :                 bStarted = true;
     131            0 :                 posNow = 0;
     132            0 :                 lastUpdateDepth = myDepth;
     133            0 :                 set(now);
     134              :         }
     135              :         else
     136              :         {
     137            0 :                 posNow++;
     138              :                 calc_next_value();
     139              :         }
     140              : }
     141            0 : void Progress::stop()
     142              : {
     143            0 :         if(bStarted && myDepth == lastUpdateDepth)
     144              :         {
     145            0 :                 int i=(int)(m_length*m_now/m_total);
     146            0 :                 for(; i<m_length; i++)
     147            0 :                         print_mark(i, m_length);
     148              :                 UG_LOG("]");
     149            0 :                 UG_LOG(" took " << reset_floats << get_clock_s()-startS << " s.\n");
     150            0 :                 lastUpdateDepth = myDepth;
     151            0 :                 bStarted = false;
     152            0 :                 posNow = -1;
     153              :         }
     154            0 :         if(!bStarted && posNow != -1 && get_clock_s() - startS > m_minSecondsUntilProgress*2)
     155              :         {
     156            0 :                 UG_LOG(m_msg << ". took " << reset_floats << get_clock_s()-startS << " s.\n");
     157            0 :                 bStarted = false;
     158            0 :                 posNow = -1;
     159              :         }
     160            0 : }
     161            0 : void Progress::start(double total, std::string msg)
     162              : {
     163            0 :         m_msg = msg;
     164            0 :         m_now = 0;
     165            0 :         m_total = total;
     166            0 :         bStarted=false;
     167            0 :         startS = get_clock_s();
     168            0 :         posNow = 0;
     169              :         calc_next_value();
     170            0 : }
     171              : 
     172              : }
        

Generated by: LCOV version 2.0-1