source: Sophya/trunk/ArchTOIPipe/Kernel/toimanager.cc@ 1712

Last change on this file since 1712 was 1704, checked in by cmv, 24 years ago

unistd.h pour sleep 17/10/01

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