summaryrefslogtreecommitdiffstats
path: root/extras/vom/vom/stat_client.hpp
blob: f1745c87b20676fb230109288945781473afdfc4 (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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
 * Copyright (c) 2018 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef __VOM_STAT_CLIENT_H__
#define __VOM_STAT_CLIENT_H__

#include <iostream>
#include <string>
#include <vector>

extern "C" {
#include <vpp-api/client/stat_client.h>
}

namespace VOM {

/**
 * A representation of a stat client in VPP
 */
class stat_client
{
public:
  /**
   * stat data representation
   */
  struct stat_data_t
  {
    /**
     * stat data custom constructor
     */
    stat_data_t(const stat_segment_data_t& stat_seg_data);

    /**
     * get name of stat
     */
    const std::string& name() const;

    /**
     * get type of stat
     */
    const stat_directory_type_t& type() const;

    /**
     * Get pointer to actual data
     */
    double get_stat_segment_scalar_data() const;
    uint64_t* get_stat_segment_error_data() const;
    uint64_t** get_stat_segment_simple_counter_data() const;
    vlib_counter_t** get_stat_segment_combined_counter_data() const;

  private:
    /**
     * name of stat data
     */
    const std::string m_name;

    /**
     * type of stat data
     */
    const stat_directory_type_t m_type;

    /**
     * union of pointers to actual stat data
     */
    union
    {
      double m_scalar_value;
      counter_t* m_error_vec;
      counter_t** m_simple_counter_vec;
      vlib_counter_t** m_combined_counter_vec;
    };
  };

  /**
   * vector of stat_data_t
   */
  typedef std::vector<stat_data_t> stat_data_vec_t;

  /**
   * Stat Client constructor with custom socket name
   */
  stat_client(std::string& socket_name);

  /**
   * Stat Client constructor with custom vector of patterns
   */
  stat_client(std::vector<std::string>& pattern);

  /**
   * Stat Client constructor with custom socket name and vector of patterns
   */
  stat_client(std::string socket_name, std::vector<std::string> patterns);

  /**
   * Stat Client constructor
   */
  stat_client();

  /**
   * Stat Client destructor
   */
  ~stat_client();

  /**
   * Stat Client copy constructor
   */
  stat_client(const stat_client& o);

  /**
   * Connect to stat segment
   */
  int connect();

  /**
   * Disconnect to stat segment
   */
  void disconnect();

  /**
   * dump all the stats for given pattern
   */
  const stat_data_vec_t& dump();

  /**
   * dump stats for given index in stat directory
   */
  const stat_data_vec_t& dump_entry(uint32_t index);

  /**
   * Get vector length of VPP style vector
   */
  int vec_len(void* vec);

  double heartbeat();

  /**
   * get index to name of stat
   */
  std::string index_to_name(uint32_t index);

private:
  /**
   * Free VPP style vector
   */
  void vec_free(void* vec);

  /**
   * Free stat segment data
   */
  void data_free();

  /**
   * ls on the stat directory using given pattern
   */
  void ls();

  /**
   * socket name
   */
  std::string m_socket_name;

  /**
   * vector of patterns for stats
   */
  std::vector<std::string> m_patterns;

  /**
   * connection bit
   */
  bool m_stat_connect;

  /**
   * Pointer to VPP style vector of stat indexes
   */
  uint32_t* m_counter_vec;

  /**
   * Pointer to stat segment
   */
  stat_segment_data_t* m_stat_seg_data;

  /**
   * Vector of stat data
   */
  stat_data_vec_t m_stat_data;
};
}; // namespace VOM

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "mozilla")
 * End:
 */

#endif