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