2 * Copyright (c) 2017 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 start_gnuplot(int ac __unused
, char **av __unused
, const char *plotfile
)
37 OutFP
= popen("gnuplot", "w");
39 fprintf(stderr
, "can't find gnuplot\n");
44 * If plotfile is specified allow .jpg or .JPG or .png or .PNG
49 if ((ext
= strrchr(plotfile
, '.')) == NULL
) {
54 if (strcmp(ext
, "jpg") == 0 ||
55 strcmp(ext
, "JPG") == 0) {
56 fprintf(OutFP
, "set terminal jpeg size %d,%d\n",
57 OutputWidth
, OutputHeight
);
58 } else if (strcmp(ext
, "png") == 0 ||
59 strcmp(ext
, "PNG") == 0) {
60 fprintf(OutFP
, "set terminal png size %d,%d\n",
61 OutputWidth
, OutputHeight
);
63 fprintf(stderr
, "plotfile must be .jpg or .png\n");
66 fprintf(OutFP
, "set output \"%s\"\n", plotfile
);
68 fprintf(OutFP
, "set terminal x11 persist size %d,%d\n",
69 OutputWidth
, OutputHeight
);
74 dump_gnuplot(kcollect_t
*ary
, size_t count
)
76 int plot1
[] = { KCOLLECT_MEMFRE
, KCOLLECT_MEMCAC
,
77 KCOLLECT_MEMINA
, KCOLLECT_MEMACT
,
78 KCOLLECT_MEMWIR
, KCOLLECT_LOAD
};
79 int plot2
[] = { KCOLLECT_IDLEPCT
, KCOLLECT_INTRPCT
,
80 KCOLLECT_SYSTPCT
, KCOLLECT_USERPCT
,
82 KCOLLECT_VMFAULT
, -1/*KCOLLECT_SYSCALLS*/,
89 "idle", "intr", "system", "user",
91 "faults", "syscalls", "nlookups" };
104 * NOTE: be sure to reset any fields adjusted by the second plot,
105 * in case we are streaming plots with -f.
107 fprintf(OutFP
, "set xdata time\n");
108 fprintf(OutFP
, "set timefmt \"%%d-%%b-%%Y %%H:%%M:%%S\"\n");
109 fprintf(OutFP
, "set style fill solid 1.0\n");
110 fprintf(OutFP
, "set multiplot layout 2,1\n");
111 fprintf(OutFP
, "set key outside\n");
112 fprintf(OutFP
, "set lmargin 10\n");
113 fprintf(OutFP
, "set rmargin 25\n");
114 fprintf(OutFP
, "set xtics rotate\n");
115 fprintf(OutFP
, "set format x '%%H:%%M'\n");
117 fprintf(OutFP
, "set ylabel \"GB\"\n");
119 fprintf(OutFP
, "set yrange [0:%d]\n",
120 (int)((KCOLLECT_GETSCALE(ary
[0].data
[KCOLLECT_MEMFRE
]) +
121 999999) / 1000000000));
122 fprintf(OutFP
, "set autoscale y2\n");
123 fprintf(OutFP
, "set y2label \"Load\"\n");
124 fprintf(OutFP
, "set ytics nomirror\n");
125 fprintf(OutFP
, "set y2tics nomirror\n");
129 "\"-\" using 1:3 title \"%s\" with boxes lw 1, "
130 "\"-\" using 1:3 title \"%s\" with boxes lw 1, "
131 "\"-\" using 1:3 title \"%s\" with boxes lw 1, "
132 "\"-\" using 1:3 title \"%s\" with boxes lw 1, "
133 "\"-\" using 1:3 title \"%s\" with boxes lw 1, "
134 "\"-\" using 1:3 axes x1y2 title \"%s\" with lines lw 1\n",
135 id1
[0], id1
[1], id1
[2], id1
[3], id1
[4], id1
[5]);
137 for (jj
= 0; jj
< (int)(sizeof(plot1
) / sizeof(plot1
[0])); ++jj
) {
141 for (i
= count
- 1; i
>= 2; --i
) {
145 t
= ary
[i
].realtime
.tv_sec
;
152 strftime(buf
, sizeof(buf
), "%d-%b-%Y %H:%M:%S", tmv
);
153 value
= ary
[i
].data
[j
];
155 for (k
= jj
+ 1; k
<= 4; ++k
)
156 value
+= ary
[i
].data
[plot1
[k
]];
157 dv
= (double)value
/ 1e9
;
159 dv
= (double)value
/ 100.0;
162 if (i
== (int)(count
- 1)) {
164 } else if (smoothed_dv
< dv
) {
166 (smoothed_dv
* 5.0 + 5 * dv
) /
170 (smoothed_dv
* 9.0 + 1 * dv
) /
175 fprintf(OutFP
, "%s %6.2f\n", buf
, dv
);
177 fprintf(OutFP
, "e\n");
181 size_t ncpu_size
= sizeof(ncpu
);
182 sysctlbyname("hw.ncpu", &ncpu
, &ncpu_size
, NULL
, 0);
184 fprintf(OutFP
, "set ylabel \"Cpu Utilization\"\n");
185 fprintf(OutFP
, "set y2label \"MOps/sec (smoothed)\"\n");
186 fprintf(OutFP
, "set ytics nomirror\n");
187 fprintf(OutFP
, "set y2tics nomirror\n");
188 fprintf(OutFP
, "set yrange [0:105]\n");
189 fprintf(OutFP
, "set y2range [0:%d.0]\n",
190 (93750 * ncpu
+ 999999) / 1000000);
194 "\"-\" using 1:3 title \"%s\" with boxes lw 1, "
195 "\"-\" using 1:3 title \"%s\" with boxes lw 1, "
196 "\"-\" using 1:3 title \"%s\" with boxes lw 1, "
197 "\"-\" using 1:3 title \"%s\" with boxes lw 1, "
198 "\"-\" using 1:3 title \"%s\" with lines lw 1, "
199 "\"-\" using 1:3 axes x1y2 title \"%s\" with lines lw 1, "
200 "\"-\" using 1:3 axes x1y2 title \"%s\" with lines lw 1, "
201 "\"-\" using 1:3 axes x1y2 title \"%s\" with lines lw 1\n",
202 id2
[0], id2
[1], id2
[2], id2
[3], id2
[4], id2
[5], id2
[6], id2
[7]);
204 for (jj
= 0; jj
< (int)(sizeof(plot2
) / sizeof(plot2
[0])); ++jj
) {
211 fprintf(OutFP
, "e\n");
219 for (i
= count
- 1; i
>= 2; --i
) {
223 t
= ary
[i
].realtime
.tv_sec
;
230 strftime(buf
, sizeof(buf
), "%d-%b-%Y %H:%M:%S", tmv
);
231 value
= ary
[i
].data
[j
];
235 * intr/sys/user/idle percentages
237 for (k
= jj
+ 1; k
<= 3; ++k
)
238 value
+= ary
[i
].data
[plot2
[k
]];
239 dv
= (double)value
/ 100.0;
241 if (i
== (int)(count
- 1)) {
243 } else if (smoothed_dv
< dv
) {
245 (smoothed_dv
* 5.0 + 5 * dv
) /
249 (smoothed_dv
* 9.0 + 1 * dv
) /
257 dv
= (double)value
/ KCOLLECT_INTERVAL
;
260 /* swap percentage (line graph) */
261 dv
= (double)value
/ 100.0;
263 if (i
== (int)(count
- 1)) {
265 } else if (smoothed_dv
< dv
) {
267 (smoothed_dv
* 5.0 + 5 * dv
) /
270 smoothed_dv
= (smoothed_dv
* 9.0 + dv
) /
275 fprintf(OutFP
, "%s %6.2f\n", buf
, dv
);
277 fprintf(OutFP
, "e\n");