Convert number of bytes into a human readable string of the form: * 100B, 2G, 100M, 4K, and so forth. */
| 7954 | /* Convert number of bytes into a human readable string of the form: |
| 7955 | * 100B, 2G, 100M, 4K, and so forth. */ |
| 7956 | void bytesToHuman(char *s, long long n) { |
| 7957 | double d; |
| 7958 | |
| 7959 | if (n < 0) { |
| 7960 | *s = '-'; |
| 7961 | s++; |
| 7962 | n = -n; |
| 7963 | } |
| 7964 | if (n < 1024) { |
| 7965 | /* Bytes */ |
| 7966 | sprintf(s,"%lldB",n); |
| 7967 | return; |
| 7968 | } else if (n < (1024*1024)) { |
| 7969 | d = (double)n/(1024); |
| 7970 | sprintf(s,"%.2fK",d); |
| 7971 | } else if (n < (1024LL*1024*1024)) { |
| 7972 | d = (double)n/(1024*1024); |
| 7973 | sprintf(s,"%.2fM",d); |
| 7974 | } else if (n < (1024LL*1024*1024*1024)) { |
| 7975 | d = (double)n/(1024LL*1024*1024); |
| 7976 | sprintf(s,"%.2fG",d); |
| 7977 | } |
| 7978 | } |
| 7979 | |
| 7980 | static void statMode(void) { |
| 7981 | redisReply *reply; |