Add option to ignore negatives

v1
Brett 2023-02-14 22:32:23 -05:00
parent 70a8e3b2ff
commit 0aab8d789c
2 changed files with 27 additions and 5 deletions

View File

@ -20,7 +20,7 @@
namespace blt::profiling {
struct capture_point {
std::string name;
long point {};
long point{};
};
struct capture_interval {
@ -35,19 +35,30 @@ namespace blt::profiling {
};
void startInterval(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);
capture_interval getInterval(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);
void printProfile(const std::string& profileName, blt::logging::LOG_LEVEL loggingLevel = logging::NONE, bool averageHistory = false);
void printOrderedProfile(const std::string& profileName, logging::LOG_LEVEL loggingLevel = logging::NONE, bool averageHistory = false);
void printProfile(
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 discardIntervals(const std::string& profileName);
void discardPoints(const std::string& profileName);
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)) {
blt::profiling::startInterval(m_Profile, m_Interval);
}
~scoped_interval() {
blt::profiling::endInterval(m_Profile, m_Interval);
}

View File

@ -53,7 +53,7 @@ namespace blt::profiling {
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};
formatter.addColumn({"Interval"});
formatter.addColumn({"Time (ns)"});
@ -69,12 +69,16 @@ namespace blt::profiling {
long total_difference = 0;
for (const auto& h_interval : history) {
const auto difference = h_interval.end - h_interval.start;
if (ignoreNegatives && difference < 0)
continue;
total_difference += difference;
}
total_difference /= (long) history.size();
formatter.addRow({interval.first, std::to_string(total_difference), std::to_string((double) total_difference / 1000000.0)});
} else {
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)});
}
}
@ -98,25 +102,31 @@ namespace blt::profiling {
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];
const auto& intervals = profile.intervals;
const auto& points = profile.points;
std::vector<timeOrderContainer> unorderedIntervalVector;
// TODO: refactor to reduce nesting
for (const auto& interval : intervals) {
if (averageHistory) {
const auto& history = profile.historicalIntervals[interval.first];
long total_difference = 0;
for (const auto& h_interval : history) {
const auto difference = h_interval.end - h_interval.start;
if (ignoreNegatives && difference < 0)
continue;
total_difference += difference;
}
total_difference /= (long) history.size();
unorderedIntervalVector.emplace_back(total_difference, std::string("(H) ") += interval.first);
} else {
const auto difference = interval.second.end - interval.second.start;
if (ignoreNegatives && difference < 0)
continue;
unorderedIntervalVector.emplace_back(difference, interval.first);
}
}