Ignore negative values by default
parent
811cdff8d1
commit
643053c409
|
@ -51,7 +51,7 @@ namespace blt::profiling {
|
||||||
|
|
||||||
void printProfile(
|
void printProfile(
|
||||||
const std::string& profileName, logging::LOG_LEVEL loggingLevel = logging::NONE,
|
const std::string& profileName, logging::LOG_LEVEL loggingLevel = logging::NONE,
|
||||||
bool averageHistory = false, bool ignoreNegatives = true
|
bool averageHistory = false
|
||||||
);
|
);
|
||||||
|
|
||||||
void writeProfile(std::ofstream& out, const std::string& profileName);
|
void writeProfile(std::ofstream& out, const std::string& profileName);
|
||||||
|
@ -104,7 +104,6 @@ namespace blt::profiling {
|
||||||
* @param profileName the profile to print
|
* @param profileName the profile to print
|
||||||
* @param loggingLevel blt::logging::LOG_LEVEL to log with (default: NONE)
|
* @param loggingLevel blt::logging::LOG_LEVEL to log with (default: NONE)
|
||||||
* @param averageHistory use the historical collection of interval rows in an average or just the latest? (default: false)
|
* @param averageHistory use the historical collection of interval rows in an average or just the latest? (default: false)
|
||||||
* @param ignoreNegatives ignore negative time values (default: true)
|
|
||||||
*/
|
*/
|
||||||
#define BLT_PRINT_PROFILE(profileName, ...) blt::profiling::printProfile(profileName, ##__VA_ARGS__)
|
#define BLT_PRINT_PROFILE(profileName, ...) blt::profiling::printProfile(profileName, ##__VA_ARGS__)
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -56,22 +56,29 @@ namespace blt::profiling {
|
||||||
const std::unordered_map<std::string, std::vector<capture_interval>>& intervals,
|
const std::unordered_map<std::string, std::vector<capture_interval>>& intervals,
|
||||||
std::unordered_map<std::string, capture_interval>& averagedIntervals
|
std::unordered_map<std::string, capture_interval>& averagedIntervals
|
||||||
) {
|
) {
|
||||||
|
// average all intervals
|
||||||
for (const auto& i : intervals) {
|
for (const auto& i : intervals) {
|
||||||
const auto& name = i.first;
|
const auto& name = i.first;
|
||||||
const auto& interval_vec = i.second;
|
const auto& interval_vec = i.second;
|
||||||
long total_difference = 0;
|
long total_difference = 0;
|
||||||
|
|
||||||
for (const auto& value : interval_vec)
|
// calculate total difference
|
||||||
total_difference += value.end - value.start;
|
for (const auto& value : interval_vec) {
|
||||||
|
auto difference = value.end - value.start;
|
||||||
|
// negatives make no sense. remove them to prevent errors
|
||||||
|
if (difference > 0)
|
||||||
|
total_difference += difference;
|
||||||
|
}
|
||||||
|
|
||||||
total_difference /= (long)interval_vec.size();
|
total_difference /= (long)interval_vec.size();
|
||||||
|
|
||||||
|
// create a new name for the interval that includes the sample size
|
||||||
std::string new_name = "(";
|
std::string new_name = "(";
|
||||||
new_name += std::to_string(interval_vec.size());
|
new_name += std::to_string(interval_vec.size());
|
||||||
new_name += ") ";
|
new_name += ") ";
|
||||||
new_name += name;
|
new_name += name;
|
||||||
|
|
||||||
// can exploit how the order func works by supplying the difference into end,
|
// we can exploit how the order func works by supplying the difference into end,
|
||||||
// which sorts correctly despite not being a true interval.
|
// which sorts correctly despite not being a true interval.
|
||||||
averagedIntervals.insert({new_name, capture_interval{0, total_difference}});
|
averagedIntervals.insert({new_name, capture_interval{0, total_difference}});
|
||||||
}
|
}
|
||||||
|
@ -82,8 +89,7 @@ namespace blt::profiling {
|
||||||
}
|
}
|
||||||
|
|
||||||
void printProfile(
|
void printProfile(
|
||||||
const std::string& profileName, logging::LOG_LEVEL loggingLevel, bool averageHistory,
|
const std::string& profileName, logging::LOG_LEVEL loggingLevel, bool averageHistory
|
||||||
bool ignoreNegatives
|
|
||||||
) {
|
) {
|
||||||
auto& profile = profiles[profileName];
|
auto& profile = profiles[profileName];
|
||||||
const auto& intervals = profile.intervals;
|
const auto& intervals = profile.intervals;
|
||||||
|
|
Loading…
Reference in New Issue