Convert number of bytes into a human readable string of the form: * 100B, 2G, 100M, 4K, and so forth. */
| 6840 | /* Convert number of bytes into a human readable string of the form: |
| 6841 | * 100B, 2G, 100M, 4K, and so forth. */ |
| 6842 | void bytesToHuman(char *s, long long n, size_t bufsize) { |
| 6843 | double d; |
| 6844 | |
| 6845 | if (n < 0) { |
| 6846 | *s = '-'; |
| 6847 | s++; |
| 6848 | n = -n; |
| 6849 | } |
| 6850 | if (n < 1024) { |
| 6851 | /* Bytes */ |
| 6852 | snprintf(s,bufsize,"%lldB",n); |
| 6853 | return; |
| 6854 | } else if (n < (1024*1024)) { |
| 6855 | d = (double)n/(1024); |
| 6856 | snprintf(s,bufsize,"%.2fK",d); |
| 6857 | } else if (n < (1024LL*1024*1024)) { |
| 6858 | d = (double)n/(1024*1024); |
| 6859 | snprintf(s,bufsize,"%.2fM",d); |
| 6860 | } else if (n < (1024LL*1024*1024*1024)) { |
| 6861 | d = (double)n/(1024LL*1024*1024); |
| 6862 | snprintf(s,bufsize,"%.2fG",d); |
| 6863 | } |
| 6864 | } |
| 6865 | |
| 6866 | static void statMode(void) { |
| 6867 | redisReply *reply; |