Also avoids %lld which isn't supported on Windows.
double ratio;
+ char a[1024], b[1024];
+
rects = 0;
pixels = bytes = equivalent = 0;
ratio = (double)stats[i][j].equivalent / stats[i][j].bytes;
- vlog.info(" %s: %u rects, %llu pixels",
- encoderTypeName((EncoderType)j),
- stats[i][j].rects, stats[i][j].pixels);
- vlog.info(" %*s %llu bytes (%g ratio)",
- strlen(encoderTypeName((EncoderType)j)), "",
- stats[i][j].bytes, ratio);
+ siPrefix(stats[i][j].rects, "rects", a, sizeof(a));
+ siPrefix(stats[i][j].pixels, "pixels", b, sizeof(b));
+ vlog.info(" %s: %s, %s", encoderTypeName((EncoderType)j), a, b);
+ iecPrefix(stats[i][j].bytes, "B", a, sizeof(a));
+ vlog.info(" %*s %s (1:%g ratio)",
+ (int)strlen(encoderTypeName((EncoderType)j)), "",
+ a, ratio);
}
}
ratio = (double)equivalent / bytes;
- vlog.info(" Total: %u rects, %llu pixels", rects, pixels);
- vlog.info(" %llu bytes (%g ratio)", bytes, ratio);
+ siPrefix(rects, "rects", a, sizeof(a));
+ siPrefix(pixels, "pixels", b, sizeof(b));
+ vlog.info(" Total: %s, %s", a, b);
+ iecPrefix(bytes, "B", a, sizeof(a));
+ vlog.info(" %s (1:%g ratio)", a, ratio);
}
bool EncodeManager::supported(int encoding)
#include <config.h>
#endif
+#include <stdio.h>
#include <sys/time.h>
#include <rfb/util.h>
return diff;
}
+
+ static size_t doPrefix(long long value, const char *unit,
+ char *buffer, size_t maxlen,
+ unsigned divisor, const char **prefixes,
+ size_t prefixCount) {
+ double newValue;
+ size_t prefix, len;
+
+ newValue = value;
+ prefix = 0;
+ while (newValue >= divisor) {
+ if (prefix >= prefixCount)
+ break;
+ newValue /= divisor;
+ prefix++;
+ }
+
+ len = snprintf(buffer, maxlen, "%g %s%s", newValue,
+ (prefix == 0) ? "" : prefixes[prefix-1], unit);
+ buffer[maxlen-1] = '\0';
+
+ return len;
+ }
+
+ static const char *siPrefixes[] =
+ { "k", "M", "G", "T", "P", "E", "Z", "Y" };
+ static const char *iecPrefixes[] =
+ { "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi" };
+
+ size_t siPrefix(long long value, const char *unit,
+ char *buffer, size_t maxlen) {
+ return doPrefix(value, unit, buffer, maxlen, 1000, siPrefixes,
+ sizeof(siPrefixes)/sizeof(*siPrefixes));
+ }
+
+ size_t iecPrefix(long long value, const char *unit,
+ char *buffer, size_t maxlen) {
+ return doPrefix(value, unit, buffer, maxlen, 1024, iecPrefixes,
+ sizeof(iecPrefixes)/sizeof(*iecPrefixes));
+ }
};
// Returns time elapsed since given moment in milliseconds.
unsigned msSince(const struct timeval *then);
+
+ size_t siPrefix(long long value, const char *unit,
+ char *buffer, size_t maxlen);
+ size_t iecPrefix(long long value, const char *unit,
+ char *buffer, size_t maxlen);
}
// Some platforms (e.g. Windows) include max() and min() macros in their