[1738] | 1 | // ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
|
---|
| 2 | // Eric Aubourg
|
---|
| 3 | // Christophe Magneville
|
---|
| 4 | // Reza Ansari
|
---|
[2133] | 5 | // $Id: toimanager.cc,v 1.16 2002-07-26 08:52:43 vfebvre Exp $
|
---|
[1738] | 6 |
|
---|
[1365] | 7 | #include "toimanager.h"
|
---|
| 8 | #include <limits.h>
|
---|
| 9 | #include <pthread.h>
|
---|
[1759] | 10 | #include <iostream.h>
|
---|
[1704] | 11 | #include <unistd.h>
|
---|
[1365] | 12 |
|
---|
[1702] | 13 | #ifndef MAXINT
|
---|
| 14 | #define MAXINT 2147483647
|
---|
| 15 | #endif
|
---|
| 16 |
|
---|
[1365] | 17 | TOIManager::TOIManager() {
|
---|
| 18 | reqBegin = 0;
|
---|
[1702] | 19 | reqEnd = MAXINT;
|
---|
[1365] | 20 | }
|
---|
| 21 |
|
---|
| 22 | TOIManager* TOIManager::instance = NULL;
|
---|
| 23 |
|
---|
| 24 | TOIManager* TOIManager::getManager() {
|
---|
| 25 | if (instance == NULL) instance = new TOIManager();
|
---|
| 26 | return instance;
|
---|
| 27 | }
|
---|
| 28 |
|
---|
[2133] | 29 | // enregistrement d'un processeur dans la liste des processeurs pour une execution en groupe
|
---|
| 30 |
|
---|
| 31 | void TOIManager::registerProcessor(TOIProcessor* proc) {
|
---|
| 32 |
|
---|
| 33 | cout << "Adding processor to TOIManager for group execution" << endl;
|
---|
| 34 | processors.push_back(proc);
|
---|
| 35 |
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 | // demarrage de tous les processeurs
|
---|
| 40 |
|
---|
| 41 | void TOIManager::startAll() {
|
---|
| 42 | for (vector<TOIProcessor*>::iterator i = processors.begin();
|
---|
| 43 | i != processors.end(); i++) {
|
---|
| 44 | TOIProcessor* proc = *i;
|
---|
| 45 | cout << "******************" << endl;
|
---|
| 46 | cout << "starting processor " << endl;
|
---|
| 47 | cout << "******************" << endl;
|
---|
| 48 | proc->start();
|
---|
| 49 | cout << "processor started " << endl;
|
---|
| 50 | cout << "******************" << endl;
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 |
|
---|
| 55 |
|
---|
[1702] | 56 | void TOIManager::setRequestedSample(int begin, int end) {
|
---|
[1365] | 57 | reqBegin = begin;
|
---|
| 58 | reqEnd = end;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[1702] | 61 | int TOIManager::getRequestedBegin() {
|
---|
[1365] | 62 | return reqBegin;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
[1702] | 65 | int TOIManager::getRequestedEnd() {
|
---|
[1365] | 66 | return reqEnd;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | void TOIManager::addThread(pthread_t* t) {
|
---|
| 70 | // cout << "adding thread " << t << endl;
|
---|
| 71 | threads.push_back(t);
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | void TOIManager::joinAll() {
|
---|
[2133] | 75 | waitForAll();
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | void TOIManager::waitForAll() {
|
---|
[1365] | 79 | for (vector<pthread_t*>::iterator i = threads.begin();
|
---|
| 80 | i != threads.end(); i++) {
|
---|
| 81 | pthread_t* pth = *i;
|
---|
| 82 | cout << "joining thread " << pth << endl;
|
---|
| 83 | pthread_join(*pth, NULL);
|
---|
| 84 | cout << "thread joined " << pth << endl;
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
[1687] | 87 |
|
---|
| 88 |
|
---|
| 89 | // -----------------------------------------------------------------
|
---|
| 90 | // Classe pour affichage de l'avancement des TOIProcessors
|
---|
| 91 | // Reza 08/2001
|
---|
| 92 | // -----------------------------------------------------------------
|
---|
| 93 |
|
---|
| 94 | RzProcSampleCounter::RzProcSampleCounter()
|
---|
| 95 | {
|
---|
| 96 | _msg = "SampleCounter/Info";
|
---|
| 97 | _rate = 50;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | RzProcSampleCounter::~RzProcSampleCounter()
|
---|
| 101 | {
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | long RzProcSampleCounter::PrintStats()
|
---|
| 105 | {
|
---|
| 106 | int istart = 0;
|
---|
| 107 | int iend = 0;
|
---|
| 108 | long dns_print = 1000;
|
---|
| 109 | int dns_print_fac = _rate;
|
---|
| 110 | int nbmax_dns_print = 2;
|
---|
| 111 |
|
---|
| 112 | TOIManager* mgr = TOIManager::getManager();
|
---|
| 113 |
|
---|
[1999] | 114 | // istart = mgr->getRequestedBegin();
|
---|
| 115 | // iend = mgr->getRequestedEnd();
|
---|
| 116 | istart = SampleBegin();
|
---|
| 117 | iend = SampleEnd();
|
---|
[1687] | 118 |
|
---|
| 119 | dns_print = (iend-istart)/dns_print_fac;
|
---|
| 120 | if (dns_print < 1000) dns_print = ((iend-istart) < 1000) ? (iend-istart) : 1000;
|
---|
| 121 | if (dns_print < 1) dns_print = 1;
|
---|
| 122 | nbmax_dns_print = (iend-istart)/dns_print;
|
---|
| 123 |
|
---|
| 124 | cout << "RzProcSampleCounter::PrintStats() InfoMessage=" << _msg
|
---|
| 125 | << "\n ... " << _msg << " istart="
|
---|
| 126 | << istart << " iend= " << iend << " dns_print= " << dns_print
|
---|
| 127 | << " nbmax_dns_print= " << nbmax_dns_print << endl;
|
---|
| 128 | // ------------------- Impression continu de stat ------------------------
|
---|
| 129 | long nb_dns_print = 0;
|
---|
| 130 | int nb_sleep = 0;
|
---|
| 131 | long last_sample_count = 0;
|
---|
| 132 | long processed_samples = 0;
|
---|
| 133 | long total_sample_count = dns_print*nbmax_dns_print;
|
---|
| 134 | bool alldone = false;
|
---|
[2077] | 135 | double fracperc = 0.;
|
---|
| 136 | int fperc = 0;
|
---|
[1687] | 137 | while (!alldone) {
|
---|
| 138 | processed_samples = ProcessedSampleCount();
|
---|
| 139 | if ( (processed_samples-last_sample_count > dns_print) ||
|
---|
[1702] | 140 | (processed_samples > total_sample_count-10) ) {
|
---|
[1687] | 141 | last_sample_count = processed_samples;
|
---|
| 142 | if (nb_dns_print == 0) cout << "\n";
|
---|
| 143 | nb_dns_print++;
|
---|
[2077] | 144 | fracperc = (double)processed_samples*100./(double)total_sample_count;
|
---|
| 145 | fperc = fracperc*100;
|
---|
[1687] | 146 | cout << ">>> " << _msg << ": ProcessedSampleCount()= " << last_sample_count
|
---|
[2077] | 147 | << " Frac done = " << (double)fperc/100. << " %" << endl;
|
---|
[1687] | 148 | if (last_sample_count > total_sample_count-10) alldone = true;
|
---|
| 149 | nb_sleep = 0;
|
---|
| 150 | }
|
---|
[2077] | 151 | else if ((nb_sleep+1)%5 == 0) {
|
---|
| 152 | fracperc = (double)processed_samples*100./(double)total_sample_count;
|
---|
| 153 | fperc = fracperc*100;
|
---|
[1687] | 154 | cout << "> " << _msg << ": ProcSamples()= " << processed_samples
|
---|
[2077] | 155 | << " Done = " << " %" << (double)fperc/100.
|
---|
[1702] | 156 | << " NbSleep(1) = " << nb_sleep << endl;
|
---|
[2077] | 157 | }
|
---|
[1687] | 158 | sleep(1); nb_sleep++;
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | // -----------------------------------------------------------------------
|
---|
| 162 |
|
---|
| 163 | return last_sample_count;
|
---|
| 164 |
|
---|
| 165 | }
|
---|