Changeset e93e741 in nscp for trunk/include
- Timestamp:
- 05/29/05 20:58:08 (8 years ago)
- Children:
- 24f7192
- Parents:
- 7da80b5
- Location:
- trunk/include
- Files:
-
- 4 edited
-
PDHCollectors.h (modified) (5 diffs)
-
PDHCounter.h (modified) (2 diffs)
-
strEx.h (modified) (1 diff)
-
utils.h (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/PDHCollectors.h
r7da80b5 re93e741 4 4 5 5 namespace PDHCollectors { 6 class StaticPDHCounterListenerInt : public PDH::PDHCounterListener { 7 __int64 value_; 6 template <class TType = __int64, DWORD TCollectionFormat = PDH_FMT_LARGE> 7 class StaticPDHCounterListener : public PDH::PDHCounterListener { 8 TType value_; 8 9 public: 9 10 virtual void collect(const PDH::PDHCounter &counter) { 10 setValue(counter.getInt64Value()); 11 switch (TCollectionFormat) { 12 case PDH_FMT_LARGE: 13 setValue(counter.getInt64Value()); 14 break; 15 case PDH_FMT_DOUBLE: 16 setValue(counter.getDoubleValue()); 17 break; 18 default: 19 return; 20 } 11 21 } 12 22 void attach(const PDH::PDHCounter &counter){} 13 23 void detach(const PDH::PDHCounter &counter){} 14 void setValue( __int64value) {24 void setValue(TType value) { 15 25 value_ = value; 16 26 } 17 __int64getValue() const {27 TType getValue() const { 18 28 return value_; 19 29 } 20 }; 21 class StaticPDHCounterListenerDouble : public PDH::PDHCounterListener { 22 double value_; 23 public: 24 virtual void collect(const PDH::PDHCounter &counter) { 25 setValue(counter.getDoubleValue()); 26 } 27 void attach(const PDH::PDHCounter &counter){} 28 void detach(const PDH::PDHCounter &counter){} 29 void setValue(double value) { 30 value_ = value; 31 } 32 double getValue() const { 33 return value_; 30 DWORD getFormat() const { 31 return TCollectionFormat; 34 32 } 35 33 }; 36 34 37 35 template <class TType = __int64, DWORD TCollectionFormat = PDH_FMT_LARGE> 38 36 class RoundINTPDHBufferListener : public PDH::PDHCounterListener { 39 37 unsigned int length; 40 int*buffer;38 TType *buffer; 41 39 unsigned int current; 42 40 public: … … 64 62 length = newLength; 65 63 66 buffer = new int[length];64 buffer = new TType[length]; 67 65 for (unsigned int i=0; i<length;i++) 68 66 buffer[i] = 0; … … 70 68 } 71 69 virtual void collect(const PDH::PDHCounter &counter) { 72 pushValue(static_cast<int>(counter.getInt64Value())); 70 switch (TCollectionFormat) { 71 case PDH_FMT_LONG: 72 pushValue(counter.getInt64Value()); 73 break; 74 case PDH_FMT_DOUBLE: 75 pushValue(counter.getInt64Value()); 76 break; 77 default: 78 return; 79 } 73 80 } 74 81 void attach(const PDH::PDHCounter &counter){} 75 82 void detach(const PDH::PDHCounter &counter){} 76 void pushValue( intvalue) {83 void pushValue(TType value) { 77 84 if (buffer == NULL) 78 85 return; … … 83 90 current = 0; 84 91 } 85 intgetAvrage(unsigned int backItems) const {92 TType getAvrage(unsigned int backItems) const { 86 93 if ((backItems == 0) || (backItems >= length)) 87 94 return -1; … … 98 105 ret += buffer[i]; 99 106 } 100 return static_cast<int>(ret/backItems);107 return (ret/backItems); 101 108 } 102 109 inline unsigned int getLength() const { 103 110 return length; 104 111 } 112 DWORD getFormat() const { 113 return TCollectionFormat; 114 } 105 115 }; 106 116 -
trunk/include/PDHCounter.h
r7da80b5 re93e741 23 23 virtual void attach(const PDHCounter &counter) = 0; 24 24 virtual void detach(const PDHCounter &counter) = 0; 25 virtual DWORD getFormat() const = 0; 25 26 }; 26 27 … … 72 73 return; 73 74 PDH_STATUS status; 74 if ((status = PdhGetFormattedCounterValue(hCounter_, PDH_FMT_LARGE , NULL, &data_)) != ERROR_SUCCESS) 75 if (!listener_) 76 return; 77 if ((status = PdhGetFormattedCounterValue(hCounter_, listener_->getFormat(), NULL, &data_)) != ERROR_SUCCESS) 75 78 throw PDHException("PdhGetFormattedCounterValue failed", status); 76 if (listener_) 77 listener_->collect(*this); 79 listener_->collect(*this); 78 80 } 79 81 double getDoubleValue() const { -
trunk/include/strEx.h
rf896cfb re93e741 40 40 } 41 41 inline std::string itos(unsigned long i) { 42 std::stringstream ss; 43 ss << i; 44 return ss.str(); 45 } 46 inline std::string itos(double i) { 42 47 std::stringstream ss; 43 48 ss << i; -
trunk/include/utils.h
rf896cfb re93e741 22 22 return strEx::itos(value) + "%"; 23 23 } 24 static std::string print_unformated(TType value) { 25 return strEx::itos(value); 26 } 24 27 }; 25 28 … … 34 37 } 35 38 static std::string print(TType value) { 39 return strEx::itos(value); 40 } 41 static std::string print_unformated(TType value) { 36 42 return strEx::itos(value); 37 43 } … … 54 60 55 61 Size() : bHasBounds_(false), value_(0) {}; 62 63 Size(const Size & other) { 64 bHasBounds_ = other.bHasBounds_; 65 value_ = other.value_; 66 } 67 56 68 void set(std::string s) { 57 69 value_ = THandler::parse(s); … … 101 113 102 114 SizePercentage() : type_(none), value_(0) {}; 115 116 SizePercentage(const SizePercentage &other) { 117 type_ = other.type_; 118 value_ = other.value_; 119 }; 103 120 void set(std::string s) { 104 121 std::string::size_type p = s.find_first_of('%'); … … 159 176 typedef SizeMaxMin<TType, THandler, THolder> TMyType; 160 177 178 SizeMaxMin() {} 179 SizeMaxMin(const SizeMaxMin &other) { 180 max = other.max; 181 min = other.min; 182 } 183 161 184 std::string printPerfData() 162 185 { 163 186 if (max.hasBounds()) { 164 return THandler::print (max.value_) + ";";187 return THandler::print_unformated(max.value_) + ";"; 165 188 } else if (min.hasBounds()) { 166 return THandler::print (min.value_) + ";";189 return THandler::print_unformated(min.value_) + ";"; 167 190 } 168 191 return "0;"; … … 180 203 THolder min; 181 204 typedef SizeMaxMinPercentage<TType, THandler, THolder> TMyType; 205 206 SizeMaxMinPercentage() {} 207 SizeMaxMinPercentage(const SizeMaxMinPercentage &other) { 208 max = other.max; 209 min = other.min; 210 } 182 211 183 212 bool isPercentage() { … … 207 236 if (max.hasBounds()) { 208 237 if (max.isPercentage()) { 209 return THandler::print ((max.value_*total)/100) + ";";210 } else { 211 return THandler::print (max.value_) + ";";238 return THandler::print_unformated((max.value_*total)/100) + ";"; 239 } else { 240 return THandler::print_unformated(max.value_) + ";"; 212 241 } 213 242 } else if (min.hasBounds()) { 214 243 if (min.isPercentage()) { 215 return THandler::print ((min.value_*total)/100) + ";";216 } else { 217 return THandler::print (min.value_) + ";";244 return THandler::print_unformated((min.value_*total)/100) + ";"; 245 } else { 246 return THandler::print_unformated(min.value_) + ";"; 218 247 } 219 248 } … … 236 265 237 266 }; 238 /*239 template <typename TType = drive_size, class THandler = drive_size_handler<>, class THolder = SizeMaxMinPercentage<> >240 class PerformancePrinterPercentage {241 public:242 static std::string printPerf(std::string name, TType value, TType total, THolder &warn, THolder &crit)243 {244 std::string s;245 bool percentage = crit.isPercentage() || warn.isPercentage();246 if (percentage)247 s += name + "=" + strEx::itos(value*100/total)+ "% ";248 else249 s+= name + "=" + strEx::itos(value) + ";";250 s += warn.printPerfData(percentage, value, total);251 s += crit.printPerfData(percentage, value, total);252 s += " ";253 return s;254 }255 };256 template <typename TType = drive_size, class THandler = drive_size_handler<>, class THolder = SizeMaxMin<> >257 class PerformancePrinter {258 public:259 static std::string printPerf(std::string name, TType value, THolder &warn, THolder &crit)260 {261 return name + "=" + strEx::itos(value) + ";" + warn.printPerfData() + crit.printPerfData();262 }263 };264 */265 267 } 266 268 void generate_crc32_table(void);
Note: See TracChangeset
for help on using the changeset viewer.








