Add option to ignore negatives
parent
70a8e3b2ff
commit
0aab8d789c
|
@ -35,19 +35,30 @@ namespace blt::profiling {
|
||||||
};
|
};
|
||||||
|
|
||||||
void startInterval(const std::string& profileName, const std::string& intervalName);
|
void startInterval(const std::string& profileName, const std::string& intervalName);
|
||||||
|
|
||||||
void endInterval(const std::string& profileName, const std::string& intervalName);
|
void endInterval(const std::string& profileName, const std::string& intervalName);
|
||||||
|
|
||||||
void point(const std::string& profileName, const std::string& pointName);
|
void point(const std::string& profileName, const std::string& pointName);
|
||||||
|
|
||||||
capture_interval getInterval(const std::string& profileName, const std::string& intervalName);
|
capture_interval getInterval(const std::string& profileName, const std::string& intervalName);
|
||||||
|
|
||||||
std::vector<capture_interval> getAllIntervals(const std::string& profileName, const std::string& intervalName);
|
std::vector<capture_interval> getAllIntervals(const std::string& profileName, const std::string& intervalName);
|
||||||
|
|
||||||
profile getProfile(const std::string& profileName);
|
profile getProfile(const std::string& profileName);
|
||||||
|
|
||||||
void printProfile(const std::string& profileName, blt::logging::LOG_LEVEL loggingLevel = logging::NONE, bool averageHistory = false);
|
void printProfile(
|
||||||
void printOrderedProfile(const std::string& profileName, logging::LOG_LEVEL loggingLevel = logging::NONE, bool averageHistory = false);
|
const std::string& profileName, blt::logging::LOG_LEVEL loggingLevel = logging::NONE, bool averageHistory = false,
|
||||||
|
bool ignoreNegatives = true
|
||||||
|
);
|
||||||
|
|
||||||
|
void printOrderedProfile(
|
||||||
|
const std::string& profileName, logging::LOG_LEVEL loggingLevel = logging::NONE, bool averageHistory = false, bool ignoreNegatives = true
|
||||||
|
);
|
||||||
|
|
||||||
void discardProfiles();
|
void discardProfiles();
|
||||||
|
|
||||||
void discardIntervals(const std::string& profileName);
|
void discardIntervals(const std::string& profileName);
|
||||||
|
|
||||||
void discardPoints(const std::string& profileName);
|
void discardPoints(const std::string& profileName);
|
||||||
|
|
||||||
class scoped_interval {
|
class scoped_interval {
|
||||||
|
@ -58,6 +69,7 @@ namespace blt::profiling {
|
||||||
scoped_interval(std::string profile, std::string interval): m_Profile(std::move(profile)), m_Interval(std::move(interval)) {
|
scoped_interval(std::string profile, std::string interval): m_Profile(std::move(profile)), m_Interval(std::move(interval)) {
|
||||||
blt::profiling::startInterval(m_Profile, m_Interval);
|
blt::profiling::startInterval(m_Profile, m_Interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
~scoped_interval() {
|
~scoped_interval() {
|
||||||
blt::profiling::endInterval(m_Profile, m_Interval);
|
blt::profiling::endInterval(m_Profile, m_Interval);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ namespace blt::profiling {
|
||||||
logger << line;
|
logger << line;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printProfile(const std::string& profileName, blt::logging::LOG_LEVEL loggingLevel, bool averageHistory) {
|
void printProfile(const std::string& profileName, blt::logging::LOG_LEVEL loggingLevel, bool averageHistory, bool ignoreNegatives) {
|
||||||
string::TableFormatter formatter {profileName};
|
string::TableFormatter formatter {profileName};
|
||||||
formatter.addColumn({"Interval"});
|
formatter.addColumn({"Interval"});
|
||||||
formatter.addColumn({"Time (ns)"});
|
formatter.addColumn({"Time (ns)"});
|
||||||
|
@ -69,12 +69,16 @@ namespace blt::profiling {
|
||||||
long total_difference = 0;
|
long total_difference = 0;
|
||||||
for (const auto& h_interval : history) {
|
for (const auto& h_interval : history) {
|
||||||
const auto difference = h_interval.end - h_interval.start;
|
const auto difference = h_interval.end - h_interval.start;
|
||||||
|
if (ignoreNegatives && difference < 0)
|
||||||
|
continue;
|
||||||
total_difference += difference;
|
total_difference += difference;
|
||||||
}
|
}
|
||||||
total_difference /= (long) history.size();
|
total_difference /= (long) history.size();
|
||||||
formatter.addRow({interval.first, std::to_string(total_difference), std::to_string((double) total_difference / 1000000.0)});
|
formatter.addRow({interval.first, std::to_string(total_difference), std::to_string((double) total_difference / 1000000.0)});
|
||||||
} else {
|
} else {
|
||||||
const auto difference = interval.second.end - interval.second.start;
|
const auto difference = interval.second.end - interval.second.start;
|
||||||
|
if (ignoreNegatives && difference < 0)
|
||||||
|
continue;
|
||||||
formatter.addRow({interval.first, std::to_string(difference), std::to_string((double) difference / 1000000.0)});
|
formatter.addRow({interval.first, std::to_string(difference), std::to_string((double) difference / 1000000.0)});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,25 +102,31 @@ namespace blt::profiling {
|
||||||
return container1.difference < container2.difference;
|
return container1.difference < container2.difference;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printOrderedProfile(const std::string& profileName, logging::LOG_LEVEL loggingLevel, bool averageHistory) {
|
void printOrderedProfile(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;
|
||||||
const auto& points = profile.points;
|
const auto& points = profile.points;
|
||||||
|
|
||||||
std::vector<timeOrderContainer> unorderedIntervalVector;
|
std::vector<timeOrderContainer> unorderedIntervalVector;
|
||||||
|
|
||||||
|
// TODO: refactor to reduce nesting
|
||||||
|
|
||||||
for (const auto& interval : intervals) {
|
for (const auto& interval : intervals) {
|
||||||
if (averageHistory) {
|
if (averageHistory) {
|
||||||
const auto& history = profile.historicalIntervals[interval.first];
|
const auto& history = profile.historicalIntervals[interval.first];
|
||||||
long total_difference = 0;
|
long total_difference = 0;
|
||||||
for (const auto& h_interval : history) {
|
for (const auto& h_interval : history) {
|
||||||
const auto difference = h_interval.end - h_interval.start;
|
const auto difference = h_interval.end - h_interval.start;
|
||||||
|
if (ignoreNegatives && difference < 0)
|
||||||
|
continue;
|
||||||
total_difference += difference;
|
total_difference += difference;
|
||||||
}
|
}
|
||||||
total_difference /= (long) history.size();
|
total_difference /= (long) history.size();
|
||||||
unorderedIntervalVector.emplace_back(total_difference, std::string("(H) ") += interval.first);
|
unorderedIntervalVector.emplace_back(total_difference, std::string("(H) ") += interval.first);
|
||||||
} else {
|
} else {
|
||||||
const auto difference = interval.second.end - interval.second.start;
|
const auto difference = interval.second.end - interval.second.start;
|
||||||
|
if (ignoreNegatives && difference < 0)
|
||||||
|
continue;
|
||||||
unorderedIntervalVector.emplace_back(difference, interval.first);
|
unorderedIntervalVector.emplace_back(difference, interval.first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue