3 Stats::Stats(int size
) {
4 throughput_
= new float[size
];
5 latency_
= new float[size
];
7 init_fini_
= new Init_Fini_t
[2*size
];
8 for(int i
= 0; i
< size
; i
++)
9 throughput_
[i
] = latency_
[i
] = 0;
12 void Stats::log(int id
, float throughput
, float latency
) {
13 throughput_
[id
] = throughput
;
14 latency_
[id
] = latency
;
18 void Stats::print(char *message
) {
19 ACE_UNUSED_ARG (message
);
25 // ACE_OS::ctime_r(<ime, time_buf, sizeof time_buf);
27 // if(ACE_OS::gettimeofday() == -1) {
28 // perror("gettimeofday");
30 // time_buf[strlen(time_buf)-1] = 0;
31 // printf("%010ld%09ld \t %s %s\n", tp.tv_sec, tp.tv_usec, time_buf, message);
35 int comp(const void *a
, const void *b
) {
36 Init_Fini_t
*A
= (Init_Fini_t
*)a
;
37 Init_Fini_t
*B
= (Init_Fini_t
*)b
;
39 return (A
->timestamp
< B
->timestamp
) ? -1 : (A
->timestamp
> B
->timestamp
);
43 void Stats::output() {
45 float tavg
= 0, lavg
= 0;
47 ACE_OS::qsort(init_fini_
, 2*thread_count_
, sizeof(Init_Fini_t
), comp
);
49 int max
= 0,thread_peak
= 0;
51 for(i
= 0; i
< 2*thread_count_
; i
++) {
52 // cerr << " " << ((init_fini_[i].type == THREAD_START) ? "START": "END") << " " << init_fini_[i].timestamp.sec() << "." << init_fini_[i].timestamp.usec() << endl;
53 if(init_fini_
[i
].type
== THREAD_START
) {
54 if(++thread_peak
> max
)
59 for(i
= 0; i
< thread_count_
; i
++) {
60 tavg
+= throughput_
[i
];
63 cout
<< " " << tavg
/thread_count_
<< " " << lavg
/thread_count_
<< " " << max
;
67 void Stats::i_have_started(int id
) {
68 init_fini_
[2*id
].type
= THREAD_START
;
69 init_fini_
[2*id
].timestamp
= ACE_OS::gettimeofday();
72 void Stats::i_am_done(int id
) {
73 init_fini_
[(2*id
)+1].type
= THREAD_END
;
75 init_fini_
[(2*id
)+1].timestamp
= ACE_OS::gettimeofday();