1 |
francois |
1156 |
//####//------------------------------------------------------------ |
2 |
|
|
//####//------------------------------------------------------------ |
3 |
|
|
//####// MAGiC |
4 |
|
|
//####// Jean Christophe Cuilliere et Vincent FRANCOIS |
5 |
|
|
//####// Departement de Genie Mecanique - UQTR |
6 |
|
|
//####//------------------------------------------------------------ |
7 |
|
|
//####// MAGIC est un projet de recherche de l equipe ERICCA |
8 |
|
|
//####// du departement de genie mecanique de l Universite du Quebec a Trois Rivieres |
9 |
|
|
//####// http://www.uqtr.ca/ericca |
10 |
|
|
//####// http://www.uqtr.ca/ |
11 |
|
|
//####//------------------------------------------------------------ |
12 |
|
|
//####//------------------------------------------------------------ |
13 |
|
|
//####// |
14 |
|
|
//####// ot_cpu.cpp |
15 |
|
|
//####// |
16 |
|
|
//####//------------------------------------------------------------ |
17 |
|
|
//####//------------------------------------------------------------ |
18 |
|
|
//####// COPYRIGHT 2000-2024 |
19 |
|
|
//####// jeu 13 jun 2024 11:54:00 EDT |
20 |
|
|
//####//------------------------------------------------------------ |
21 |
|
|
//####//------------------------------------------------------------ |
22 |
francois |
277 |
#include "ot_cpu.h" |
23 |
|
|
#include <stdio.h> |
24 |
|
|
#include <map> |
25 |
|
|
|
26 |
francois |
674 |
double CODE_ASTER_CPU; |
27 |
francois |
727 |
double CODE_ASTER_ECOULE; |
28 |
francois |
277 |
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
OT_CPU::OT_CPU() |
32 |
|
|
{ |
33 |
francois |
283 |
initialise(); |
34 |
francois |
277 |
} |
35 |
|
|
|
36 |
|
|
OT_CPU::OT_CPU(OT_CPU &mdd) |
37 |
|
|
{ |
38 |
francois |
283 |
for (int i=0;i<mdd.tabcpu.size();i++) |
39 |
|
|
tabcpu.insert(tabcpu.end(),mdd.tabcpu[i]); |
40 |
|
|
for (int i=0;i<mdd.tabnom.size();i++) |
41 |
|
|
tabnom.insert(tabnom.end(),mdd.tabnom[i]); |
42 |
francois |
277 |
} |
43 |
|
|
|
44 |
|
|
OT_CPU::~OT_CPU() |
45 |
|
|
{ |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
|
49 |
|
|
void OT_CPU::initialise(void) |
50 |
|
|
{ |
51 |
francois |
283 |
tabcpu.clear(); |
52 |
|
|
tabnom.clear(); |
53 |
|
|
tabcpu.insert(tabcpu.end(),clock()); |
54 |
|
|
tabnom.insert(tabnom.end(),"Initialisation"); |
55 |
francois |
277 |
} |
56 |
|
|
|
57 |
|
|
|
58 |
francois |
410 |
double OT_CPU::ajouter_etape(std::string nom) |
59 |
francois |
277 |
{ |
60 |
francois |
283 |
tabcpu.insert(tabcpu.end(),clock()); |
61 |
|
|
tabnom.insert(tabnom.end(),nom); |
62 |
francois |
410 |
double temps=tabcpu[tabcpu.size()-1]-tabcpu[tabcpu.size()-2]; |
63 |
|
|
return temps/CLOCKS_PER_SEC; |
64 |
francois |
277 |
} |
65 |
|
|
|
66 |
|
|
int OT_CPU::get_nb_etape(void) |
67 |
|
|
{ |
68 |
francois |
283 |
return tabcpu.size()-1; |
69 |
francois |
277 |
} |
70 |
|
|
|
71 |
|
|
void OT_CPU::get_etape(int num,std::string &nom,double &temps) |
72 |
|
|
{ |
73 |
francois |
283 |
temps=1.*(tabcpu[num]-tabcpu[num-1]); |
74 |
francois |
410 |
temps=temps*1./CLOCKS_PER_SEC; |
75 |
francois |
283 |
nom=tabnom[num]; |
76 |
francois |
277 |
} |
77 |
|
|
|
78 |
|
|
|
79 |
|
|
void OT_CPU::get_etape(std::string nom,double &temps) |
80 |
|
|
{ |
81 |
francois |
283 |
temps=0.; |
82 |
|
|
for (int i=0;i<get_nb_etape();i++) |
83 |
|
|
{ |
84 |
|
|
std::string nomtmp; |
85 |
|
|
double tempstmp; |
86 |
|
|
get_etape(i+1,nomtmp,tempstmp); |
87 |
|
|
if (nomtmp==nom) temps=temps+tempstmp; |
88 |
|
|
} |
89 |
francois |
277 |
|
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
void OT_CPU::get_etape(int num1,int num2,std::string &nom,double &temps) |
93 |
|
|
{ |
94 |
francois |
283 |
temps=1.*(tabcpu[num2]-tabcpu[num1-1]); |
95 |
|
|
temps=temps*1/CLOCKS_PER_SEC; |
96 |
|
|
nom=tabnom[num1]+"-"+tabnom[num2]; |
97 |
francois |
277 |
} |
98 |
|
|
|
99 |
|
|
void OT_CPU::get_total(int num,double &temps) |
100 |
|
|
{ |
101 |
francois |
283 |
temps=1.*(tabcpu[num]-tabcpu[0]); |
102 |
|
|
temps=temps*1./CLOCKS_PER_SEC; |
103 |
francois |
277 |
} |
104 |
|
|
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
void OT_CPU::get_tabfinal(std::vector<std::string> &tab) |
108 |
|
|
{ |
109 |
francois |
283 |
tab.clear(); |
110 |
|
|
std::string nom; |
111 |
|
|
double temps; |
112 |
|
|
char mess[255]; |
113 |
|
|
for (int i=0;i<get_nb_etape();i++) |
114 |
|
|
{ |
115 |
|
|
get_etape(i+1,nom,temps); |
116 |
|
|
char mess[255]; |
117 |
|
|
sprintf(mess," %30s : %.2lf s",nom.c_str(),temps); |
118 |
|
|
tab.insert(tab.end(),mess); |
119 |
|
|
} |
120 |
|
|
get_total(get_nb_etape(),temps); |
121 |
|
|
nom="Total"; |
122 |
|
|
sprintf(mess," %30s : %.2lf s",nom.c_str(),temps); |
123 |
|
|
tab.insert(tab.end(),mess); |
124 |
francois |
277 |
} |
125 |
|
|
|
126 |
|
|
void OT_CPU::get_tabfinalcompresse(std::vector<std::string> &tab) |
127 |
|
|
{ |
128 |
francois |
283 |
tab.clear(); |
129 |
|
|
std::string nom; |
130 |
|
|
double temps; |
131 |
|
|
char mess[255]; |
132 |
|
|
std::map<std::string,std::string> lst; |
133 |
|
|
for (int i=0;i<get_nb_etape();i++) |
134 |
|
|
{ |
135 |
|
|
get_etape(i+1,nom,temps); |
136 |
|
|
std::map<std::string,std::string>::iterator it=lst.find(nom); |
137 |
|
|
if (it==lst.end()) |
138 |
|
|
{ |
139 |
|
|
get_etape(nom,temps); |
140 |
|
|
char mess[255]; |
141 |
|
|
sprintf(mess," %30s : %.2lf s",nom.c_str(),temps); |
142 |
|
|
tab.insert(tab.end(),mess); |
143 |
|
|
std::pair<std::string,std::string> tmp(nom,nom); |
144 |
|
|
lst.insert(tmp); |
145 |
|
|
} |
146 |
|
|
} |
147 |
|
|
get_total(get_nb_etape(),temps); |
148 |
|
|
nom="Total"; |
149 |
|
|
sprintf(mess," %30s : %.2lf s",nom.c_str(),temps); |
150 |
|
|
tab.insert(tab.end(),mess); |
151 |
francois |
277 |
} |
152 |
|
|
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
void OT_CPU::enregistrer(char* fichier) |
156 |
|
|
{ |
157 |
francois |
283 |
std::vector<std::string> tab1,tab2; |
158 |
|
|
get_tabfinal(tab1); |
159 |
|
|
get_tabfinalcompresse(tab2); |
160 |
couturad |
944 |
FILE *out=fopen(fichier,"wt"); |
161 |
francois |
283 |
for (int i=0;i<tab1.size();i++) |
162 |
|
|
fprintf(out,"%s\n",(char*)tab1[i].c_str()); |
163 |
|
|
for (int i=0;i<tab2.size();i++) |
164 |
|
|
fprintf(out,"%s\n",(char*)tab2[i].c_str()); |
165 |
|
|
fclose(out); |
166 |
francois |
277 |
} |
167 |
|
|
|
168 |
francois |
532 |
void OT_CPU::affiche(void) |
169 |
|
|
{ |
170 |
|
|
std::vector<std::string> tab1; |
171 |
|
|
get_tabfinal(tab1); |
172 |
|
|
for (int i=0;i<tab1.size();i++) |
173 |
|
|
printf("%s\n",(char*)tab1[i].c_str()); |
174 |
|
|
|
175 |
|
|
} |
176 |
|
|
|
177 |
|
|
void OT_CPU::affichecompresser(void) |
178 |
|
|
{ |
179 |
|
|
std::vector<std::string> tab2; |
180 |
|
|
get_tabfinalcompresse(tab2); |
181 |
|
|
for (int i=0;i<tab2.size();i++) |
182 |
|
|
printf("%s\n",(char*)tab2[i].c_str()); |
183 |
|
|
} |
184 |
|
|
|