forked from clbr/radeontop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump.c
140 lines (106 loc) · 3.44 KB
/
dump.c
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
/*
Copyright (C) 2012 Lauri Kasanen
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "radeontop.h"
static unsigned char quit = 0;
static void sighandler(int sig) {
switch (sig) {
case SIGTERM:
case SIGINT:
quit = 1;
break;
}
}
void dumpdata(const unsigned int ticks, const char file[], const unsigned int limit) {
#ifdef ENABLE_NLS
// This is a data format, so disable decimal point localization
setlocale(LC_NUMERIC, "C");
#endif
// Set up signals to exit gracefully when terminated
struct sigaction sig;
sig.sa_handler = sighandler;
sigaction(SIGTERM, &sig, NULL);
sigaction(SIGINT, &sig, NULL);
printf(_("Dumping to %s, "), file);
if (limit)
printf(_("line limit %u.\n"), limit);
else
puts(_("until termination."));
// Check the file can be output to
FILE *f = NULL;
if (file[0] == '-')
f = stdout;
else
f = fopen(file, "a");
if (!f)
die(_("Can't open file for writing."));
// This does not need to be atomic. A delay here is acceptable.
while(!results)
usleep(16000);
// Action
unsigned int count;
for (count = limit; !limit || count; count--) {
struct timeval t;
gettimeofday(&t, NULL);
fprintf(f, "%llu.%llu: ", (unsigned long long) t.tv_sec,
(unsigned long long) t.tv_usec);
// Again, no need to protect these. Worst that happens is a slightly
// wrong number.
float ee = 100.0 * (float) results->ee / ticks;
float vgt = 100.0 * (float) results->vgt / ticks;
float gui = 100.0 * (float) results->gui / ticks;
float ta = 100.0 * (float) results->ta / ticks;
float tc = 100.0 * (float) results->tc / ticks;
float sx = 100.0 * (float) results->sx / ticks;
float sh = 100.0 * (float) results->sh / ticks;
float spi = 100.0 * (float) results->spi / ticks;
float smx = 100.0 * (float) results->smx / ticks;
float sc = 100.0 * (float) results->sc / ticks;
float pa = 100.0 * (float) results->pa / ticks;
float db = 100.0 * (float) results->db / ticks;
float cr = 100.0 * (float) results->cr / ticks;
float cb = 100.0 * (float) results->cb / ticks;
float vram = 100.0 * (float) results->vram / vramsize;
float vrammb = results->vram / 1024.0f / 1024.0f;
fprintf(f, "gpu %.2f%%, ", gui);
fprintf(f, "ee %.2f%%, ", ee);
fprintf(f, "vgt %.2f%%, ", vgt);
fprintf(f, "ta %.2f%%, ", ta);
if (bits.tc)
fprintf(f, "tc %.2f%%, ", tc);
fprintf(f, "sx %.2f%%, ", sx);
fprintf(f, "sh %.2f%%, ", sh);
fprintf(f, "spi %.2f%%, ", spi);
if (bits.smx)
fprintf(f, "smx %.2f%%, ", smx);
if (bits.cr)
fprintf(f, "cr %.2f%%, ", cr);
fprintf(f, "sc %.2f%%, ", sc);
fprintf(f, "pa %.2f%%, ", pa);
fprintf(f, "db %.2f%%, ", db);
fprintf(f, "cb %.2f%%", cb);
if (bits.vram)
fprintf(f, ", vram %.2f%% %.2fmb\n", vram, vrammb);
else
fprintf(f, "\n");
fflush(f);
// Did we get a termination signal?
if (quit)
break;
sleep(1);
}
fflush(f);
if (f != stdout) {
fsync(fileno(f));
fclose(f);
}
}