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

Last change on this file since 1996 was 1759, checked in by aubourg, 24 years ago

on rechange les include stl pour !&@@ SGI.

File size: 3.5 KB
Line 
1// ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
2// Eric Aubourg
3// Christophe Magneville
4// Reza Ansari
5// $Id: toimanager.cc,v 1.12 2001-11-13 15:47:26 aubourg 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
17TOIManager::TOIManager() {
18 reqBegin = 0;
19 reqEnd = MAXINT;
20}
21
22TOIManager* TOIManager::instance = NULL;
23
24TOIManager* TOIManager::getManager() {
25 if (instance == NULL) instance = new TOIManager();
26 return instance;
27}
28
29void TOIManager::setRequestedSample(int begin, int end) {
30 reqBegin = begin;
31 reqEnd = end;
32}
33
34int TOIManager::getRequestedBegin() {
35 return reqBegin;
36}
37
38int TOIManager::getRequestedEnd() {
39 return reqEnd;
40}
41
42void TOIManager::addThread(pthread_t* t) {
43 // cout << "adding thread " << t << endl;
44 threads.push_back(t);
45}
46
47void 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
63RzProcSampleCounter::RzProcSampleCounter()
64{
65 _msg = "SampleCounter/Info";
66 _rate = 50;
67}
68
69RzProcSampleCounter::~RzProcSampleCounter()
70{
71}
72
73long 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
86 dns_print = (iend-istart)/dns_print_fac;
87 if (dns_print < 1000) dns_print = ((iend-istart) < 1000) ? (iend-istart) : 1000;
88 if (dns_print < 1) dns_print = 1;
89 nbmax_dns_print = (iend-istart)/dns_print;
90
91 cout << "RzProcSampleCounter::PrintStats() InfoMessage=" << _msg
92 << "\n ... " << _msg << " istart="
93 << istart << " iend= " << iend << " dns_print= " << dns_print
94 << " nbmax_dns_print= " << nbmax_dns_print << endl;
95 // ------------------- Impression continu de stat ------------------------
96 long nb_dns_print = 0;
97 int nb_sleep = 0;
98 long last_sample_count = 0;
99 long processed_samples = 0;
100 long total_sample_count = dns_print*nbmax_dns_print;
101 bool alldone = false;
102 while (!alldone) {
103 processed_samples = ProcessedSampleCount();
104 if ( (processed_samples-last_sample_count > dns_print) ||
105 (processed_samples > total_sample_count-10) ) {
106 last_sample_count = processed_samples;
107 if (nb_dns_print == 0) cout << "\n";
108 nb_dns_print++;
109 cout << ">>> " << _msg << ": ProcessedSampleCount()= " << last_sample_count
110 << " Frac done = " << processed_samples*100/total_sample_count << " %" << endl;
111 if (last_sample_count > total_sample_count-10) alldone = true;
112 nb_sleep = 0;
113 }
114 else if ((nb_sleep+1)%5 == 0)
115 cout << "> " << _msg << ": ProcSamples()= " << processed_samples
116 << " Done = " << " %" << processed_samples*100/total_sample_count
117 << " NbSleep(1) = " << nb_sleep << endl;
118
119 sleep(1); nb_sleep++;
120 }
121
122 // -----------------------------------------------------------------------
123
124 return last_sample_count;
125
126}
Note: See TracBrowser for help on using the repository browser.