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

Last change on this file since 2125 was 2077, checked in by ansari, 23 years ago

Correction print ds ProcSampleCounter / suite - Reza 18/6/2002

File size: 3.8 KB
RevLine 
[1738]1// ArchTOIPipe (C) CEA/DAPNIA/SPP IN2P3/LAL
2// Eric Aubourg
3// Christophe Magneville
4// Reza Ansari
[2077]5// $Id: toimanager.cc,v 1.15 2002-06-18 21:15:19 ansari Exp $
[1738]6
[1365]7#include "toimanager.h"
8#include <limits.h>
9#include <pthread.h>
[1759]10#include <iostream.h>
[1704]11#include <unistd.h>
[1365]12
[1702]13#ifndef MAXINT
14#define MAXINT 2147483647
15#endif
16
[1365]17TOIManager::TOIManager() {
18 reqBegin = 0;
[1702]19 reqEnd = MAXINT;
[1365]20}
21
22TOIManager* TOIManager::instance = NULL;
23
24TOIManager* TOIManager::getManager() {
25 if (instance == NULL) instance = new TOIManager();
26 return instance;
27}
28
[1702]29void TOIManager::setRequestedSample(int begin, int end) {
[1365]30 reqBegin = begin;
31 reqEnd = end;
32}
33
[1702]34int TOIManager::getRequestedBegin() {
[1365]35 return reqBegin;
36}
37
[1702]38int TOIManager::getRequestedEnd() {
[1365]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}
[1687]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
[1999]83 // istart = mgr->getRequestedBegin();
84 // iend = mgr->getRequestedEnd();
85 istart = SampleBegin();
86 iend = SampleEnd();
[1687]87
88 dns_print = (iend-istart)/dns_print_fac;
89 if (dns_print < 1000) dns_print = ((iend-istart) < 1000) ? (iend-istart) : 1000;
90 if (dns_print < 1) dns_print = 1;
91 nbmax_dns_print = (iend-istart)/dns_print;
92
93 cout << "RzProcSampleCounter::PrintStats() InfoMessage=" << _msg
94 << "\n ... " << _msg << " istart="
95 << istart << " iend= " << iend << " dns_print= " << dns_print
96 << " nbmax_dns_print= " << nbmax_dns_print << endl;
97 // ------------------- Impression continu de stat ------------------------
98 long nb_dns_print = 0;
99 int nb_sleep = 0;
100 long last_sample_count = 0;
101 long processed_samples = 0;
102 long total_sample_count = dns_print*nbmax_dns_print;
103 bool alldone = false;
[2077]104 double fracperc = 0.;
105 int fperc = 0;
[1687]106 while (!alldone) {
107 processed_samples = ProcessedSampleCount();
108 if ( (processed_samples-last_sample_count > dns_print) ||
[1702]109 (processed_samples > total_sample_count-10) ) {
[1687]110 last_sample_count = processed_samples;
111 if (nb_dns_print == 0) cout << "\n";
112 nb_dns_print++;
[2077]113 fracperc = (double)processed_samples*100./(double)total_sample_count;
114 fperc = fracperc*100;
[1687]115 cout << ">>> " << _msg << ": ProcessedSampleCount()= " << last_sample_count
[2077]116 << " Frac done = " << (double)fperc/100. << " %" << endl;
[1687]117 if (last_sample_count > total_sample_count-10) alldone = true;
118 nb_sleep = 0;
119 }
[2077]120 else if ((nb_sleep+1)%5 == 0) {
121 fracperc = (double)processed_samples*100./(double)total_sample_count;
122 fperc = fracperc*100;
[1687]123 cout << "> " << _msg << ": ProcSamples()= " << processed_samples
[2077]124 << " Done = " << " %" << (double)fperc/100.
[1702]125 << " NbSleep(1) = " << nb_sleep << endl;
[2077]126 }
[1687]127 sleep(1); nb_sleep++;
128 }
129
130 // -----------------------------------------------------------------------
131
132 return last_sample_count;
133
134}
Note: See TracBrowser for help on using the repository browser.