1 /*
2  * bmon/history.h		History Management
3  *
4  * Copyright (c) 2001-2013 Thomas Graf <tgraf@suug.ch>
5  * Copyright (c) 2013 Red Hat, Inc.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23  * DEALINGS IN THE SOFTWARE.
24  */
25 
26 #ifndef __BMON_HISTORY_H_
27 #define __BMON_HISTORY_H_
28 
29 #include <bmon/bmon.h>
30 #include <bmon/attr.h>
31 
32 #define HISTORY_UNKNOWN		((uint64_t) -1)
33 #define HBEAT_TRIGGER		60.0f
34 
35 enum {
36 	HISTORY_TYPE_8	= 1,
37 	HISTORY_TYPE_16	= 2,
38 	HISTORY_TYPE_32	= 4,
39 	HISTORY_TYPE_64	= 8,
40 };
41 
42 struct history_def
43 {
44 	char *			hd_name;
45 	int			hd_size,
46 				hd_type;
47 	float			hd_interval;
48 
49 	struct list_head	hd_list;
50 };
51 
52 struct history_store
53 {
54 	/* TODO? store error ratio? */
55 	void *			hs_data;
56 	uint64_t		hs_prev_total;
57 };
58 
59 struct history
60 {
61 	/* index to current entry in data array */
62 	int			h_index;
63 	struct history_def *	h_definition;
64 	/* time of last history update */
65 	timestamp_t		h_last_update;
66 	struct list_head	h_list;
67 
68 	float			h_min_interval,
69 				h_max_interval;
70 
71 	struct history_store	h_rx,
72 				h_tx;
73 
74 };
75 
76 extern struct history_def *	history_def_lookup(const char *);
77 extern struct history_def *	history_def_alloc(const char *);
78 
79 extern uint64_t			history_data(struct history *,
80 					     struct history_store *, int);
81 extern void			history_update(struct attr *,
82 					       struct history *, timestamp_t *);
83 extern struct history *		history_alloc(struct history_def *);
84 extern void			history_free(struct history *);
85 extern void			history_attach(struct attr *);
86 
87 extern struct history_def *	history_select_first(void);
88 extern struct history_def *	history_select_last(void);
89 extern struct history_def *	history_select_next(void);
90 extern struct history_def *	history_select_prev(void);
91 extern struct history_def *	history_current(void);
92 
93 #endif
94