Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / apps / JAWS / stress_testing / stats.cpp
blobbeb1c0014abd6513d5ee0fdf960cecb6cc2d3818
1 #include "stats.h"
3 Stats::Stats(int size) {
4 throughput_ = new float[size];
5 latency_ = new float[size];
6 thread_count_ = 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;
17 // Unused for now.
18 void Stats::print(char *message) {
19 ACE_UNUSED_ARG (message);
21 // char time_buf[64];
22 // long ltime;
23 // time(&ltime);
25 // ACE_OS::ctime_r(&ltime, time_buf, sizeof time_buf);
27 // if(ACE_OS::gettimeofday() == -1) {
28 // perror("gettimeofday");
29 // }
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() {
44 int i;
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)
55 max = thread_peak;
57 else thread_peak--;
59 for(i = 0; i < thread_count_; i++) {
60 tavg += throughput_[i];
61 lavg += latency_[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();