1 /**************************************************************************
2  *
3  * Copyright 2013 Marek Olšák <maraeo@gmail.com>
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27 
28 #ifndef HUD_PRIVATE_H
29 #define HUD_PRIVATE_H
30 
31 #include "pipe/p_context.h"
32 #include "util/list.h"
33 
34 struct hud_graph {
35    /* initialized by common code */
36    struct list_head head;
37    struct hud_pane *pane;
38    float color[3];
39    float *vertices; /* ring buffer of vertices */
40 
41    /* name and query */
42    char name[128];
43    void *query_data;
44    void (*begin_query)(struct hud_graph *gr);
45    void (*query_new_value)(struct hud_graph *gr);
46    void (*free_query_data)(void *ptr); /**< do not use ordinary free() */
47 
48    /* mutable variables */
49    unsigned num_vertices;
50    unsigned index; /* vertex index being updated */
51    uint64_t current_value;
52    FILE *fd;
53 };
54 
55 struct hud_pane {
56    struct list_head head;
57    unsigned x1, y1, x2, y2;
58    unsigned inner_x1;
59    unsigned inner_y1;
60    unsigned inner_x2;
61    unsigned inner_y2;
62    unsigned inner_width;
63    unsigned inner_height;
64    float yscale;
65    unsigned max_num_vertices;
66    unsigned last_line; /* index of the last describing line in the graph */
67    uint64_t max_value;
68    uint64_t initial_max_value;
69    uint64_t ceiling;
70    unsigned dyn_ceil_last_ran;
71    boolean dyn_ceiling;
72    boolean sort_items;
73    enum pipe_driver_query_type type;
74    uint64_t period; /* in microseconds */
75 
76    struct list_head graph_list;
77    unsigned num_graphs;
78    unsigned next_color;
79 };
80 
81 
82 /* core */
83 void hud_pane_add_graph(struct hud_pane *pane, struct hud_graph *gr);
84 void hud_pane_set_max_value(struct hud_pane *pane, uint64_t value);
85 void hud_graph_add_value(struct hud_graph *gr, uint64_t value);
86 
87 /* graphs/queries */
88 struct hud_batch_query_context;
89 
90 #define ALL_CPUS ~0 /* optionally set as cpu_index */
91 
92 int hud_get_num_cpus(void);
93 
94 void hud_fps_graph_install(struct hud_pane *pane);
95 void hud_cpu_graph_install(struct hud_pane *pane, unsigned cpu_index);
96 void hud_pipe_query_install(struct hud_batch_query_context **pbq,
97                             struct hud_pane *pane, struct pipe_context *pipe,
98                             const char *name, unsigned query_type,
99                             unsigned result_index,
100                             uint64_t max_value,
101                             enum pipe_driver_query_type type,
102                             enum pipe_driver_query_result_type result_type,
103                             unsigned flags);
104 boolean hud_driver_query_install(struct hud_batch_query_context **pbq,
105                                  struct hud_pane *pane,
106                                  struct pipe_context *pipe, const char *name);
107 void hud_batch_query_begin(struct hud_batch_query_context *bq);
108 void hud_batch_query_update(struct hud_batch_query_context *bq);
109 void hud_batch_query_cleanup(struct hud_batch_query_context **pbq);
110 
111 void hud_graph_set_dump_file(struct hud_graph *gr);
112 
113 #if HAVE_GALLIUM_EXTRA_HUD
114 int hud_get_num_nics(bool displayhelp);
115 #define NIC_DIRECTION_RX 1
116 #define NIC_DIRECTION_TX 2
117 #define NIC_RSSI_DBM     3
118 void hud_nic_graph_install(struct hud_pane *pane, const char *nic_index,
119                            unsigned int mode);
120 
121 int hud_get_num_disks(bool displayhelp);
122 #define DISKSTAT_RD 1
123 #define DISKSTAT_WR 2
124 void hud_diskstat_graph_install(struct hud_pane *pane, const char *dev_name,
125                                 unsigned int mode);
126 
127 int hud_get_num_cpufreq(bool displayhelp);
128 #define CPUFREQ_MINIMUM     1
129 #define CPUFREQ_CURRENT     2
130 #define CPUFREQ_MAXIMUM     3
131 void hud_cpufreq_graph_install(struct hud_pane *pane, int cpu_index, unsigned int mode);
132 #endif
133 
134 #if HAVE_LIBSENSORS
135 int hud_get_num_sensors(bool displayhelp);
136 #define SENSORS_TEMP_CURRENT     1
137 #define SENSORS_TEMP_CRITICAL    2
138 #define SENSORS_VOLTAGE_CURRENT  3
139 #define SENSORS_CURRENT_CURRENT  4
140 #define SENSORS_POWER_CURRENT    5
141 void hud_sensors_temp_graph_install(struct hud_pane *pane, const char *dev_name,
142                                     unsigned int mode);
143 #endif
144 
145 #endif
146