Herezh_dev/herezh_pp/TypeBase/Temps_CPU_HZpp.h

244 lines
10 KiB
C++
Executable file

// This file is part of the Herezh++ application.
//
// The finite element software Herezh++ is dedicated to the field
// of mechanics for large transformations of solid structures.
// It is developed by Gérard Rio (APP: IDDN.FR.010.0106078.000.R.P.2006.035.20600)
// INSTITUT DE RECHERCHE DUPUY DE LÔME (IRDL) <https://www.irdl.fr/>.
//
// Herezh++ is distributed under GPL 3 license ou ultérieure.
//
// Copyright (C) 1997-2021 Université Bretagne Sud (France)
// AUTHOR : Gérard Rio
// E-MAIL : gerardrio56@free.fr
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// For more information, please consult: <https://herezh.irdl.fr/>.
/************************************************************************
* DATE: 01/02/2016 *
* $ *
* AUTEUR: G RIO (mailto:gerardrio56@free.fr) *
* $ *
* PROJET: Herezh++ *
* $ *
************************************************************************
* BUT: une classe dédiée à la gestion des temps d'exécution *
* il s'agit ici uniquement du temps user *
* $ *
* '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' *
* *
* VERIFICATION: *
* *
* ! date ! auteur ! but ! *
* ------------------------------------------------------------ *
* ! ! ! ! *
* $ *
* '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' *
* MODIFICATIONS: *
* ! date ! auteur ! but ! *
* ------------------------------------------------------------ *
* $ *
************************************************************************/
#ifndef TEMPS_CPU_HZPP_H
#define TEMPS_CPU_HZPP_H
#include <iomanip>
#include <string.h>
#include <iostream>
#include <stdlib.h>
#include "Sortie.h"
#include "ParaGlob.h"
#include "Enum_IO_XML.h"
// ne fonctionne que si on accepte Boost
#ifdef UTILISATION_DE_LA_LIBRAIRIE_BOOST
#include <boost/chrono/include.hpp>
#include <boost/system/error_code.hpp>
using namespace boost::chrono;
#ifndef BOOST_CHRONO_HAS_PROCESS_CLOCKS
#define BOOST_CHRONO_HAS_PROCESS_CLOCKS
#endif
// typedef boost::chrono::duration<long long, boost::micro> microseconds; // classique
// typedef boost::chrono::duration<long long, boost::nano> nanoseconds; // classique
// typedef boost::chrono::duration<double, boost::micro> flotant_microseconds; // ajout GR
#include <boost/chrono/round.hpp>
// format duration as [-]d/hh::mm::ss.cc
template <class CharT, class Traits, class Rep, class Period>
std::basic_ostream<CharT, Traits>&
display(std::basic_ostream<CharT, Traits>& os,
boost::chrono::duration<Rep, Period> d)
{
using namespace std;
using namespace boost;
typedef boost::chrono::duration<long long, boost::ratio<86400> > days;
typedef boost::chrono::duration<long long, boost::centi> centiseconds;
// if negative, print negative sign and negate
if (d < boost::chrono::duration<Rep, Period>(0))
{
d = -d;
os << '-';
}
// round d to nearest centiseconds, to even on tie
centiseconds cs = boost::chrono::duration_cast<centiseconds>(d);
if (d - cs > boost::chrono::milliseconds(5)
|| (d - cs == boost::chrono::milliseconds(5) && cs.count() & 1))
++cs;
// separate seconds from centiseconds
boost::chrono::seconds s = boost::chrono::duration_cast<boost::chrono::seconds>(cs);
cs -= s;
// separate minutes from seconds
boost::chrono::minutes m = boost::chrono::duration_cast<boost::chrono::minutes>(s);
s -= m;
// separate hours from minutes
boost::chrono::hours h = boost::chrono::duration_cast<boost::chrono::hours>(m);
m -= h;
// separate days from hours
days dy = boost::chrono::duration_cast<days>(h);
h -= dy;
// print d/hh:mm:ss.cc
os << dy.count() << '/';
if (h < boost::chrono::hours(10))
os << '0';
os << h.count() << ':';
if (m < boost::chrono::minutes(10))
os << '0';
os << m.count() << ':';
if (s < boost::chrono::seconds(10))
os << '0';
os << s.count() << '.';
if (cs < centiseconds(10))
os << '0';
os << cs.count();
return os;
}
#else // sinon en attendant on définit des types par défaut
typedef long hours;
typedef long minutes;
typedef long seconds;
typedef long long milliseconds;
typedef long long microseconds;
typedef long long nanoseconds;
#endif
//------------------------------------------------------------------
//! Temps_CPU_HZpp une classe dédiée à la gestion des temps d'exécution, il s'agit ici uniquement du temps user
//------------------------------------------------------------------
/// \author Gérard Rio
/// \version 1.0
/// \date 01/02/2016
class Temps_CPU_HZpp
{
// surcharge de l'operator de lecture
friend istream & operator >> (istream & ent, Temps_CPU_HZpp & a);
// surcharge de l'operator d'ecriture
friend ostream & operator << (ostream & sort , const Temps_CPU_HZpp & a);
public :
// CONSTRUCTEURS :
Temps_CPU_HZpp(); // par défaut, initialise à défaut
// constructeur de copie
Temps_CPU_HZpp(const Temps_CPU_HZpp& tps):
temps_user(tps.temps_user),debut_temps_user(tps.debut_temps_user)
,comptage_en_cours(tps.comptage_en_cours){};
// DESTRUCTEUR :
~Temps_CPU_HZpp(){};
// --- METHODES PUBLIQUES :
// mise en route du comptage
void Mise_en_route_du_comptage();
// arrêt du comptage et cumul
void Arret_du_comptage();
// indique si oui ou non, on est en phase de comptage
// permet de fermer un comptage en catastrophe,
bool Comptage_en_cours() const {return comptage_en_cours;};
// retour de la valeur actuelle du temps_cpu user en miliseconde
// long long Temps_CPU_User() const {return temps_user.count()/1000;};
// retour de la valeur actuelle du temps_cpu user en microseconde
long long Temps_CPU_User() const {return temps_user.count()/1000;};
// retour de la valeur actuelle du temps_cpu user en milliseconde
long long Temps_CPU_User_milli() const {return temps_user.count()/1000000;};
// affichage en microsecondes
// si niveau = 1 ou plus, on a plus d'info pour le débug par exemple
void Affiche(ostream & sort,int niveau = 0);
// affichage en hh:mn:s:ml
void Affiche_hh_mn_s_ml(ostream & sort);
// surcharge de l'affectation
Temps_CPU_HZpp& operator= (const Temps_CPU_HZpp& de)
{ temps_user = de.temps_user; return (*this);};
// accumulation
Temps_CPU_HZpp& operator+= (const Temps_CPU_HZpp& de)
{ temps_user += de.temps_user; return (*this);};
// diminution
Temps_CPU_HZpp& operator-= (const Temps_CPU_HZpp& de)
{ temps_user -= de.temps_user; return (*this);};
// surcharge de lecture en XML
istream & LectXML_Temps_CPU_HZpp(istream & ent);
// surcharge d'ecriture en XML
ostream & EcritXML_Temps_CPU_HZpp(ostream & sort);
//Surcharge d'operateurs logiques: ne concerne que la durée reel
bool operator == (const Temps_CPU_HZpp& a) const
{ if ( temps_user == a.temps_user) return true; else return false;};
bool operator != (const Temps_CPU_HZpp& a) const { return !(*this == a);};
// surchage de l'opérateur de comparaison :
bool operator > (const Temps_CPU_HZpp& a) const { return (this->temps_user > a.temps_user);};
bool operator >= (const Temps_CPU_HZpp& a) const { return (this->temps_user >= a.temps_user);};
bool operator < (const Temps_CPU_HZpp& a) const { return (this->temps_user < a.temps_user);};
bool operator <= (const Temps_CPU_HZpp& a) const { return (this->temps_user <= a.temps_user);};
// sortie du schemaXML: en fonction de enu
void SchemaXML_Temps_CPU_HZpp(ofstream& sort,const Enum_IO_XML enu) const ;
private :
// VARIABLES PROTEGEES :
// def des variables du process
bool comptage_en_cours; // indique si oui ou non on est dans une phase de comptage
// microseconds temps_user;
nanoseconds temps_user;
// def des variables de début: au lieu d'utiliser un time_point et une duration
// j'utilise directement des microsecondes car sinon tout est en nanoseconde et
// il faut redéfinir un compteur en microsecondes: c'est une solution possible qui a été faite
// dans Chrono_GR.h mais je ne suis pas sûr que 1) cela soit indispensable, 2) que cela soit pérenne
// car j'ai été obligé de récupérer du code de boost et de l'adapter du coup c'est une usine dont je ne
// suis pas sûr de bien tout maîtriser donc j'utilise une solution plus simple
// microseconds debut_temps_user;
nanoseconds debut_temps_user;
// gestion schéma XML
static short int impre_schem_XML;
};
#endif