1 |
francois |
277 |
#include "gestionversion.h" |
2 |
|
|
#include "ot_cpu.h" |
3 |
|
|
#include <stdio.h> |
4 |
|
|
#include <map> |
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 |
|
|
OT_CPU::OT_CPU() |
11 |
|
|
{ |
12 |
|
|
initialise(); |
13 |
|
|
} |
14 |
|
|
|
15 |
|
|
OT_CPU::OT_CPU(OT_CPU &mdd) |
16 |
|
|
{ |
17 |
|
|
for (int i=0;i<mdd.tabcpu.size();i++) |
18 |
|
|
tabcpu.insert(tabcpu.end(),mdd.tabcpu[i]); |
19 |
|
|
for (int i=0;i<mdd.tabnom.size();i++) |
20 |
|
|
tabnom.insert(tabnom.end(),mdd.tabnom[i]); |
21 |
|
|
} |
22 |
|
|
|
23 |
|
|
OT_CPU::~OT_CPU() |
24 |
|
|
{ |
25 |
|
|
} |
26 |
|
|
|
27 |
|
|
|
28 |
|
|
void OT_CPU::initialise(void) |
29 |
|
|
{ |
30 |
|
|
tabcpu.clear(); |
31 |
|
|
tabnom.clear(); |
32 |
|
|
tabcpu.insert(tabcpu.end(),clock()); |
33 |
|
|
tabnom.insert(tabnom.end(),"Initialisation"); |
34 |
|
|
} |
35 |
|
|
|
36 |
|
|
|
37 |
|
|
int OT_CPU::ajouter_etape(std::string nom) |
38 |
|
|
{ |
39 |
|
|
tabcpu.insert(tabcpu.end(),clock()); |
40 |
|
|
tabnom.insert(tabnom.end(),nom); |
41 |
|
|
return tabcpu.size(); |
42 |
|
|
} |
43 |
|
|
|
44 |
|
|
int OT_CPU::get_nb_etape(void) |
45 |
|
|
{ |
46 |
|
|
return tabcpu.size()-1; |
47 |
|
|
} |
48 |
|
|
|
49 |
|
|
void OT_CPU::get_etape(int num,std::string &nom,double &temps) |
50 |
|
|
{ |
51 |
|
|
temps=1.*(tabcpu[num]-tabcpu[num-1]); |
52 |
|
|
temps=temps*1/CLOCKS_PER_SEC; |
53 |
|
|
nom=tabnom[num]; |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
|
57 |
|
|
void OT_CPU::get_etape(std::string nom,double &temps) |
58 |
|
|
{ |
59 |
|
|
temps=0.; |
60 |
|
|
for (int i=0;i<get_nb_etape();i++) |
61 |
|
|
{ |
62 |
|
|
std::string nomtmp; |
63 |
|
|
double tempstmp; |
64 |
|
|
get_etape(i+1,nomtmp,tempstmp); |
65 |
|
|
if (nomtmp==nom) temps=temps+tempstmp; |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
void OT_CPU::get_etape(int num1,int num2,std::string &nom,double &temps) |
71 |
|
|
{ |
72 |
|
|
temps=1.*(tabcpu[num2]-tabcpu[num1-1]); |
73 |
|
|
temps=temps*1/CLOCKS_PER_SEC; |
74 |
|
|
nom=tabnom[num1]+"-"+tabnom[num2]; |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
void OT_CPU::get_total(int num,double &temps) |
78 |
|
|
{ |
79 |
|
|
temps=1.*(tabcpu[num]-tabcpu[0]); |
80 |
|
|
temps=temps*1./CLOCKS_PER_SEC; |
81 |
|
|
} |
82 |
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
void OT_CPU::get_tabfinal(std::vector<std::string> &tab) |
86 |
|
|
{ |
87 |
|
|
tab.clear(); |
88 |
|
|
std::string nom; |
89 |
|
|
double temps; |
90 |
|
|
char mess[255]; |
91 |
|
|
sprintf(mess," Temps CPU :"); |
92 |
|
|
tab.insert(tab.end(),mess); |
93 |
|
|
for (int i=0;i<get_nb_etape();i++) |
94 |
|
|
{ |
95 |
|
|
get_etape(i+1,nom,temps); |
96 |
|
|
char mess[255]; |
97 |
|
|
sprintf(mess," %30s : %.2lf s",nom.c_str(),temps); |
98 |
|
|
tab.insert(tab.end(),mess); |
99 |
|
|
} |
100 |
|
|
get_total(get_nb_etape(),temps); |
101 |
|
|
nom="Total"; |
102 |
|
|
sprintf(mess," %30s : %.2lf s",nom.c_str(),temps); |
103 |
|
|
tab.insert(tab.end(),mess); |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
void OT_CPU::get_tabfinalcompresse(std::vector<std::string> &tab) |
107 |
|
|
{ |
108 |
|
|
tab.clear(); |
109 |
|
|
std::string nom; |
110 |
|
|
double temps; |
111 |
|
|
char mess[255]; |
112 |
|
|
sprintf(mess," Temps CPU :"); |
113 |
|
|
tab.insert(tab.end(),mess); |
114 |
|
|
std::map<std::string,std::string> lst; |
115 |
|
|
for (int i=0;i<get_nb_etape();i++) |
116 |
|
|
{ |
117 |
|
|
get_etape(i+1,nom,temps); |
118 |
|
|
std::map<std::string,std::string>::iterator it=lst.find(nom); |
119 |
|
|
if (it==lst.end()) |
120 |
|
|
{ |
121 |
|
|
get_etape(nom,temps); |
122 |
|
|
char mess[255]; |
123 |
|
|
sprintf(mess," %30s : %.2lf s",nom.c_str(),temps); |
124 |
|
|
tab.insert(tab.end(),mess); |
125 |
|
|
std::pair<std::string,std::string> tmp(nom,nom); |
126 |
|
|
lst.insert(tmp); |
127 |
|
|
} |
128 |
|
|
} |
129 |
|
|
get_total(get_nb_etape(),temps); |
130 |
|
|
nom="Total"; |
131 |
|
|
sprintf(mess," %30s : %.2lf s",nom.c_str(),temps); |
132 |
|
|
tab.insert(tab.end(),mess); |
133 |
|
|
} |
134 |
|
|
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
void OT_CPU::enregistrer(char* fichier) |
138 |
|
|
{ |
139 |
|
|
std::vector<std::string> tab1,tab2; |
140 |
|
|
get_tabfinal(tab1); |
141 |
|
|
get_tabfinalcompresse(tab2); |
142 |
|
|
FILE *out=fopen(fichier,"rt"); |
143 |
|
|
for (int i=0;i<tab1.size();i++) |
144 |
|
|
fprintf(out,"%s\n",(char*)tab1[i].c_str()); |
145 |
|
|
for (int i=0;i<tab2.size();i++) |
146 |
|
|
fprintf(out,"%s\n",(char*)tab2[i].c_str()); |
147 |
|
|
fclose(out); |
148 |
|
|
} |
149 |
|
|
|