+
+static void
+get_stats(const char *file, statinfo *info, int *opt, int other_opt, const char *label)
+{
+ if (!parse_statfile(file, info)) {
+ if (!other_opt) {
+ fprintf(stderr, "Warning: No %s Stats (%s: %m). \n", label, file);
+ exit(2);
+ }
+ *opt = 0;
+ }
+}
+
+static int
+has_stats(const unsigned int *info)
+{
+ return (info[0] && info[info[0] + 1] != info[0]);
+}
+
+/* clone 'src' to 'dest' */
+static void
+copy_stats(struct statinfo *dest, struct statinfo *src)
+{
+ int i, j;
+
+ for (i = 0; src[i].tag; i++) {
+ dest[i].tag = src[i].tag;
+ dest[i].nrvals = src[i].nrvals;
+ for (j = 0; j < dest[i].nrvals; j++)
+ dest[i].valptr[j] = src[i].valptr[j];
+ }
+}
+
+/*
+ * take the difference of each individual stat value in 'new' and 'old'
+ * and store the results back into 'new'
+ */
+static void
+diff_stats(struct statinfo *new, struct statinfo *old)
+{
+ int i, j, is_srv, should_diff;
+
+ is_srv = (new == srvinfo);
+ for (i = 0; old[i].tag; i++) {
+ for (j = 0; j < new[i].nrvals; j++) {
+ /* skip items in valptr that shouldn't be changed */
+ should_diff = (i < (3 + is_srv) || j > 0);
+ if (should_diff)
+ new[i].valptr[j] -= old[i].valptr[j];
+ }
+ }
+}
+
+static void
+unpause(int sig)
+{
+ double time_diff;
+ int minutes, seconds;
+ time_t endtime;
+
+ endtime = time(NULL);
+ time_diff = difftime(endtime, starttime);
+ minutes = time_diff / 60;
+ seconds = (int)time_diff % 60;
+ printf("Signal received; displaying (only) statistics gathered over the last %d minutes, %d seconds:\n\n", minutes, seconds);
+}