Changeset de8ef76 in nscp for include


Ignore:
Timestamp:
02/04/08 22:42:46 (5 years ago)
Author:
Michael Medin <michael@…>
Branches:
master, 0.4.0, 0.4.1, 0.4.2, stable
Children:
047516e
Parents:
f6edbcd
Message:

2008-02-04 MickeM

* Happy Birthday bogi!! :)

  • Fixed issues with performance counter rendering (mainly checkDisk)
Location:
include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • include/checkHelpers.hpp

    r99e4d8f rde8ef76  
    134134      return strEx::itos_as_BKMG(value); 
    135135    } 
    136     static std::wstring print_perf(TType value) { 
    137       return strEx::itos_as_BKMG(value); 
     136    static std::wstring get_perf_unit(TType value) { 
     137      return strEx::find_proper_unit_BKMG(value); 
     138    } 
     139    static std::wstring print_perf(TType value, std::wstring unit) { 
     140      return strEx::format_BKMG(value, unit); 
    138141    } 
    139142    static TType parse(std::wstring s) { 
     
    187190      return strEx::itos(value); 
    188191    } 
    189     static std::wstring print_perf(TType value) { 
     192    static std::wstring get_perf_unit(TType value) { 
     193      return _T(""); 
     194    } 
     195    static std::wstring print_perf(TType value, std::wstring unit) { 
    190196      return strEx::itos(value); 
    191197    } 
     
    211217      return strEx::itos(value); 
    212218    } 
    213     static std::wstring print_perf(int value) { 
     219    static std::wstring get_perf_unit(int value) { 
     220      return _T(""); 
     221    } 
     222    static std::wstring print_perf(int value, std::wstring unit) { 
    214223      return strEx::itos(value); 
    215224    } 
     
    238247      return strEx::itos(value); 
    239248    } 
    240     static std::wstring print_perf(__int64 value) { 
     249    static std::wstring get_perf_unit(__int64 value) { 
     250      return _T(""); 
     251    } 
     252    static std::wstring print_perf(__int64 value, std::wstring unit) { 
    241253      return strEx::itos(value); 
    242254    } 
     
    262274      return strEx::stod(s); 
    263275    } 
    264     static std::wstring print_perf(double value) { 
     276    static std::wstring get_perf_unit(double value) { 
     277      return _T(""); 
     278    } 
     279    static std::wstring print_perf(double value, std::wstring unit) { 
    265280      return strEx::itos(value); 
    266281    } 
     
    360375    } 
    361376    static std::wstring gatherPerfData(std::wstring alias, TType &value, TType warn, TType crit) { 
    362       return MAKE_PERFDATA(alias, THandler::print_perf(value), _T(""), THandler::print_perf(warn), THandler::print_perf(crit)); 
     377      std::wstring unit = THandler::get_perf_unit(min(warn, min(crit, value))); 
     378      return MAKE_PERFDATA(alias, THandler::print_perf(value, unit), unit, THandler::print_perf(warn, unit), THandler::print_perf(crit, unit)); 
    363379    } 
    364380 
     
    495511            THandler::print_unformated(warn), THandler::print_unformated(crit)); 
    496512      } else { 
     513        std::wstring unit = THandler::get_perf_unit(min(warn, min(crit, value.value))); 
    497514        return  
    498           MAKE_PERFDATA(alias, THandler::print_perf(value.value), _T(""),  
    499           THandler::print_perf(warn), THandler::print_perf(crit)); 
     515          MAKE_PERFDATA(alias, THandler::print_perf(value.value, unit), unit,  
     516          THandler::print_perf(warn, unit), THandler::print_perf(crit, unit)); 
    500517      } 
    501518    } 
  • include/strEx.h

    r5ac88c0a rde8ef76  
    310310    return ret; 
    311311  } 
     312  inline std::wstring format_BKMG(unsigned __int64 i, std::wstring unit) { 
     313    double cpy = static_cast<double>(i); 
     314    TCHAR postfix[] = _T(BKMG_RANGE); 
     315    if (unit.length() != 1) 
     316      return itos(cpy); 
     317    for (int i=0;i<BKMG_SIZE;i++) { 
     318      if (unit[0] == postfix[i]) { 
     319        std::wstringstream ss; 
     320        ss << std::setiosflags(std::ios::fixed) << std::setprecision(3) << cpy; 
     321        std::wstring s = ss.str(); 
     322        std::wstring::size_type pos = s.find_last_not_of(_T("0")); 
     323        if (pos != std::string::npos) { 
     324          s = s.substr(0,pos); 
     325        } 
     326        return s; 
     327      } 
     328      cpy/=1024; 
     329    } 
     330    return itos(cpy); 
     331  } 
     332  inline std::wstring find_proper_unit_BKMG(unsigned __int64 i) { 
     333    double cpy = static_cast<double>(i); 
     334    TCHAR postfix[] = _T(BKMG_RANGE); 
     335    int idx = 0; 
     336    while ((cpy > 999)&&(idx<BKMG_SIZE)) { 
     337      cpy/=1024; 
     338      idx++; 
     339    } 
     340    return std::wstring(1, postfix[idx]); 
     341  } 
    312342 
    313343  typedef std::list<std::wstring> splitList; 
Note: See TracChangeset for help on using the changeset viewer.