| 27 | namespace cachelib { |
| 28 | namespace cachebench { |
| 29 | std::string EventInfo::formatTime() const { |
| 30 | // Out format is fixed size. It needs 16 chars with terminating null. For |
| 31 | // safety (if someone changes the strftime format) I made it double of it. |
| 32 | char buf[32]; |
| 33 | size_t bufSize{sizeof buf}; |
| 34 | auto tt = std::chrono::system_clock::to_time_t(tp); |
| 35 | struct tm tm_time; |
| 36 | ::localtime_r(&tt, &tm_time); |
| 37 | ::strftime(buf, bufSize, "%H:%M:%S", &tm_time); |
| 38 | auto len = std::strlen(buf); |
| 39 | auto micros = std::chrono::duration_cast<std::chrono::microseconds>( |
| 40 | tp.time_since_epoch()); |
| 41 | std::snprintf(buf + len, |
| 42 | bufSize - len, |
| 43 | ".%06d", |
| 44 | static_cast<int>(micros.count() % 1'000'000)); |
| 45 | return buf; |
| 46 | } |
| 47 | |
| 48 | bool ValueHistory::isWriteEnd(Event e) { |
| 49 | switch (e) { |