sandeep-krishnamurthy commented on a change in pull request #15132: Profiler
API Enhancements
URL: https://github.com/apache/incubator-mxnet/pull/15132#discussion_r291420380
##########
File path: src/profiler/aggregate_stats.cc
##########
@@ -28,100 +28,210 @@
#include <fstream>
#include <thread>
#include <iomanip>
+#include <queue>
+#include <utility>
#include "./profiler.h"
namespace mxnet {
namespace profiler {
+using pi = std::pair<double, std::string>;
+
template<typename DType>
inline float MicroToMilli(const DType micro) {
return static_cast<float>(static_cast<double>(micro) / 1000);
}
+template<typename DType>
+inline float ByteToKilobyte(const DType micro) {
+ return static_cast<float>(static_cast<double>(micro) / 100);
+}
+
+inline std::priority_queue<pi>
+ BuildHeap(const std::unordered_map<std::string, AggregateStats::StatData>&
mm,
+ int sort_by, int ascending) {
+ std::priority_queue<pi> heap;
+ for (const auto& iter : mm) {
+ const std::string& name = iter.first;
+ const AggregateStats::StatData &data = iter.second;
+ double value = 0;
+ switch (sort_by) {
+ case 0:
+ if (data.type_ == AggregateStats::StatData::kCounter)
+ value = (data.max_aggregate_ - data.min_aggregate_) / 2;
+ else
+ value = static_cast<double>(data.total_aggregate_)
+ / data.total_count_;
+ break;
+ case 1:
+ value = data.min_aggregate_;
+ break;
+ case 2:
+ value = data.max_aggregate_;
+ break;
+ case 3:
+ value = data.total_count_;
+ break;
+ }
+ if (ascending == 1)
+ value = -value;
+ heap.push(std::make_pair(value, name));
+ }
+ return heap;
+}
+
void AggregateStats::OnProfileStat(const ProfileStat& stat) {
std::unique_lock<std::mutex> lk(m_);
stat.SaveAggregate(&stats_[stat.categories_.c_str()][stat.name_.c_str()]);
}
-void AggregateStats::Dump(std::ostream& os, bool clear) {
+void AggregateStats::DumpTable(std::ostream& os, int sort_by, int ascending) {
std::ios state(nullptr);
state.copyfmt(os);
os << std::endl
- << "Profile Statistics." << std::endl
- << "\tNote that counter items are counter values and not time units."
+ << "Profile Statistics:" << std::endl
+ << "\tNote the difference in units for different entries."
<< std::endl;
std::unique_lock<std::mutex> lk(m_);
for (const auto& stat : stats_) {
const std::string& type = stat.first;
const std::unordered_map<std::string, StatData>& mm = stat.second;
- if (!mm.empty()) {
- os << type << std::endl << "=================" << std::endl;
- os << std::setw(25) << std::left << "Name"
- << std::setw(16) << std::right << "Total Count"
- << " "
- << std::setw(16) << std::right
- << "Time (ms)"
- << " "
- << std::setw(16) << std::right
- << "Min Time (ms)"
- << " "
- << std::setw(16) << std::right
- << "Max Time (ms)"
- << " "
- << std::setw(16) << std::right
- << "Avg Time (ms)"
- << std::endl;
- os << std::setw(25) << std::left << "----"
- << std::setw(16) << std::right << "-----------"
- << " "
- << std::setw(16) << std::right
- << "---------"
- << " "
- << std::setw(16) << std::right
- << "-------------"
- << " "
- << std::setw(16) << std::right
- << "-------------"
- << " "
- << std::setw(16) << std::right
- << "-------------"
- << std::endl;
- for (const auto& iter : mm) {
- const StatData &data = iter.second;
- if (data.type_ == StatData::kDuration || data.type_ ==
StatData::kCounter) {
- const std::string &name = iter.first;
- os << std::setw(25) << std::left << name
- << std::setw(16) << std::right << data.total_count_;
- os << " "
- << std::fixed << std::setw(16) << std::setprecision(4) <<
std::right
- << MicroToMilli(data.total_aggregate_)
- << " "
- << std::fixed << std::setw(16) << std::setprecision(4) <<
std::right
- << MicroToMilli(data.min_aggregate_)
- << " "
- << std::fixed << std::setw(16) << std::setprecision(4) <<
std::right
- << MicroToMilli(data.max_aggregate_);
- if (data.type_ == StatData::kCounter) {
- os << " "
- << std::fixed << std::setw(16) << std::setprecision(4) <<
std::right
- << (MicroToMilli(data.max_aggregate_ - data.min_aggregate_) /
2);
- } else {
- os << " "
- << std::fixed << std::setw(16) << std::setprecision(4) <<
std::right
- << (MicroToMilli(static_cast<double>(data.total_aggregate_)
- / data.total_count_));
- }
- os << std::endl;
- }
+ bool is_memory = (type == "Device Storage" || type == "Pool Memory");
+ os << type << std::endl << "=================" << std::endl;
+ os << std::setw(25) << std::left << "Name"
+ << std::setw(16) << std::right << "Total Count"
+ << " "
+ << (is_memory ? std::setw(0) : std::setw(16)) << std::right
+ << (is_memory ? "" : "Time (ms)")
+ << (is_memory ? "" : " ")
+ << std::setw(16) << std::right
+ << (is_memory ? "Min Use (kb)" : "Min Time (ms)")
Review comment:
KB ? bytes?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services