Generate Server-Timing headers interactively in modern C++11
Inpired by:
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>π View your server's metrics in @ChromeDevTools via Server Timing headers. Big thanks to longtime Firebug developer @sroussey for the patch! pic.twitter.com/OjDDIv0lLR
β Paul Irish (@paul_irish) February 7, 2017
The library is header-only. Just drop the servertiming.hpp in your project and use it. You'll need a modern C++11 compatible compiler though.
#include "servertiming.hpp"
ServerTiming timing();
timing.startTimer("Database Query");
// ... do something work-intensive
timing.stopTimer("Database Query");
// you can also add metrics without the timer function
// the time value is always in milliseconds!
timing.addMetric("Image Processing", 12365)
// ... use the header string within your server framework or whatever
std::string header = timing.generateHeader();
// this will output:
// database-query;dur=0.122;desc="Database Query",image-processing;dur=12.365;desc="Image Processing"