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