00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <iomanip>
00014 #include <sstream>
00015
00016 #include "Rtypes.h"
00017
00018 #include "TMemStatHelpers.h"
00019
00020 using namespace std;
00021
00022
00023 string Memstat::dig2bytes(Long64_t bytes)
00024 {
00025
00026
00027
00028
00029 ostringstream ss;
00030 ss << fixed;
00031
00032 if (bytes < 0) {
00033 ss << '-';
00034 bytes = -bytes;
00035 }
00036
00037 static const long kB = 1024L;
00038 static const long lMB = kB * kB;
00039 static const long lGB = lMB * kB;
00040
00041 if (bytes < kB)
00042 ss << bytes << " B";
00043 else if (bytes < (10L * kB))
00044 ss << setprecision(2) << ((double)bytes / (float)kB) << " kB";
00045 else if (bytes < (100L * kB))
00046 ss << setprecision(1) << ((double)bytes / (float)kB) << " kB";
00047 else if (bytes < lMB)
00048 ss << setprecision(0) << ((double)bytes / (float)kB) << " kB";
00049 else if (bytes < (10L * lMB))
00050 ss << setprecision(2) << ((double)bytes / (float)lMB) << " MB";
00051 else if (bytes < (100L * lMB))
00052 ss << setprecision(1) << ((double)bytes / (float)lMB) << " MB";
00053 else if (bytes < lGB)
00054 ss << setprecision(0) << ((double)bytes / (float)lMB) << " MB";
00055 else
00056 ss << setprecision(2) << ((double)bytes / (float)lGB) << " GB";
00057
00058 return ss.str();
00059 }