| 1 | // ArchTOIPipe           (C)     CEA/DAPNIA/SPP IN2P3/LAL | 
|---|
| 2 | //                               Eric Aubourg | 
|---|
| 3 | //                               Christophe Magneville | 
|---|
| 4 | //                               Reza Ansari | 
|---|
| 5 | // $Id: toimanager.cc,v 1.13 2002-05-13 15:50:50 ansari Exp $ | 
|---|
| 6 |  | 
|---|
| 7 | #include "toimanager.h" | 
|---|
| 8 | #include <limits.h> | 
|---|
| 9 | #include <pthread.h> | 
|---|
| 10 | #include <iostream.h> | 
|---|
| 11 | #include <unistd.h> | 
|---|
| 12 |  | 
|---|
| 13 | #ifndef MAXINT | 
|---|
| 14 | #define MAXINT 2147483647 | 
|---|
| 15 | #endif | 
|---|
| 16 |  | 
|---|
| 17 | TOIManager::TOIManager() { | 
|---|
| 18 | reqBegin = 0; | 
|---|
| 19 | reqEnd = MAXINT; | 
|---|
| 20 | } | 
|---|
| 21 |  | 
|---|
| 22 | TOIManager* TOIManager::instance = NULL; | 
|---|
| 23 |  | 
|---|
| 24 | TOIManager* TOIManager::getManager() { | 
|---|
| 25 | if (instance == NULL) instance =  new TOIManager(); | 
|---|
| 26 | return instance; | 
|---|
| 27 | } | 
|---|
| 28 |  | 
|---|
| 29 | void TOIManager::setRequestedSample(int begin, int end) { | 
|---|
| 30 | reqBegin = begin; | 
|---|
| 31 | reqEnd   = end; | 
|---|
| 32 | } | 
|---|
| 33 |  | 
|---|
| 34 | int TOIManager::getRequestedBegin() { | 
|---|
| 35 | return reqBegin; | 
|---|
| 36 | } | 
|---|
| 37 |  | 
|---|
| 38 | int TOIManager::getRequestedEnd() { | 
|---|
| 39 | return reqEnd; | 
|---|
| 40 | } | 
|---|
| 41 |  | 
|---|
| 42 | void TOIManager::addThread(pthread_t* t) { | 
|---|
| 43 | //  cout << "adding thread  "  <<  t << endl; | 
|---|
| 44 | threads.push_back(t); | 
|---|
| 45 | } | 
|---|
| 46 |  | 
|---|
| 47 | void TOIManager::joinAll() { | 
|---|
| 48 | for (vector<pthread_t*>::iterator i = threads.begin(); | 
|---|
| 49 | i != threads.end(); i++) { | 
|---|
| 50 | pthread_t* pth = *i; | 
|---|
| 51 | cout << "joining thread  " << pth <<  endl; | 
|---|
| 52 | pthread_join(*pth, NULL); | 
|---|
| 53 | cout << "thread joined " << pth << endl; | 
|---|
| 54 | } | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|
| 57 |  | 
|---|
| 58 | // ----------------------------------------------------------------- | 
|---|
| 59 | //    Classe pour affichage de l'avancement des TOIProcessors | 
|---|
| 60 | //                         Reza 08/2001 | 
|---|
| 61 | // ----------------------------------------------------------------- | 
|---|
| 62 |  | 
|---|
| 63 | RzProcSampleCounter::RzProcSampleCounter() | 
|---|
| 64 | { | 
|---|
| 65 | _msg = "SampleCounter/Info"; | 
|---|
| 66 | _rate = 50; | 
|---|
| 67 | } | 
|---|
| 68 |  | 
|---|
| 69 | RzProcSampleCounter::~RzProcSampleCounter() | 
|---|
| 70 | { | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|
| 73 | long RzProcSampleCounter::PrintStats() | 
|---|
| 74 | { | 
|---|
| 75 | int istart = 0; | 
|---|
| 76 | int iend = 0; | 
|---|
| 77 | long dns_print = 1000; | 
|---|
| 78 | int dns_print_fac = _rate; | 
|---|
| 79 | int nbmax_dns_print = 2; | 
|---|
| 80 |  | 
|---|
| 81 | TOIManager* mgr = TOIManager::getManager(); | 
|---|
| 82 |  | 
|---|
| 83 | //  istart = mgr->getRequestedBegin(); | 
|---|
| 84 | //  iend = mgr->getRequestedEnd(); | 
|---|
| 85 | istart = SampleBegin(); | 
|---|
| 86 | iend = SampleEnd(); | 
|---|
| 87 |  | 
|---|
| 88 | dns_print = (iend-istart)/dns_print_fac; | 
|---|
| 89 | if (dns_print < 1000) dns_print = ((iend-istart) < 1000) ? (iend-istart) : 1000; | 
|---|
| 90 | if (dns_print < 1) dns_print = 1; | 
|---|
| 91 | nbmax_dns_print = (iend-istart)/dns_print; | 
|---|
| 92 |  | 
|---|
| 93 | cout << "RzProcSampleCounter::PrintStats() InfoMessage=" << _msg | 
|---|
| 94 | << "\n ... " << _msg << " istart=" | 
|---|
| 95 | << istart << " iend= " << iend << " dns_print= " << dns_print | 
|---|
| 96 | << " nbmax_dns_print= " << nbmax_dns_print << endl; | 
|---|
| 97 | // ------------------- Impression continu de stat ------------------------ | 
|---|
| 98 | long nb_dns_print = 0; | 
|---|
| 99 | int nb_sleep = 0; | 
|---|
| 100 | long last_sample_count = 0; | 
|---|
| 101 | long processed_samples = 0; | 
|---|
| 102 | long total_sample_count = dns_print*nbmax_dns_print; | 
|---|
| 103 | bool alldone = false; | 
|---|
| 104 | while (!alldone) { | 
|---|
| 105 | processed_samples = ProcessedSampleCount(); | 
|---|
| 106 | if ( (processed_samples-last_sample_count > dns_print) || | 
|---|
| 107 | (processed_samples > total_sample_count-10) ) { | 
|---|
| 108 | last_sample_count = processed_samples; | 
|---|
| 109 | if (nb_dns_print == 0) cout << "\n"; | 
|---|
| 110 | nb_dns_print++; | 
|---|
| 111 | cout << ">>> " << _msg << ": ProcessedSampleCount()= " << last_sample_count | 
|---|
| 112 | << " Frac done = " << processed_samples*100/total_sample_count << " %" << endl; | 
|---|
| 113 | if (last_sample_count > total_sample_count-10)  alldone = true; | 
|---|
| 114 | nb_sleep = 0; | 
|---|
| 115 | } | 
|---|
| 116 | else if ((nb_sleep+1)%5 == 0) | 
|---|
| 117 | cout << "> " << _msg << ": ProcSamples()= " <<  processed_samples | 
|---|
| 118 | << " Done = " << " %" << processed_samples*100/total_sample_count | 
|---|
| 119 | << " NbSleep(1) = " << nb_sleep << endl; | 
|---|
| 120 |  | 
|---|
| 121 | sleep(1);  nb_sleep++; | 
|---|
| 122 | } | 
|---|
| 123 |  | 
|---|
| 124 | // ----------------------------------------------------------------------- | 
|---|
| 125 |  | 
|---|
| 126 | return last_sample_count; | 
|---|
| 127 |  | 
|---|
| 128 | } | 
|---|