Herezh_dev/herezh_pp/TypeBase/Temps_CPU_HZpp_3.h

151 lines
6 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 *
* ici on cumule 3 compteurs: user, systéme et réel *
* $ *
* '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' *
* $ *
************************************************************************/
#ifndef TEMPS_CPU_HZPP_3_H
#define TEMPS_CPU_HZPP_3_H
#include <iomanip>
#include <string.h>
#include <iostream>
#include <stdlib.h>
#include "Sortie.h"
#include "ParaGlob.h"
#include "Enum_IO_XML.h"
#include "Temps_CPU_HZpp.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;
// typedef boost::chrono::duration<long long, boost::micro> microseconds; // classique
// typedef boost::chrono::duration<double, boost::micro> flotant_microseconds; // ajout GR
#include <boost/chrono/round.hpp>
#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;
#endif
//------------------------------------------------------------------
//! Temps_CPU_HZpp_3 une classe dédiée à la gestion des temps d'exécution, ici on cumule 3 compteurs: user, systéme et réel
//------------------------------------------------------------------
/// \author Gérard Rio
/// \version 1.0
/// \date 01/02/2016
class Temps_CPU_HZpp_3
{
// surcharge de l'operator de lecture
friend istream & operator >> (istream & ent, Temps_CPU_HZpp_3 & a);
// surcharge de l'operator d'ecriture
friend ostream & operator << (ostream & sort , const Temps_CPU_HZpp_3 & a);
public :
// CONSTRUCTEURS :
Temps_CPU_HZpp_3(); // par défaut, initialise à défaut
// DESTRUCTEUR :
~Temps_CPU_HZpp_3(){};
// --- METHODES PUBLIQUES :
// mise en route du comptage
void Mise_en_route_du_comptage();
// arrêt du comptage et cumul
void Arret_du_comptage();
// retour de la valeur actuelle du temps_cpu user en miliseconde
long long Temps_CPU_User() const {return temps_user.count()/1000;};
// idem temps_cpu system
long long Temps_CPU_System() const {return temps_system.count()/1000;};
// idem temps_cpu reel
long long Temps_CPU_Reel() const {return temps_reel.count()/1000;};
// 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_3& operator= (const Temps_CPU_HZpp_3& de)
{ temps_user = de.temps_user; temps_reel = de.temps_reel;
temps_system = de.temps_system;
return (*this);};
// surcharge de lecture en XML
istream & LectXML_Temps_CPU_HZpp_3(istream & ent);
// surcharge d'ecriture en XML
ostream & EcritXML_Temps_CPU_HZpp_3(ostream & sort);
// sortie du schemaXML: en fonction de enu
void SchemaXML_Temps_CPU_HZpp_3(ofstream& sort,const Enum_IO_XML enu) const ;
private :
// VARIABLES PROTEGEES :
// def des variables du process
microseconds temps_user;
microseconds temps_system;
microseconds temps_reel;
// 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;
microseconds debut_temps_system;
microseconds debut_temps_reel;
// gestion schéma XML
static short int impre_schem_XML;
};
#endif