diff options
author | 2016-12-13 22:32:46 -0800 | |
---|---|---|
committer | 2016-12-13 22:43:54 -0800 | |
commit | 9466e2c7b6cc7924ae02017686c60209679fb3c4 (patch) | |
tree | 45d55686601f25ca276536ef96d263823d212b8b /tensorflow/core/util/stat_summarizer.h | |
parent | 9004714bc4de1c78735bfe8178b441a371df1762 (diff) |
Refactor StatSummarizer: use Stats for more things, remove redundant methods, combine mem/time data structures, and overhaul sorting / output formatting.
Change: 141981032
Diffstat (limited to 'tensorflow/core/util/stat_summarizer.h')
-rw-r--r-- | tensorflow/core/util/stat_summarizer.h | 103 |
1 files changed, 39 insertions, 64 deletions
diff --git a/tensorflow/core/util/stat_summarizer.h b/tensorflow/core/util/stat_summarizer.h index 57b17bd208..f766f0f281 100644 --- a/tensorflow/core/util/stat_summarizer.h +++ b/tensorflow/core/util/stat_summarizer.h @@ -38,6 +38,10 @@ template <typename ValueType, typename HighPrecisionValueType = double> class Stat { public: void UpdateStat(ValueType v) { + if (count_ == 0) { + first_ = v; + } + newest_ = v; max_ = std::max(v, max_); min_ = std::min(v, min_); @@ -50,6 +54,8 @@ class Stat { bool empty() const { return count_ == 0; } + ValueType first() const { return first_; } + ValueType newest() const { return newest_; } ValueType max() const { return max_; } @@ -77,12 +83,12 @@ class Stat { if (empty()) { *stream << "count=0"; } else if (all_same()) { - *stream << "curr=" << newest_ << " count=" << count_; + *stream << "count=" << count_ << " curr=" << newest_; if (count_ > 1) *stream << "(all same)"; } else { - *stream << "curr=" << newest_ << " count=" << count_ << " min=" << min_ - << " max=" << max_ << " avg=" << avg() - << " std=" << std_deviation(); + *stream << "count=" << count_ << " first=" << first_ + << " curr=" << newest_ << " min=" << min_ << " max=" << max_ + << " avg=" << avg() << " std=" << std_deviation(); } } @@ -93,6 +99,7 @@ class Stat { } private: + ValueType first_ = 0; ValueType newest_ = 0; ValueType max_ = std::numeric_limits<ValueType>::min(); ValueType min_ = std::numeric_limits<ValueType>::max(); @@ -121,93 +128,61 @@ class StatSummarizer { // Prints the output tensor sizes and types for each node. void PrintOutputs() const; - // Summarizes all nodes' stat in the order of top durations. - // Will stop printing if either cdf_cutoff_ratio or num_max_nodes_to_print - // is hit. - std::string GetTimingStatsByTopDurations( - double cdf_cutoff_ratio = 1.0, - int num_max_nodes_to_print = std::numeric_limits<int>::max()) const; - - // Summarizes all nodes' timing stat in the order of nodes getting executed. - std::string GetTimingStatsByRunOrder() const; - - // Summarizes all timing stats in the order of node definitions in the graph. - std::string GetTimingStatsByOrderOfNodeDefinitions() const; - - // Summarizes all nodes' stat in the order of memory used (high -> low). - // Will stop printing if either cdf_cutoff_ratio or num_max_nodes_to_print - // is hit. - std::string GetMemoryStatsByUsage( - double cdf_cutoff_ratio = 1.0, - int num_max_nodes_to_print = std::numeric_limits<int>::max()) const; - - // Summarizes all nodes' memory stat in the order of nodes getting executed. - std::string GetMemoryStatsByRunOrder() const; - - // Summarizes all memory stats in the order of node definitions in the graph. - std::string GetMemoryStatsByOrderOfNodeDefinitions() const; - - // Deprecated, use GetTimingStatsByOrderOfNodeDefinitions instead - std::string GetStatsByOrderOfNodeDefinitions() const; - - // Deprecated, use GetTimingStatsByRunOrder instead - std::string GetStatsByRunOrder() const; - - // Deprecated, use GetTimingStatsByTopDurations instead - std::string GetStatsByTopDurations( - double cdf_cutoff_ratio = 1.0, - int num_max_nodes_to_print = std::numeric_limits<int>::max()) const; - std::string GetStatsByNodeType() const; void Reset() { - run_total_micros_.Reset(); + run_total_us_.Reset(); memory_.Reset(); - timing_details_.clear(); - memory_details_.clear(); + details_.clear(); } // Returns number of runs. - int num_runs() const { return run_total_micros_.count(); } + int num_runs() const { return run_total_us_.count(); } // Returns stats of total microseconds spent by all nodes in each run. - const Stat<int64>& run_total_us() const { return run_total_micros_; } + const Stat<int64>& run_total_us() const { return run_total_us_; } private: struct Detail { - int64 first_start; - int64 first_rel_end; - int64 total; + string name; + string type; + int64 run_order; + Stat<int64> start_us; + Stat<int64> rel_end_us; + Stat<int64> mem_used; std::vector<TensorDescription> outputs; }; enum SortingMetric { - BY_TOTAL, + BY_NAME, + BY_DEFINITION_ORDER, BY_RUN_ORDER, + BY_TIME, + BY_MEMORY, + BY_TYPE, }; void Validate(const Detail* detail, const NodeExecStats& ns) const; - // Summarizes all nodes' stat in the order of node names defined in the graph. - std::string GetStatsByOrderOfNodeDefinitions(bool use_memory) const; + void OrderNodesByMetric(SortingMetric sorting_metric, + std::vector<const Detail*>* details) const; + + std::string GetStatsByMetric(const string& title, + SortingMetric sorting_metric, + int num_stats) const; - std::string GetStatsBySorting(SortingMetric sorting_metric, - double cdf_cutoff_ratio, - int num_max_nodes_to_print, - bool use_memory) const; + std::string HeaderString(const string& title) const; + std::string ColumnString(const Detail& detail, + const int64 cumulative_stat_on_node, + const Stat<int64>& stat) const; - std::string HeaderString() const; - std::string ColumnString(const std::string& name, const Detail& detail, - int64 cumulative_stat_on_node, - Stat<int64> stat) const; std::string ShortSummary() const; - int64 first_node_start_micros_; - Stat<int64> run_total_micros_; + Stat<int64> run_total_us_; Stat<int64> memory_; + std::vector<string> nodes_in_def_order_; - std::map<std::string, Detail> timing_details_; - std::map<std::string, Detail> memory_details_; + std::map<std::string, Detail> details_; std::map<string, string> node_types_; }; |