~ps10gel/ubuntu/xenial/trafficserver/6.2.0

« back to all changes in this revision

Viewing changes to proxy/mgmt2/stats/StatType.h

  • Committer: Bazaar Package Importer
  • Author(s): Arno Toell
  • Date: 2011-01-13 11:49:18 UTC
  • Revision ID: james.westby@ubuntu.com-20110113114918-vu422h8dknrgkj15
Tags: upstream-2.1.5-unstable
ImportĀ upstreamĀ versionĀ 2.1.5-unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file
 
2
 
 
3
  A brief file description
 
4
 
 
5
  @section license License
 
6
 
 
7
  Licensed to the Apache Software Foundation (ASF) under one
 
8
  or more contributor license agreements.  See the NOTICE file
 
9
  distributed with this work for additional information
 
10
  regarding copyright ownership.  The ASF licenses this file
 
11
  to you under the Apache License, Version 2.0 (the
 
12
  "License"); you may not use this file except in compliance
 
13
  with the License.  You may obtain a copy of the License at
 
14
 
 
15
      http://www.apache.org/licenses/LICENSE-2.0
 
16
 
 
17
  Unless required by applicable law or agreed to in writing, software
 
18
  distributed under the License is distributed on an "AS IS" BASIS,
 
19
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
20
  See the License for the specific language governing permissions and
 
21
  limitations under the License.
 
22
 */
 
23
 
 
24
/***************************************/
 
25
/****************************************************************************
 
26
 *
 
27
 *  StatType.h - Functions for computing node and cluster stat
 
28
 *                          aggregation
 
29
 *
 
30
 *
 
31
 ****************************************************************************/
 
32
 
 
33
#ifndef _STATTYPE_H_
 
34
#define _STATTYPE_H_
 
35
 
 
36
#include "StatXML.h"
 
37
#include "Main.h"               // Debug()
 
38
#include "WebMgmtUtils.h"
 
39
 
 
40
#define BYTES_TO_MBIT_SCALE (8/1000000.0)
 
41
 
 
42
#if defined MODULARIZED
 
43
 
 
44
#define ERROR_VALUE      0
 
45
#define StatDataT        RecDataT
 
46
#define StatFloat        RecFloat
 
47
#define StatInt          RecInt
 
48
#define StatCounter      RecCounter
 
49
#define StatString       RecString
 
50
 
 
51
#define STAT_INT         RECD_INT
 
52
#define STAT_FLOAT       RECD_FLOAT
 
53
#define STAT_STRING      RECD_STRING
 
54
#define STAT_COUNTER     RECD_COUNTER
 
55
#define STAT_CONST       RECD_STAT_CONST
 
56
#define STAT_FX          RECD_STAT_FX
 
57
 
 
58
/* Structs used in Average Statistics calculations */
 
59
struct StatFloatSamples
 
60
{
 
61
  ink_hrtime previous_time;
 
62
  ink_hrtime current_time;
 
63
  StatFloat previous_value;
 
64
  StatFloat current_value;
 
65
 
 
66
  StatFloat diff_value()
 
67
  {
 
68
    return (current_value - previous_value);
 
69
  }
 
70
  ink_hrtime diff_time()
 
71
  {
 
72
    return (current_time - previous_time);
 
73
  }
 
74
};
 
75
 
 
76
#else
 
77
 
 
78
#include "MgmtDefs.h"
 
79
#define ERROR_VALUE      -9999.0
 
80
#define StatDataT        MgmtType
 
81
#define StatFloat        MgmtFloat
 
82
#define StatInt          MgmtInt
 
83
#define StatCounter      MgmtIntCounter
 
84
#define StatString       MgmtString
 
85
 
 
86
#define STAT_INT         INK_INT
 
87
#define STAT_FLOAT       INK_FLOAT
 
88
#define STAT_STRING      INK_STRING
 
89
#define STAT_COUNTER     INK_COUNTER
 
90
#define STAT_CONST       INK_STAT_CONST
 
91
#define STAT_FX          INK_STAT_FX
 
92
 
 
93
#define StatFloatSamples StatTwoFloatSamples
 
94
#endif
 
95
 
 
96
// Urgly workaround -- no optimization in HPUX
 
97
#if defined(hpux)
 
98
#define inline
 
99
#endif
 
100
 
 
101
#define MODULE      "StatPro"   // Statistics processor debug tag
 
102
#define MODULE_INIT "StatProInit"       // Statistics processor debug tag
 
103
 
 
104
/***************************************************************
 
105
 *                       StatExprToken
 
106
 * a statistics expression token can either be a binary operator,
 
107
 * name '+', '-', '*', '/', or parenthesis '(', ')' or a TS variable.
 
108
 * In the former case, the arithSymbol stores the operator or
 
109
 * paranthesis; otherwise arithSymbol is '/0';
 
110
 ***************************************************************/
 
111
class StatExprToken
 
112
{
 
113
 
 
114
public:
 
115
 
 
116
  char m_arith_symbol;
 
117
  char *m_token_name;
 
118
  StatDataT m_token_type;
 
119
  StatFloat m_token_value;
 
120
  StatFloat m_token_value_max;
 
121
  StatFloat m_token_value_min;
 
122
  StatFloatSamples *m_token_value_delta;
 
123
  bool m_sum_var;
 
124
  bool m_node_var;
 
125
 
 
126
  // Member Functions
 
127
  void assignTokenName(const char *);
 
128
  bool assignTokenType();
 
129
  void print(const char *);
 
130
  short precedence();
 
131
  void copy(const StatExprToken &);
 
132
 
 
133
  LINK(StatExprToken, link);
 
134
  StatExprToken();
 
135
  inline ~ StatExprToken()
 
136
  {
 
137
    clean();
 
138
  };
 
139
  void clean();
 
140
 
 
141
  bool statVarSet(StatFloat);
 
142
};
 
143
 
 
144
 
 
145
/**
 
146
 * StatExprList
 
147
 *   simply a list of StatExprToken.
 
148
 **/
 
149
class StatExprList
 
150
{
 
151
 
 
152
public:
 
153
 
 
154
  StatExprList();
 
155
  inline ~ StatExprList()
 
156
  {
 
157
    clean();
 
158
  };
 
159
  void clean();
 
160
 
 
161
  void enqueue(StatExprToken *);
 
162
  void push(StatExprToken *);
 
163
  StatExprToken *dequeue();
 
164
  StatExprToken *pop();
 
165
  StatExprToken *top();
 
166
  StatExprToken *first();
 
167
  StatExprToken *next(StatExprToken *);
 
168
  unsigned count();
 
169
  void print(const char *);
 
170
 
 
171
private:
 
172
 
 
173
  size_t m_size;
 
174
  Queue<StatExprToken> m_tokenList;
 
175
};
 
176
 
 
177
/***************************************************************
 
178
 *                        StatObject
 
179
 * Each entry in the statistics XML file is represented by a
 
180
 * StatObject.
 
181
 ***************************************************************/
 
182
class StatObject
 
183
{
 
184
 
 
185
public:
 
186
 
 
187
  unsigned m_id;
 
188
  bool m_debug;
 
189
  char *m_expr_string;          /* for debugging using only */
 
190
  StatExprToken *m_node_dest;
 
191
  StatExprToken *m_cluster_dest;
 
192
  StatExprList *m_expression;
 
193
  StatExprList *m_postfix;
 
194
  ink_hrtime m_last_update;
 
195
  ink_hrtime m_current_time;
 
196
  ink_hrtime m_update_interval;
 
197
  StatFloat m_stats_max;
 
198
  StatFloat m_stats_min;
 
199
  bool m_has_delta;
 
200
  LINK(StatObject, link);
 
201
 
 
202
  // Member functions
 
203
  StatObject();
 
204
  StatObject(unsigned);
 
205
  inline ~ StatObject()
 
206
  {
 
207
    clean();
 
208
  };
 
209
  void clean();
 
210
  void assignDst(const char *, bool, bool);
 
211
  void assignExpr(const char *);
 
212
 
 
213
  StatExprToken *StatBinaryEval(StatExprToken *, char, StatExprToken *, bool cluster = false);
 
214
  StatFloat NodeStatEval(bool cluster);
 
215
  StatFloat ClusterStatEval();
 
216
  void setTokenValue(StatExprToken *, bool cluster = false);
 
217
 
 
218
private:
 
219
 
 
220
  void infix2postfix();
 
221
};
 
222
 
 
223
 
 
224
/**
 
225
 * StatObjectList
 
226
 *    simply a list of StatObject.
 
227
 **/
 
228
class StatObjectList
 
229
{
 
230
 
 
231
public:
 
232
 
 
233
  // Member functions
 
234
  StatObjectList();
 
235
  inline ~ StatObjectList()
 
236
  {
 
237
    clean();
 
238
  };
 
239
  void clean();
 
240
  void enqueue(StatObject * object);
 
241
  StatObject *first();
 
242
  StatObject *next(StatObject * current);
 
243
  void print(const char *prefix = "");
 
244
  short Eval();                 // return the number of statistics object processed
 
245
 
 
246
  size_t m_size;
 
247
 
 
248
private:
 
249
 
 
250
  Queue<StatObject> m_statList;
 
251
};
 
252
 
 
253
#endif