Implement statistics collection: (#2056)
1. Add `-s` CLI key to get statistics file path 2. Implement `StatisticsWriter` singleton to manage handle to this file
This commit is contained in:
parent
f86d930e3f
commit
4bd05c5364
@ -21,6 +21,9 @@ static const char target_device_message[] = "Required. Specify a target device t
|
||||
"Use \"-d MULTI:<comma-separated_devices_list>\" format to specify MULTI plugin. " \
|
||||
"The application looks for a suitable plugin for the specified device.";
|
||||
|
||||
/// @brief message for statistics path argument
|
||||
static const char statistics_path_message[] = "Required. Path to a file to write statistics.";
|
||||
|
||||
/// @brief Define flag for showing help message <br>
|
||||
DEFINE_bool(h, false, help_message);
|
||||
|
||||
@ -35,6 +38,10 @@ DEFINE_string(m, "", model_message);
|
||||
/// It is a required parameter
|
||||
DEFINE_string(d, "", target_device_message);
|
||||
|
||||
/// @brief Define parameter for set path to a file to write statistics <br>
|
||||
/// It is a required parameter
|
||||
DEFINE_string(s, "", statistics_path_message);
|
||||
|
||||
/**
|
||||
* @brief This function show a help message
|
||||
*/
|
||||
@ -46,4 +53,5 @@ static void showUsage() {
|
||||
std::cout << " -h, --help " << help_message << std::endl;
|
||||
std::cout << " -m \"<path>\" " << model_message << std::endl;
|
||||
std::cout << " -d \"<device>\" " << target_device_message << std::endl;
|
||||
std::cout << " -s \"<path>\" " << statistics_path_message << std::endl;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
//
|
||||
|
||||
#include "cli.h"
|
||||
#include "statistics_writer.h"
|
||||
#include "../ftti_pipeline/ftti_pipeline.h"
|
||||
|
||||
#include <iostream>
|
||||
@ -23,6 +24,9 @@ bool parseAndCheckCommandLine(int argc, char **argv) {
|
||||
if (FLAGS_d.empty())
|
||||
throw std::logic_error("Device is required but not set. Please set -d option.");
|
||||
|
||||
if (FLAGS_s.empty())
|
||||
throw std::logic_error("Statistics file path is required but not set. Please set -s option.");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -43,5 +47,6 @@ int main(int argc, char **argv) {
|
||||
if (!parseAndCheckCommandLine(argc, argv))
|
||||
return -1;
|
||||
|
||||
StatisticsWriter::Instance().setFile(FLAGS_s);
|
||||
return _runPipeline();
|
||||
}
|
55
tests/time_tests/common/statistics_writer.h
Normal file
55
tests/time_tests/common/statistics_writer.h
Normal file
@ -0,0 +1,55 @@
|
||||
// Copyright (C) 2020 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
/**
|
||||
* @brief Class response for writing provided statistics
|
||||
*
|
||||
* Object of the class is writing provided statistics to a specified
|
||||
* file in YAML format.
|
||||
*/
|
||||
class StatisticsWriter {
|
||||
private:
|
||||
std::ofstream statistics_file;
|
||||
|
||||
StatisticsWriter() = default;
|
||||
StatisticsWriter(const StatisticsWriter&) = delete;
|
||||
StatisticsWriter& operator=(const StatisticsWriter&) = delete;
|
||||
public:
|
||||
/**
|
||||
* @brief Creates StatisticsWriter singleton object
|
||||
*/
|
||||
static StatisticsWriter& Instance(){
|
||||
static StatisticsWriter writer;
|
||||
return writer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Specifies, opens and validates statistics path for writing
|
||||
*/
|
||||
void setFile(const std::string &statistics_path) {
|
||||
statistics_file.open(statistics_path);
|
||||
if (!statistics_file.good()) {
|
||||
std::stringstream err;
|
||||
err << "Statistic file \"" << statistics_path << "\" can't be used for writing";
|
||||
throw std::runtime_error(err.str());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Writes provided statistics in YAML format.
|
||||
*/
|
||||
void write(const std::pair<std::string, float> &record) {
|
||||
if (!statistics_file)
|
||||
throw std::runtime_error("Statistic file path isn't set");
|
||||
statistics_file << record.first << ": " << record.second << "\n";
|
||||
}
|
||||
};
|
@ -5,11 +5,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
|
||||
#include "statistics_writer.h"
|
||||
|
||||
using time_point = std::chrono::high_resolution_clock::time_point;
|
||||
|
||||
/**
|
||||
@ -38,7 +39,7 @@ public:
|
||||
~Timer(){
|
||||
float duration = std::chrono::duration_cast<std::chrono::microseconds>(
|
||||
std::chrono::high_resolution_clock::now() - start_time).count();
|
||||
std::cout << name << ":" << duration << "\n"; // TODO: replace with writer
|
||||
StatisticsWriter::Instance().write({name, duration});
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user