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

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

intro des toisegmented + constructeur avec char* pour compat cmv 15/10/01

File size: 3.2 KB
Line 
1#include "toimanager.h"
2#include <unistd.h>
3#include <limits.h>
4#include <pthread.h>
5#include <iostream.h>
6
7TOIManager::TOIManager() {
8 reqBegin = 0;
9 reqEnd = LONG_MAX;
10}
11
12TOIManager* TOIManager::instance = NULL;
13
14TOIManager* TOIManager::getManager() {
15 if (instance == NULL) instance = new TOIManager();
16 return instance;
17}
18
19void TOIManager::setRequestedSample(long begin, long end) {
20 reqBegin = begin;
21 reqEnd = end;
22}
23
24long TOIManager::getRequestedBegin() {
25 return reqBegin;
26}
27
28long TOIManager::getRequestedEnd() {
29 return reqEnd;
30}
31
32void TOIManager::addThread(pthread_t* t) {
33 // cout << "adding thread " << t << endl;
34 threads.push_back(t);
35}
36
37void 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}
46
47
48// -----------------------------------------------------------------
49// Classe pour affichage de l'avancement des TOIProcessors
50// Reza 08/2001
51// -----------------------------------------------------------------
52
53RzProcSampleCounter::RzProcSampleCounter()
54{
55 _msg = "SampleCounter/Info";
56 _rate = 50;
57}
58
59RzProcSampleCounter::~RzProcSampleCounter()
60{
61}
62
63long 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) ||
95 (processed_samples > total_sample_count-10) ) {
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
100 << " Frac done = " << processed_samples*100/total_sample_count << " %" << endl;
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
106 << " Done = " << " %" << processed_samples*100/total_sample_count
107 << " NbSleep(1) = " << nb_sleep << endl;
108
109 sleep(1); nb_sleep++;
110 }
111
112 // -----------------------------------------------------------------------
113
114 return last_sample_count;
115
116}
Note: See TracBrowser for help on using the repository browser.