Commit a32ac9ae authored by Paal Kvamme's avatar Paal Kvamme
Browse files

In the performance logger, optionally output to a different log file for each reader.

parent 6fd370c6
......@@ -30,10 +30,10 @@ namespace InternalZGY {
}
#endif
FileWithPerformanceLogger::FileWithPerformanceLogger(std::shared_ptr<FileADT> relay, std::shared_ptr<std::ostream> outfile, std::int64_t chunksize, int hist_bincount, double hist_min, double hist_max, int interval)
FileWithPerformanceLogger::FileWithPerformanceLogger(std::shared_ptr<FileADT> relay, const std::string& outname, std::int64_t chunksize, int hist_bincount, double hist_min, double hist_max, int interval)
: FileRelay(relay)
, _recorder(new PerformanceLogger
(outfile, chunksize, hist_bincount, hist_min, hist_max, interval))
(outname, chunksize, hist_bincount, hist_min, hist_max, interval))
{
}
......@@ -91,9 +91,17 @@ FileWithPerformanceLogger::xx_close()
* Inject a telemetry module if enabled by environment variables.
* If not enabled the telemetry code has zero impact on the system.
*
* OPENZGY_MEASURE_KB = brick size to monitor, or -1 for all reads.
* OPENZGY_MEASURE_BINS = bins in histogram (default 251)
* OPENZGY_MEASURE_TIME = highest latency in ms (default 500)
* OPENZGY_MEASURE_KB = brick size to monitor, or -1 for all reads.
* OPENZGY_MEASURE_LOGFILE = optionally write to this file
* OPENZGY_MEASURE_BINS = bins in histogram (default 251)
* OPENZGY_MEASURE_TIME = highest latency in ms (default 500)
* OPENZGY_MEASURE_INTERVAL = periodic report of throughput and latency
*
* There are three distinct reports being output:
* - Periodic latency and throughput, enable by MEASURE_INTERVAL, tags CSV0,CSV8
* - Latency statistics for the entire file, tags CSV1,CSV2
* - Latency histogram for the entire file, tags CSV3,CSV4,CSV5,CSV6
* and can be fine tuned by MEASURE_BINS and MEASURE_TIME.
*/
std::shared_ptr<FileADT>
FileWithPerformanceLogger::inject(std::shared_ptr<FileADT> file)
......@@ -105,13 +113,7 @@ FileWithPerformanceLogger::inject(std::shared_ptr<FileADT> file)
int interval = Environment::getNumericEnv("OPENZGY_MEASURE_INTERVAL", 0);
std::string filename = Environment::getStringEnv("OPENZGY_MEASURE_LOGFILE");
std::shared_ptr<std::ostream> out;
if (!filename.empty()) {
out = std::make_shared<std::ofstream>(filename, std::ofstream::app);
}
else {
out = std::shared_ptr<std::ostream>(&std::cout, [](std::ostream*){});
}
file = std::shared_ptr<FileADT>(new FileWithPerformanceLogger(file, out, target*1024, bincount, 0.0, maxtime, interval));
file = std::shared_ptr<FileADT>(new FileWithPerformanceLogger(file, filename, target*1024, bincount, 0.0, maxtime, interval));
}
return file;
}
......
......@@ -50,7 +50,7 @@ private:
FileWithPerformanceLogger& operator=(FileWithPerformanceLogger&&) = delete;
public:
explicit FileWithPerformanceLogger(std::shared_ptr<FileADT> relay, std::shared_ptr<std::ostream> outfile, std::int64_t chunksize, int hist_bincount, double hist_min, double hist_max, int interval);
explicit FileWithPerformanceLogger(std::shared_ptr<FileADT> relay, const std::string& outname, std::int64_t chunksize, int hist_bincount, double hist_min, double hist_max, int interval);
virtual ~FileWithPerformanceLogger();
// Intercept
......
......@@ -33,8 +33,8 @@ namespace InternalZGY {
std::atomic<int> PerformanceLogger::_last_id{0};
PerformanceLogger::PerformanceLogger(std::shared_ptr<std::ostream> outfile, std::int64_t chunksize, int hist_bincount, double hist_min, double hist_max, int interval)
: _outfile(outfile)
PerformanceLogger::PerformanceLogger(const std::string& outname, std::int64_t chunksize, int hist_bincount, double hist_min, double hist_max, int interval)
: _outfile()
, _chunksize(chunksize)
, _mutex()
, _nsamples(0)
......@@ -54,6 +54,16 @@ PerformanceLogger::PerformanceLogger(std::shared_ptr<std::ostream> outfile, std:
, _id(0)
{
_id = 1 + _last_id.fetch_add(1);
std::string name(outname);
if (!name.empty()) {
std::size_t pos = name.find("{}");
if (pos != std::string::npos)
name = name.substr(0, pos) + std::to_string(_id) + name.substr(pos+2);
_outfile = std::make_shared<std::ofstream>(name, std::ofstream::app);
}
else {
_outfile = std::shared_ptr<std::ostream>(&std::cerr, [](std::ostream*){});
}
}
PerformanceLogger::~PerformanceLogger()
......
......@@ -64,7 +64,7 @@ class SummaryTimer;
class PerformanceLogger
{
private:
const std::shared_ptr<std::ostream> _outfile;
std::shared_ptr<std::ostream> _outfile;
const std::int64_t _chunksize;
mutable std::mutex _mutex;
// Latency a.k.a. round trip time: reported one for each thread.
......@@ -88,7 +88,7 @@ private:
PerformanceLogger& operator=(PerformanceLogger&&) = delete;
public:
explicit PerformanceLogger(std::shared_ptr<std::ostream> outfile, std::int64_t chunksize, int hist_bincount, double hist_min, double hist_max, int interval);
explicit PerformanceLogger(const std::string& outname, std::int64_t chunksize, int hist_bincount, double hist_min, double hist_max, int interval);
virtual ~PerformanceLogger();
bool logThisSize(std::int64_t size);
public:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment