summaryrefslogtreecommitdiff
path: root/TAO/examples/RTScheduling/Task_Stats.h
blob: 2cd65095b426119b1a66399f5fb41e6fcc01fa49 (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
/* -*- C++ -*- */
//=============================================================================
/**
 *  @file Task_Stats.h
 *
 *  $Id$
 *
 *  Utility Stats class that maintains the readings.
 *
 *  @author Pradeep Gore <pradeep@cs.wustl.edu>
 */
//=============================================================================
#ifndef TASK_STATS_H
#define TASK_STATS_H

#include "rtschedtestlib_export.h"

#include "tao/orbconf.h"
#include "tao/debug.h"

#include "ace/OS_NS_time.h"
#include "ace/Singleton.h"

/**
 * @class Base_Time
 *
 * @brief maintains readings recorded by tasks.
 */
class RTSCHEDTESTLIB_Export Base_Time
{
 public:
  Base_Time (void);
  ACE_hrtime_t base_time_;
};

typedef ACE_Singleton<Base_Time, TAO_SYNCH_MUTEX> BASE_TIME;

/**
 * @class Task_Stats
 *
 * @brief maintains readings recorded by tasks.
 *
 */
class RTSCHEDTESTLIB_Export Task_Stats
{
 public:
  /// Constructor
  Task_Stats (void);

  /// Destructor
  ~Task_Stats (void);

  /// Init
  int init (size_t max_samples);

  /// Set the base time value.
  void base_time (ACE_hrtime_t time);

  /// Set the end time value.
  void end_time (ACE_hrtime_t time);

  /// Record a sample
  int sample (time_t thr_run_time, int thr_count);

  void dump_samples (const ACE_TCHAR *file_name, const ACE_TCHAR *msg);
 protected:
  void dump_latency_stats (ACE_TCHAR *out_msg, ACE_UINT32 sf);

  /// Base and end times
  ACE_hrtime_t base_time_;
  ACE_hrtime_t end_time_;

  /// The maximum number of samples
  ACE_UINT32 max_samples_;

  /// The number of samples
  ACE_UINT32 samples_count_;

  /// The samples : the time of execution. and the recorded exec. time .
  time_t *thr_run_time_;
  int *thr_count_;

  /// The minimum value
  ACE_UINT64 exec_time_min_;

  /// The number of the sample that had the minimum value
  ACE_UINT32 exec_time_min_at_;

  /// The maximum value
  ACE_UINT64 exec_time_max_;

  /// The number of the sample that had the maximum value
  ACE_UINT32 exec_time_max_at_;

  /// The sum of all the values
  ACE_UINT64 sum_;

  /// The sum of the square of all the values
  ACE_UINT64 sum2_;
};

typedef ACE_Singleton<Task_Stats, TAO_SYNCH_MUTEX> TASK_STATS;

#if defined (__ACE_INLINE__)
#include "Task_Stats.inl"
#endif /* __ACE_INLINE__ */

#endif /* TASK_STATS_H */