Permalink
Browse files

Move microseconds() helper function to utils.c

  • Loading branch information...
1 parent 6f421cb commit 05f18e5dcd2d8a5c04a016a1ac7f0ff1e262ddcc @pietern pietern committed Nov 22, 2010
Showing with 16 additions and 12 deletions.
  1. +0 −10 redis-stat.c
  2. +14 −2 utils.c
  3. +2 −0 utils.h
View
@@ -41,16 +41,6 @@ static struct config {
int logscale;
} config;
-static long long microseconds(void) {
- struct timeval tv;
- long long mst;
-
- gettimeofday(&tv, NULL);
- mst = ((long long)tv.tv_sec)*1000000;
- mst += tv.tv_usec;
- return mst;
-}
-
/* Return the specified INFO field from the INFO command output "info".
* A new buffer is allocated for the result, that needs to be free'd.
* If the field is not found NULL is returned. */
View
16 utils.c
@@ -1,7 +1,18 @@
#include <stdio.h>
+#include <sys/time.h>
-/* Convert an amount of bytes into a human readable string in the form
- * of 100B, 2G, 100M, 4K, and so forth. */
+/* Returns the number of microseconds since Unix epoch. */
+long long microseconds(void) {
+ struct timeval tv;
+ long long mst;
+ gettimeofday(&tv, NULL);
+ mst = ((long long)tv.tv_sec)*1000000;
+ mst += tv.tv_usec;
+ return mst;
+}
+
+/* Convert number of bytes into a human readable string of the form:
+ * 100B, 2G, 100M, 4K, and so forth. */
void bytesToHuman(char *s, long long n) {
double d;
@@ -25,3 +36,4 @@ void bytesToHuman(char *s, long long n) {
sprintf(s,"%.2fG",d);
}
}
+
View
@@ -1,6 +1,8 @@
#ifndef __REDISTOOLS_UTILS_H
#define __REDISTOOLS_UTILS_H
+long long microseconds();
void bytesToHuman(char *s, unsigned long long n);
#endif
+

0 comments on commit 05f18e5

Please sign in to comment.