summaryrefslogtreecommitdiff
path: root/TAO/tests/Param_Test/results.cpp
blob: 405441edf59b3b4339b972541a00f8507bebdd38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// $Id$

// ============================================================================
//
// = LIBRARY
//    TAO/tests/Param_Test
//
// = FILENAME
//    results.cpp
//
// = DESCRIPTION
//    Printing the results
//
// = AUTHORS
//    Aniruddha Gokhale
//
// ============================================================================

#include "ace/Log_Msg.h"
#include "results.h"

ACE_RCSID(Param_Test, results, "$Id$")

Results::Results (void)
{
}

Results::~Results (void)
{
  delete [] this->elapsed_time_;
}

void
Results::print_stats (void)
{
  double
    avg_real_time = 0,
    avg_user_time = 0,
    avg_system_time = 0,
    cps; // calls per sec

  CORBA::ULong i;

  if (this->error_count_ == 0)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "Iteration\tReal time (msec)\tUser time (msec)"
                  "\tSystem time (msec)\n\n"));
      for (i = 0; i < this->call_count_; i++)
        {
          this->elapsed_time_[i].real_time *= ACE_ONE_SECOND_IN_MSECS;
          this->elapsed_time_[i].user_time *= ACE_ONE_SECOND_IN_MSECS;
          this->elapsed_time_[i].system_time *= ACE_ONE_SECOND_IN_MSECS;
          avg_real_time += this->elapsed_time_[i].real_time;
          avg_user_time += this->elapsed_time_[i].user_time;
          avg_system_time += this->elapsed_time_[i].system_time;

          ACE_DEBUG ((LM_DEBUG,
                      "%u\t\t%0.06f\t\t%0.06f\t\t%0.06f\n",
                      i,
                      (this->elapsed_time_[i].real_time < 0.0?
                       0.0:this->elapsed_time_[i].real_time),
                      (this->elapsed_time_[i].user_time < 0.0?
                       0.0:this->elapsed_time_[i].user_time),
                      (this->elapsed_time_[i].system_time < 0.0?
                       0.0:this->elapsed_time_[i].system_time)));
        } // end of for loop

      // compute average
      avg_real_time /= this->call_count_;
      avg_user_time /= this->call_count_;
      avg_system_time /= this->call_count_;
      cps = 1000 / avg_real_time;

      ACE_DEBUG ((LM_DEBUG,
                  "\n*=*=*=*=*= Average *=*=*=*=*=*=\n"
                  "\treal_time\t= %0.06f ms, \n"
                  "\tuser_time\t= %0.06f ms, \n"
                  "\tsystem_time\t= %0.06f ms\n"
                  "\t%0.00f calls/second\n"
                  "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=\n",
                  (avg_real_time < 0.0? 0.0:avg_real_time),
                  (avg_user_time < 0.0? 0.0:avg_user_time),
                  (avg_system_time < 0.0? 0.0:avg_system_time),
                  (cps < 0.0? 0.0 : cps)));

    }
  else
    {
      ACE_ERROR ((LM_ERROR,
                  "\tNo time stats printed.  Call count zero or error ocurred.\n"));

    }

  ACE_DEBUG ((LM_DEBUG,
              "\t%d calls, %d errors\n"
              "*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=\n",
              this->call_count_,
              this->error_count_));
}

void
Results::print_exception (const char *call_name,
                          CORBA::Environment &env)
{
  env.print_exception (call_name);
}

void
Results::start_timer (void)
{
  this->timer_.start ();
}

void
Results::stop_timer (void)
{
  this->timer_.stop ();
  this->timer_.elapsed_time (this->elapsed_time_[this->call_count_-1]);
}

CORBA::ULong
Results::call_count (void)
{
  return this->call_count_;
}

void
Results::call_count (CORBA::ULong c)
{
  this->call_count_ = c;
}

CORBA::ULong
Results::error_count (void)
{
  return this->error_count_;
}

void
Results::error_count (CORBA::ULong c)
{
  this->error_count_ = c;
}

void
Results::iterations (CORBA::ULong iters)
{
  this->elapsed_time_ = new ACE_Profile_Timer::ACE_Elapsed_Time [iters];
}