From b4746e1e3f1fccdb0c1b862a4e88a6f961b51bf2 Mon Sep 17 00:00:00 2001 From: Anna Petrosyan Date: Tue, 18 Jun 2024 11:56:30 +0400 Subject: [PATCH 01/10] Added long running commands runtime to log files, added unit test Signed-off-by: Anna Petrosyan --- src/drt/src/TritonRoute.cpp | 2 ++ src/gpl/src/nesterovPlace.cpp | 2 ++ src/grt/src/GlobalRouter.cpp | 2 ++ src/mpl2/src/rtl_mp.cpp | 2 ++ src/rsz/src/RepairDesign.cc | 2 ++ src/rsz/src/RepairHold.cc | 3 +++ src/utl/include/utl/timer.h | 13 ++++++++++ src/utl/src/timer.cpp | 21 ++++++++++++++++ src/utl/test/regression_tests.tcl | 1 + src/utl/test/test_statistics.ok | 1 + src/utl/test/test_statistics.py | 42 +++++++++++++++++++++++++++++++ test/regression.tcl | 28 ++++++++++++++++----- 12 files changed, 113 insertions(+), 6 deletions(-) create mode 100644 src/utl/test/test_statistics.ok create mode 100644 src/utl/test/test_statistics.py diff --git a/src/drt/src/TritonRoute.cpp b/src/drt/src/TritonRoute.cpp index eb13434889e..2dc33896398 100644 --- a/src/drt/src/TritonRoute.cpp +++ b/src/drt/src/TritonRoute.cpp @@ -57,6 +57,7 @@ #include "sta/StaMain.hh" #include "stt/SteinerTreeBuilder.h" #include "ta/FlexTA.h" +#include "utl/timer.h" namespace sta { // Tcl files encoded into strings. @@ -917,6 +918,7 @@ void TritonRoute::sendDesignUpdates(const std::string& globals_path) int TritonRoute::main() { + utl::ScopedStatistics stat(logger_); if (DBPROCESSNODE == "GF14_13M_3Mx_2Cx_4Kx_2Hx_2Gx_LB") { USENONPREFTRACKS = false; } diff --git a/src/gpl/src/nesterovPlace.cpp b/src/gpl/src/nesterovPlace.cpp index 90707177b7a..4fc6fb51691 100644 --- a/src/gpl/src/nesterovPlace.cpp +++ b/src/gpl/src/nesterovPlace.cpp @@ -46,6 +46,7 @@ #include "routeBase.h" #include "timingBase.h" #include "utl/Logger.h" +#include "utl/timer.h" namespace gpl { using utl::GPL; @@ -62,6 +63,7 @@ NesterovPlace::NesterovPlace(const NesterovPlaceVars& npVars, utl::Logger* log) : NesterovPlace() { + utl::ScopedStatistics stat(log); npVars_ = npVars; pbc_ = pbc; nbc_ = nbc; diff --git a/src/grt/src/GlobalRouter.cpp b/src/grt/src/GlobalRouter.cpp index 89c5b36cb37..1ed4f3528b9 100644 --- a/src/grt/src/GlobalRouter.cpp +++ b/src/grt/src/GlobalRouter.cpp @@ -72,6 +72,7 @@ #include "stt/SteinerTreeBuilder.h" #include "utl/Logger.h" #include "utl/algorithms.h" +#include "utl/timer.h" namespace grt { @@ -250,6 +251,7 @@ void GlobalRouter::globalRoute(bool save_guides, bool start_incremental, bool end_incremental) { + utl::ScopedStatistics stat(logger_); if (start_incremental && end_incremental) { logger_->error(GRT, 251, diff --git a/src/mpl2/src/rtl_mp.cpp b/src/mpl2/src/rtl_mp.cpp index 85334cd8427..98b443b9fde 100644 --- a/src/mpl2/src/rtl_mp.cpp +++ b/src/mpl2/src/rtl_mp.cpp @@ -37,6 +37,7 @@ #include "hier_rtlmp.h" #include "object.h" #include "odb/db.h" +#include "utl/timer.h" namespace mpl2 { using odb::dbDatabase; @@ -92,6 +93,7 @@ bool MacroPlacer2::place(const int num_threads, const bool bus_planning_on, const char* report_directory) { + utl::ScopedStatistics stat(logger_); hier_rtlmp_->setClusterSize( max_num_macro, min_num_macro, max_num_inst, min_num_inst); hier_rtlmp_->setClusterSizeTolerance(tolerance); diff --git a/src/rsz/src/RepairDesign.cc b/src/rsz/src/RepairDesign.cc index 32ea02dd422..5dc8d344377 100644 --- a/src/rsz/src/RepairDesign.cc +++ b/src/rsz/src/RepairDesign.cc @@ -51,6 +51,7 @@ #include "sta/Search.hh" #include "sta/SearchPred.hh" #include "sta/Units.hh" +#include "utl/timer.h" namespace rsz { @@ -93,6 +94,7 @@ void RepairDesign::repairDesign(double max_wire_length, bool verbose) { init(); + utl::ScopedStatistics stat(logger_); int repaired_net_count, slew_violations, cap_violations; int fanout_violations, length_violations; repairDesign(max_wire_length, diff --git a/src/rsz/src/RepairHold.cc b/src/rsz/src/RepairHold.cc index a8e5022a5fe..bd25f556654 100644 --- a/src/rsz/src/RepairHold.cc +++ b/src/rsz/src/RepairHold.cc @@ -55,6 +55,7 @@ #include "sta/TimingArc.hh" #include "sta/Units.hh" #include "utl/Logger.h" +#include "utl/timer.h" namespace rsz { @@ -93,6 +94,7 @@ void RepairHold::repairHold( const bool verbose) { init(); + utl::ScopedStatistics stat(logger_); sta_->checkSlewLimitPreamble(); sta_->checkCapacitanceLimitPreamble(); LibertyCell* buffer_cell = findHoldBuffer(); @@ -132,6 +134,7 @@ void RepairHold::repairHold(const Pin* end_pin, const int max_passes) { init(); + utl::ScopedStatistics stat(logger_); sta_->checkSlewLimitPreamble(); sta_->checkCapacitanceLimitPreamble(); LibertyCell* buffer_cell = findHoldBuffer(); diff --git a/src/utl/include/utl/timer.h b/src/utl/include/utl/timer.h index 0397748c6c3..5137482d838 100644 --- a/src/utl/include/utl/timer.h +++ b/src/utl/include/utl/timer.h @@ -35,6 +35,8 @@ #pragma once +#include + #include #include @@ -78,4 +80,15 @@ class DebugScopedTimer : public Timer std::ostream& operator<<(std::ostream& os, const Timer& t); +class ScopedStatistics : public Timer +{ + public: + ScopedStatistics(utl::Logger* logger); + ~ScopedStatistics() override; + + private: + size_t getPeakMemoryUsage(); + utl::Logger* logger_; +}; + } // namespace utl diff --git a/src/utl/src/timer.cpp b/src/utl/src/timer.cpp index ef5a30b944a..d850f34d936 100644 --- a/src/utl/src/timer.cpp +++ b/src/utl/src/timer.cpp @@ -35,6 +35,8 @@ #include "utl/timer.h" +#include + namespace utl { void Timer::reset() @@ -74,4 +76,23 @@ DebugScopedTimer::~DebugScopedTimer() debugPrint(logger_, tool_, group_.c_str(), level_, msg_, *this); } +ScopedStatistics::ScopedStatistics(utl::Logger* logger) + : Timer(), logger_(logger) +{ +} + +size_t ScopedStatistics::getPeakMemoryUsage() +{ + struct rusage rusage; + getrusage(RUSAGE_SELF, &rusage); + return (size_t) (rusage.ru_maxrss * 1024L); +} + +ScopedStatistics::~ScopedStatistics() +{ + logger_->report("Runtime {} seconds, memory used {} KB.", + Timer::elapsed(), + getPeakMemoryUsage()); +} + } // namespace utl diff --git a/src/utl/test/regression_tests.tcl b/src/utl/test/regression_tests.tcl index 320605e186b..912f850993c 100644 --- a/src/utl/test/regression_tests.tcl +++ b/src/utl/test/regression_tests.tcl @@ -3,6 +3,7 @@ record_tests { test_error test_suppress_message test_metrics + test_statistics #utl_man_tcl_check #utl_readme_msgs_check #test_error_exception diff --git a/src/utl/test/test_statistics.ok b/src/utl/test/test_statistics.ok new file mode 100644 index 00000000000..e7c76ecec8d --- /dev/null +++ b/src/utl/test/test_statistics.ok @@ -0,0 +1 @@ +Passed: Statistics are logged. diff --git a/src/utl/test/test_statistics.py b/src/utl/test/test_statistics.py new file mode 100644 index 00000000000..b38edc3ae8f --- /dev/null +++ b/src/utl/test/test_statistics.py @@ -0,0 +1,42 @@ +import os +import subprocess +import re + +def run_regression_script(regression_script_path, argument): + try: + subprocess.run([regression_script_path, argument], check=True) + except subprocess.CalledProcessError as e: + print(f"Error running regression script: {e}") + return False + return True + +def check_log_file(log_path): + pattern = re.compile(r"Runtime\s+\d+\.\d+\s+seconds,\s+memory used\s+\d+\s+KB") + runtime_count = 0 + + with open(log_path, 'r') as log_file: + for line in log_file: + if pattern.search(line): + runtime_count += 1 + if runtime_count == 2: + print("Passed: Statistics are logged.") + exit(0) + else: + print("Statistics are not logged enough times.") + exit(1) + +def main(): + script_dir = os.path.dirname(os.path.abspath(__file__)) + base_dir = os.path.abspath(os.path.join(script_dir, "../../rsz/test")) + log_path = os.path.join(base_dir, "results", "repair_design4-tcl.log") + regression_script_path = os.path.join(base_dir, "regression") + + if not os.path.exists(log_path): + if not run_regression_script(regression_script_path, "repair_design4"): + exit(1) + + check_log_file(log_path) + +if __name__ == "__main__": + main() + diff --git a/test/regression.tcl b/test/regression.tcl index 33d7b2f9d3e..4518e92d168 100755 --- a/test/regression.tcl +++ b/test/regression.tcl @@ -230,14 +230,30 @@ proc run_test_lang { test lang } { set tmp_file [file join $result_dir $test.tmp] exec tr -d "\r" < $log_file > $tmp_file file rename -force $tmp_file $log_file - if [catch [concat exec diff $diff_options $ok_file $log_file \ - >> $diff_file]] { - puts " *FAIL*$error_msg" - append_failure $test - incr errors(fail) + + # Create a temporary filtered log file that ignores lines with the specific pattern + set tmp_log_file [file join $result_dir "${test}_log.tmp"] + + set sed_result [catch {exec sed {/Runtime.*seconds.*memory.*used.*KB.*/d} \ + $log_file > $tmp_log_file} sed_error] + if {$sed_result != 0} { + puts "Error running sed" + puts "Error message: $sed_error" + incr errors(fail) } else { - puts " pass$error_msg" + # Proceed with the diff operation + set result [catch {exec diff $diff_options $ok_file $tmp_log_file >> $diff_file}] + if {$result != 0} { + exec cat $diff_file + puts " *FAIL*$error_msg" + append_failure $test + incr errors(fail) + } else { + puts " pass$error_msg" + } } + # Clean up the temporary filtered log file. + file delete -force $tmp_log_file } else { puts " *NO OK FILE*$error_msg" append_failure $test From 139a8668fc21abb1e1cbb34c9c4b3f3e4163a6bc Mon Sep 17 00:00:00 2001 From: Anna Petrosyan Date: Wed, 19 Jun 2024 18:25:30 +0400 Subject: [PATCH 02/10] Added vsz, rsz memory usage, added command name in log file. Signed-off-by: Anna Petrosyan --- src/drt/src/TritonRoute.cpp | 2 +- src/gpl/src/nesterovPlace.cpp | 2 +- src/grt/src/GlobalRouter.cpp | 2 +- src/mpl2/src/rtl_mp.cpp | 2 +- src/rsz/src/RepairDesign.cc | 2 +- src/rsz/src/RepairHold.cc | 4 +- src/utl/include/utl/timer.h | 12 +++++- src/utl/src/timer.cpp | 68 ++++++++++++++++++++++++++++----- src/utl/test/test_statistics.py | 2 +- test/regression.tcl | 66 +++++++++++++++++++------------- 10 files changed, 116 insertions(+), 46 deletions(-) diff --git a/src/drt/src/TritonRoute.cpp b/src/drt/src/TritonRoute.cpp index 2dc33896398..72d477f2907 100644 --- a/src/drt/src/TritonRoute.cpp +++ b/src/drt/src/TritonRoute.cpp @@ -918,7 +918,7 @@ void TritonRoute::sendDesignUpdates(const std::string& globals_path) int TritonRoute::main() { - utl::ScopedStatistics stat(logger_); + utl::ScopedStatistics stat(logger_, "detailed_route"); if (DBPROCESSNODE == "GF14_13M_3Mx_2Cx_4Kx_2Hx_2Gx_LB") { USENONPREFTRACKS = false; } diff --git a/src/gpl/src/nesterovPlace.cpp b/src/gpl/src/nesterovPlace.cpp index 4fc6fb51691..842e20af8b6 100644 --- a/src/gpl/src/nesterovPlace.cpp +++ b/src/gpl/src/nesterovPlace.cpp @@ -63,7 +63,7 @@ NesterovPlace::NesterovPlace(const NesterovPlaceVars& npVars, utl::Logger* log) : NesterovPlace() { - utl::ScopedStatistics stat(log); + utl::ScopedStatistics stat(log, "global_place"); npVars_ = npVars; pbc_ = pbc; nbc_ = nbc; diff --git a/src/grt/src/GlobalRouter.cpp b/src/grt/src/GlobalRouter.cpp index 6c01b816df6..4dc0de2fdd9 100644 --- a/src/grt/src/GlobalRouter.cpp +++ b/src/grt/src/GlobalRouter.cpp @@ -249,7 +249,7 @@ void GlobalRouter::globalRoute(bool save_guides, bool start_incremental, bool end_incremental) { - utl::ScopedStatistics stat(logger_); + utl::ScopedStatistics stat(logger_, "global_route"); if (start_incremental && end_incremental) { logger_->error(GRT, 251, diff --git a/src/mpl2/src/rtl_mp.cpp b/src/mpl2/src/rtl_mp.cpp index fabe1489490..47812d32e52 100644 --- a/src/mpl2/src/rtl_mp.cpp +++ b/src/mpl2/src/rtl_mp.cpp @@ -95,7 +95,7 @@ bool MacroPlacer2::place(const int num_threads, const bool bus_planning_on, const char* report_directory) { - utl::ScopedStatistics stat(logger_); + utl::ScopedStatistics stat(logger_, "rtl_macro_placer"); hier_rtlmp_->setClusterSize( max_num_macro, min_num_macro, max_num_inst, min_num_inst); hier_rtlmp_->setClusterSizeTolerance(tolerance); diff --git a/src/rsz/src/RepairDesign.cc b/src/rsz/src/RepairDesign.cc index 5dc8d344377..79806d2fc90 100644 --- a/src/rsz/src/RepairDesign.cc +++ b/src/rsz/src/RepairDesign.cc @@ -94,7 +94,7 @@ void RepairDesign::repairDesign(double max_wire_length, bool verbose) { init(); - utl::ScopedStatistics stat(logger_); + utl::ScopedStatistics stat(logger_, "repair_design"); int repaired_net_count, slew_violations, cap_violations; int fanout_violations, length_violations; repairDesign(max_wire_length, diff --git a/src/rsz/src/RepairHold.cc b/src/rsz/src/RepairHold.cc index bd25f556654..9f97630363e 100644 --- a/src/rsz/src/RepairHold.cc +++ b/src/rsz/src/RepairHold.cc @@ -94,7 +94,7 @@ void RepairHold::repairHold( const bool verbose) { init(); - utl::ScopedStatistics stat(logger_); + utl::ScopedStatistics stat(logger_, "repair_timing"); sta_->checkSlewLimitPreamble(); sta_->checkCapacitanceLimitPreamble(); LibertyCell* buffer_cell = findHoldBuffer(); @@ -134,7 +134,7 @@ void RepairHold::repairHold(const Pin* end_pin, const int max_passes) { init(); - utl::ScopedStatistics stat(logger_); + utl::ScopedStatistics stat(logger_, "repair_timing"); sta_->checkSlewLimitPreamble(); sta_->checkCapacitanceLimitPreamble(); LibertyCell* buffer_cell = findHoldBuffer(); diff --git a/src/utl/include/utl/timer.h b/src/utl/include/utl/timer.h index 5137482d838..614bad8a915 100644 --- a/src/utl/include/utl/timer.h +++ b/src/utl/include/utl/timer.h @@ -83,11 +83,19 @@ std::ostream& operator<<(std::ostream& os, const Timer& t); class ScopedStatistics : public Timer { public: - ScopedStatistics(utl::Logger* logger); + ScopedStatistics(utl::Logger* logger, std::string msg); ~ScopedStatistics() override; private: - size_t getPeakMemoryUsage(); + size_t getMemoryUsage(const char* tag); + size_t getStartRSZ(); + size_t getPeakRSZ(); + size_t getStartVSZ(); + size_t getPeakVSZ(); + + std::string msg_; + size_t start_rsz_; + size_t start_vsz_; utl::Logger* logger_; }; diff --git a/src/utl/src/timer.cpp b/src/utl/src/timer.cpp index d850f34d936..772795dd36d 100644 --- a/src/utl/src/timer.cpp +++ b/src/utl/src/timer.cpp @@ -33,10 +33,13 @@ // /////////////////////////////////////////////////////////////////////////////// +#define _GNU_SOURCE #include "utl/timer.h" #include +#include + namespace utl { void Timer::reset() @@ -76,23 +79,70 @@ DebugScopedTimer::~DebugScopedTimer() debugPrint(logger_, tool_, group_.c_str(), level_, msg_, *this); } -ScopedStatistics::ScopedStatistics(utl::Logger* logger) - : Timer(), logger_(logger) +ScopedStatistics::ScopedStatistics(utl::Logger* logger, std::string msg) + : Timer(), + msg_(msg), + start_rsz_(getStartRSZ()), + start_vsz_(getStartVSZ()), + logger_(logger) +{ +} + +size_t ScopedStatistics::getMemoryUsage(const char* tag) +{ + FILE* file = fopen("/proc/self/status", "r"); + if (file == NULL) { + perror("Failed to open /proc/self/status"); + exit(EXIT_FAILURE); + } + + size_t result = (size_t) -1; + char line[128]; + size_t tagLength = strlen(tag); + + while (fgets(line, sizeof(line), file) != NULL) { + if (strncmp(line, tag, tagLength) == 0) { + const char* p = line; + while (*p < '0' || *p > '9') + p++; + result = (size_t) atoi(p); + break; + } + } + + fclose(file); + if (result == (size_t) -1) { + fprintf(stderr, "%s not found in /proc/self/status\n", tag); + exit(EXIT_FAILURE); + } + + return result / 1024; +} + +size_t ScopedStatistics::getStartVSZ() +{ + return getMemoryUsage("VmSize:"); +} + +size_t ScopedStatistics::getPeakVSZ() +{ + return getMemoryUsage("VmPeak:"); +} + +size_t ScopedStatistics::getStartRSZ() { + return getMemoryUsage("VmRSS:"); } -size_t ScopedStatistics::getPeakMemoryUsage() +size_t ScopedStatistics::getPeakRSZ() { - struct rusage rusage; - getrusage(RUSAGE_SELF, &rusage); - return (size_t) (rusage.ru_maxrss * 1024L); + return getMemoryUsage("VmHWM:"); } ScopedStatistics::~ScopedStatistics() { - logger_->report("Runtime {} seconds, memory used {} KB.", - Timer::elapsed(), - getPeakMemoryUsage()); + logger_->report(msg_ + ": runtime {} seconds, usage: rsz = {} MB, vsz = {} MB, peak: rsz = {} MB, vsz = {} MB", static_cast(Timer::elapsed()), (getPeakRSZ() - start_rsz_), + (getPeakVSZ() - start_vsz_), (getPeakRSZ()), (getPeakVSZ())); } } // namespace utl diff --git a/src/utl/test/test_statistics.py b/src/utl/test/test_statistics.py index b38edc3ae8f..14836982c60 100644 --- a/src/utl/test/test_statistics.py +++ b/src/utl/test/test_statistics.py @@ -11,7 +11,7 @@ def run_regression_script(regression_script_path, argument): return True def check_log_file(log_path): - pattern = re.compile(r"Runtime\s+\d+\.\d+\s+seconds,\s+memory used\s+\d+\s+KB") + pattern = re.compile(r"repair_design: runtime.*seconds.*usage.*rsz.*MB.*vsz.*MB.*peak.*rsz.*vsz.*") runtime_count = 0 with open(log_path, 'r') as log_file: diff --git a/test/regression.tcl b/test/regression.tcl index 4518e92d168..59eb6349265 100755 --- a/test/regression.tcl +++ b/test/regression.tcl @@ -180,6 +180,40 @@ proc run_test { test } { } } +proc log_comparer {test log_file ok_file diff_file diff_options error_msg} { + global result_dir errors + + # Filter dos '/r's from log file. + set tmp_file [file join $result_dir $test.tmp] + exec tr -d "\r" < $log_file > $tmp_file + file rename -force $tmp_file $log_file + + # Create a temporary filtered log file that ignores lines with the specific pattern + set tmp_log_file [file join $result_dir "${test}_log.tmp"] + + set sed_result [catch \ + {exec sed {/.*runtime.*seconds.*usage.*rsz.*MB.*vsz.*MB.*peak.*rsz.*vsz.*/d} \ + $log_file > $tmp_log_file} sed_error] + if {$sed_result != 0} { + puts "Error running sed" + puts "Error message: $sed_error" + incr errors(fail) + return 1 + } else { + # Proceed with the diff operation + set result [catch {exec diff $diff_options $ok_file $tmp_log_file >> $diff_file}] + if {$result != 0} { + puts " *FAIL log_and_ok*$error_msg" + return 1 + } else { + puts " pass$error_msg" + return 0 + } + } + # Clean up the temporary filtered log file. + file delete -force $tmp_log_file +} + proc run_test_lang { test lang } { global result_dir diff_file errors diff_options @@ -226,34 +260,12 @@ proc run_test_lang { test lang } { switch [test_pass_criteria $test] { compare_logfile { if { [file exists $ok_file] } { - # Filter dos '/r's from log file. - set tmp_file [file join $result_dir $test.tmp] - exec tr -d "\r" < $log_file > $tmp_file - file rename -force $tmp_file $log_file - - # Create a temporary filtered log file that ignores lines with the specific pattern - set tmp_log_file [file join $result_dir "${test}_log.tmp"] - - set sed_result [catch {exec sed {/Runtime.*seconds.*memory.*used.*KB.*/d} \ - $log_file > $tmp_log_file} sed_error] - if {$sed_result != 0} { - puts "Error running sed" - puts "Error message: $sed_error" - incr errors(fail) - } else { - # Proceed with the diff operation - set result [catch {exec diff $diff_options $ok_file $tmp_log_file >> $diff_file}] - if {$result != 0} { - exec cat $diff_file - puts " *FAIL*$error_msg" - append_failure $test - incr errors(fail) - } else { - puts " pass$error_msg" - } + set compare_result [log_comparer $test $log_file $ok_file \ + $diff_file $diff_options $error_msg] + if {$compare_result != 0} { + append_failure $test + incr errors(fail) } - # Clean up the temporary filtered log file. - file delete -force $tmp_log_file } else { puts " *NO OK FILE*$error_msg" append_failure $test From fe02c84ff1899c30edf731c788f7346e080dcc0d Mon Sep 17 00:00:00 2001 From: Anna Petrosyan Date: Thu, 20 Jun 2024 10:24:35 +0400 Subject: [PATCH 03/10] Removed unused define Signed-off-by: Anna Petrosyan --- src/utl/src/timer.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utl/src/timer.cpp b/src/utl/src/timer.cpp index 772795dd36d..4bfee722f16 100644 --- a/src/utl/src/timer.cpp +++ b/src/utl/src/timer.cpp @@ -33,7 +33,6 @@ // /////////////////////////////////////////////////////////////////////////////// -#define _GNU_SOURCE #include "utl/timer.h" #include @@ -81,7 +80,7 @@ DebugScopedTimer::~DebugScopedTimer() ScopedStatistics::ScopedStatistics(utl::Logger* logger, std::string msg) : Timer(), - msg_(msg), + msg_(std::move(msg)), start_rsz_(getStartRSZ()), start_vsz_(getStartVSZ()), logger_(logger) @@ -91,7 +90,7 @@ ScopedStatistics::ScopedStatistics(utl::Logger* logger, std::string msg) size_t ScopedStatistics::getMemoryUsage(const char* tag) { FILE* file = fopen("/proc/self/status", "r"); - if (file == NULL) { + if (file == nullptr) { perror("Failed to open /proc/self/status"); exit(EXIT_FAILURE); } @@ -100,11 +99,12 @@ size_t ScopedStatistics::getMemoryUsage(const char* tag) char line[128]; size_t tagLength = strlen(tag); - while (fgets(line, sizeof(line), file) != NULL) { + while (fgets(line, sizeof(line), file) != nullptr) { if (strncmp(line, tag, tagLength) == 0) { const char* p = line; - while (*p < '0' || *p > '9') + while (*p < '0' || *p > '9') { p++; + } result = (size_t) atoi(p); break; } From d38cfdee39d504d85c7238141f5703614b850172 Mon Sep 17 00:00:00 2001 From: Anna Petrosyan Date: Tue, 25 Jun 2024 17:18:33 +0400 Subject: [PATCH 04/10] Change logging format and unit test Signed-off-by: Anna Petrosyan --- src/gpl/src/nesterovPlace.cpp | 2 +- src/rsz/src/RepairDesign.cc | 2 - src/rsz/src/RepairHold.cc | 7 +-- src/rsz/src/Resizer.cc | 4 ++ src/utl/include/utl/timer.h | 7 +-- src/utl/src/timer.cpp | 108 ++++++++++++++++++-------------- src/utl/test/test_statistics.py | 51 ++++++++------- test/regression.tcl | 2 +- 8 files changed, 98 insertions(+), 85 deletions(-) diff --git a/src/gpl/src/nesterovPlace.cpp b/src/gpl/src/nesterovPlace.cpp index 842e20af8b6..71ea722bcb5 100644 --- a/src/gpl/src/nesterovPlace.cpp +++ b/src/gpl/src/nesterovPlace.cpp @@ -63,7 +63,6 @@ NesterovPlace::NesterovPlace(const NesterovPlaceVars& npVars, utl::Logger* log) : NesterovPlace() { - utl::ScopedStatistics stat(log, "global_place"); npVars_ = npVars; pbc_ = pbc; nbc_ = nbc; @@ -301,6 +300,7 @@ void NesterovPlace::reset() int NesterovPlace::doNesterovPlace(int start_iter) { + utl::ScopedStatistics stat(log_, "global_place"); // if replace diverged in init() function, // replace must be skipped. if (isDiverged_) { diff --git a/src/rsz/src/RepairDesign.cc b/src/rsz/src/RepairDesign.cc index 79806d2fc90..32ea02dd422 100644 --- a/src/rsz/src/RepairDesign.cc +++ b/src/rsz/src/RepairDesign.cc @@ -51,7 +51,6 @@ #include "sta/Search.hh" #include "sta/SearchPred.hh" #include "sta/Units.hh" -#include "utl/timer.h" namespace rsz { @@ -94,7 +93,6 @@ void RepairDesign::repairDesign(double max_wire_length, bool verbose) { init(); - utl::ScopedStatistics stat(logger_, "repair_design"); int repaired_net_count, slew_violations, cap_violations; int fanout_violations, length_violations; repairDesign(max_wire_length, diff --git a/src/rsz/src/RepairHold.cc b/src/rsz/src/RepairHold.cc index 9f97630363e..ad267353a6b 100644 --- a/src/rsz/src/RepairHold.cc +++ b/src/rsz/src/RepairHold.cc @@ -55,7 +55,6 @@ #include "sta/TimingArc.hh" #include "sta/Units.hh" #include "utl/Logger.h" -#include "utl/timer.h" namespace rsz { @@ -80,8 +79,10 @@ RepairHold::RepairHold(Resizer* resizer) : resizer_(resizer) void RepairHold::init() { logger_ = resizer_->logger_; - dbStaState::init(resizer_->sta_); + sta_ = resizer_->sta_; db_network_ = resizer_->db_network_; + + copyState(sta_); } void RepairHold::repairHold( @@ -94,7 +95,6 @@ void RepairHold::repairHold( const bool verbose) { init(); - utl::ScopedStatistics stat(logger_, "repair_timing"); sta_->checkSlewLimitPreamble(); sta_->checkCapacitanceLimitPreamble(); LibertyCell* buffer_cell = findHoldBuffer(); @@ -134,7 +134,6 @@ void RepairHold::repairHold(const Pin* end_pin, const int max_passes) { init(); - utl::ScopedStatistics stat(logger_, "repair_timing"); sta_->checkSlewLimitPreamble(); sta_->checkCapacitanceLimitPreamble(); LibertyCell* buffer_cell = findHoldBuffer(); diff --git a/src/rsz/src/Resizer.cc b/src/rsz/src/Resizer.cc index 175d9fd3b28..1c38b9986bc 100644 --- a/src/rsz/src/Resizer.cc +++ b/src/rsz/src/Resizer.cc @@ -66,6 +66,7 @@ #include "sta/TimingModel.hh" #include "sta/Units.hh" #include "utl/Logger.h" +#include "utl/timer.h" // http://vlsicad.eecs.umich.edu/BK/Slots/cache/dropzone.tamu.edu/~zhuoli/GSRC/fast_buffer_insertion.html @@ -2528,6 +2529,7 @@ void Resizer::repairDesign(double max_wire_length, double cap_margin, bool verbose) { + utl::ScopedStatistics stat(logger_, "repair_design"); resizePreamble(); if (parasitics_src_ == ParasiticsSrc::global_routing) { opendp_->initMacrosAndGrid(); @@ -2717,6 +2719,7 @@ void Resizer::repairHold( int max_passes, bool verbose) { + utl::ScopedStatistics stat(logger_, "repair_timing"); resizePreamble(); if (parasitics_src_ == ParasiticsSrc::global_routing) { opendp_->initMacrosAndGrid(); @@ -2736,6 +2739,7 @@ void Resizer::repairHold(const Pin* end_pin, float max_buffer_percent, int max_passes) { + utl::ScopedStatistics stat(logger_, "repair_timing"); resizePreamble(); repair_hold_->repairHold(end_pin, setup_margin, diff --git a/src/utl/include/utl/timer.h b/src/utl/include/utl/timer.h index 614bad8a915..2d179a2bcdd 100644 --- a/src/utl/include/utl/timer.h +++ b/src/utl/include/utl/timer.h @@ -35,7 +35,8 @@ #pragma once -#include +#include +#include #include #include @@ -87,16 +88,14 @@ class ScopedStatistics : public Timer ~ScopedStatistics() override; private: - size_t getMemoryUsage(const char* tag); size_t getStartRSZ(); size_t getPeakRSZ(); - size_t getStartVSZ(); - size_t getPeakVSZ(); std::string msg_; size_t start_rsz_; size_t start_vsz_; utl::Logger* logger_; + clock_t cpu_start_; }; } // namespace utl diff --git a/src/utl/src/timer.cpp b/src/utl/src/timer.cpp index 4bfee722f16..795001fee72 100644 --- a/src/utl/src/timer.cpp +++ b/src/utl/src/timer.cpp @@ -35,9 +35,21 @@ #include "utl/timer.h" +#if defined(__unix__) || defined(__unix) || defined(unix) \ + || (defined(__APPLE__) && defined(__MACH__)) #include +#include -#include +#if defined(__APPLE__) && defined(__MACH__) +#include + +#elif defined(__linux__) || defined(__linux) || defined(linux) \ + || defined(__gnu_linux__) +#include +#include +#endif + +#endif namespace utl { @@ -82,67 +94,69 @@ ScopedStatistics::ScopedStatistics(utl::Logger* logger, std::string msg) : Timer(), msg_(std::move(msg)), start_rsz_(getStartRSZ()), - start_vsz_(getStartVSZ()), - logger_(logger) + logger_(logger), + cpu_start_(clock()) { } -size_t ScopedStatistics::getMemoryUsage(const char* tag) +size_t ScopedStatistics::getStartRSZ() { - FILE* file = fopen("/proc/self/status", "r"); - if (file == nullptr) { - perror("Failed to open /proc/self/status"); - exit(EXIT_FAILURE); +#if defined(__APPLE) && defined(__MACH__) + struct mach_task_basic_info info; + mach_msg_type_number_t info_count = MACH_TASK_BASIC_INFO_COUNT; + if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO, + (task_info_t) &info, &info_count) { + return (size_t) 0L; } - - size_t result = (size_t) -1; - char line[128]; - size_t tagLength = strlen(tag); - - while (fgets(line, sizeof(line), file) != nullptr) { - if (strncmp(line, tag, tagLength) == 0) { - const char* p = line; - while (*p < '0' || *p > '9') { - p++; - } - result = (size_t) atoi(p); - break; - } + return (size_t) info.resident_size / 1024; +#elif defined(__linux) || defined(__linux) || defined(linux) \ + || defined(__gnu_linux__) + int64_t rss = 0L; + FILE* fp = fopen("/proc/self/statm", "r"); + if (fp == nullptr) { + return (size_t) 0L; } - - fclose(file); - if (result == (size_t) -1) { - fprintf(stderr, "%s not found in /proc/self/status\n", tag); - exit(EXIT_FAILURE); + if (fscanf(fp, "%*s%ld", &rss) != 1) { + fclose(fp); + return (size_t) 0L; } - - return result / 1024; -} - -size_t ScopedStatistics::getStartVSZ() -{ - return getMemoryUsage("VmSize:"); -} - -size_t ScopedStatistics::getPeakVSZ() -{ - return getMemoryUsage("VmPeak:"); -} - -size_t ScopedStatistics::getStartRSZ() -{ - return getMemoryUsage("VmRSS:"); + fclose(fp); + return ((size_t) rss * (size_t) sysconf(_SC_PAGESIZE)) / (1024 * 1024); +#else + return (size_t) 0L; /* Unsupported. */ +#endif } size_t ScopedStatistics::getPeakRSZ() { - return getMemoryUsage("VmHWM:"); +#if defined(__unix__) || defined(__unix) || defined(unix) \ + || (defined(__APPLE__) && defined(__MACH__)) + struct rusage rsg; + if (getrusage(RUSAGE_SELF, &rsg) != 0) { + return (size_t) 0L; + } +#if defined(__APPLE__) && defined(__MACH__) + return ((size_t) rsg.ru_maxrss) / (1024 * 1024); +#else + return (size_t) rsg.ru_maxrss / 1024; +#endif +#endif } ScopedStatistics::~ScopedStatistics() { - logger_->report(msg_ + ": runtime {} seconds, usage: rsz = {} MB, vsz = {} MB, peak: rsz = {} MB, vsz = {} MB", static_cast(Timer::elapsed()), (getPeakRSZ() - start_rsz_), - (getPeakVSZ() - start_vsz_), (getPeakRSZ()), (getPeakVSZ())); + auto ts_elapsed = Timer::elapsed(); + int hour = ts_elapsed / 3600; + int min = (((int) ts_elapsed % 3600) / 60); + int sec = (int) ts_elapsed % 60; + + auto ts_cpu = (clock() - cpu_start_) / CLOCKS_PER_SEC; + int chour = ts_cpu / 3600; + int cmin = (ts_cpu % 3600) / 60; + int csec = ts_cpu % 60; + + logger_->report(msg_ + ": cpu time = {:02}:{:02}:{:02}, elapsed time = {:02}:{:02}:{:02}, memory = {} MB, peak = {} MB", + chour, cmin, csec, hour, min, sec, start_rsz_, getPeakRSZ()); } } // namespace utl diff --git a/src/utl/test/test_statistics.py b/src/utl/test/test_statistics.py index 14836982c60..0890efe23e2 100644 --- a/src/utl/test/test_statistics.py +++ b/src/utl/test/test_statistics.py @@ -1,41 +1,40 @@ import os -import subprocess import re - -def run_regression_script(regression_script_path, argument): - try: - subprocess.run([regression_script_path, argument], check=True) - except subprocess.CalledProcessError as e: - print(f"Error running regression script: {e}") - return False - return True +from openroad import Tech, Design def check_log_file(log_path): - pattern = re.compile(r"repair_design: runtime.*seconds.*usage.*rsz.*MB.*vsz.*MB.*peak.*rsz.*vsz.*") - runtime_count = 0 + pattern = re.compile(r"global.*route.*cpu.*time.*elapsed.*time.*memory.*peak.*") + match_count = 0 with open(log_path, 'r') as log_file: for line in log_file: if pattern.search(line): - runtime_count += 1 - if runtime_count == 2: - print("Passed: Statistics are logged.") - exit(0) - else: - print("Statistics are not logged enough times.") - exit(1) + match_count += 1 + + return match_count == 1 def main(): - script_dir = os.path.dirname(os.path.abspath(__file__)) - base_dir = os.path.abspath(os.path.join(script_dir, "../../rsz/test")) - log_path = os.path.join(base_dir, "results", "repair_design4-tcl.log") - regression_script_path = os.path.join(base_dir, "regression") + test_path = os.path.abspath(os.path.dirname(__file__)) - if not os.path.exists(log_path): - if not run_regression_script(regression_script_path, "repair_design4"): - exit(1) + tech = Tech() + tech.readLef(os.path.join(test_path, "../../../test/Nangate45/Nangate45.lef")) - check_log_file(log_path) + design = Design(tech) + gcddef = os.path.abspath(os.path.join(test_path, "../../grt/test/gcd.def")) + design.readDef(gcddef) + + gr = design.getGlobalRouter() + gr.globalRoute(True) + + log_path = os.path.join(test_path, "results", "test_statistics-py.log") + if check_log_file(log_path): + with open(log_path, 'w') as log_file: + log_file.write("Passed: Statistics are logged.\n") + exit(0) + else: + with open(log_path, 'w') as log_file: + log_file.write("Failed: Statistics are not logged.\n") + exit(1) if __name__ == "__main__": main() diff --git a/test/regression.tcl b/test/regression.tcl index 59eb6349265..23d36217bd4 100755 --- a/test/regression.tcl +++ b/test/regression.tcl @@ -192,7 +192,7 @@ proc log_comparer {test log_file ok_file diff_file diff_options error_msg} { set tmp_log_file [file join $result_dir "${test}_log.tmp"] set sed_result [catch \ - {exec sed {/.*runtime.*seconds.*usage.*rsz.*MB.*vsz.*MB.*peak.*rsz.*vsz.*/d} \ + {exec sed {/.*cpu.*time.*.*elapsed.*time.*memory.*peak.*/d} \ $log_file > $tmp_log_file} sed_error] if {$sed_result != 0} { puts "Error running sed" From a3adf9fa4bd83ac8758a0829fc9c82d05166659f Mon Sep 17 00:00:00 2001 From: Anna Petrosyan Date: Tue, 25 Jun 2024 17:58:18 +0400 Subject: [PATCH 05/10] Restore RepairHold Signed-off-by: Anna Petrosyan --- src/rsz/src/RepairHold.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/rsz/src/RepairHold.cc b/src/rsz/src/RepairHold.cc index ad267353a6b..a8e5022a5fe 100644 --- a/src/rsz/src/RepairHold.cc +++ b/src/rsz/src/RepairHold.cc @@ -79,10 +79,8 @@ RepairHold::RepairHold(Resizer* resizer) : resizer_(resizer) void RepairHold::init() { logger_ = resizer_->logger_; - sta_ = resizer_->sta_; + dbStaState::init(resizer_->sta_); db_network_ = resizer_->db_network_; - - copyState(sta_); } void RepairHold::repairHold( From f86f009f9909d5df81c0b7a06cfc1ba1a46c2c4a Mon Sep 17 00:00:00 2001 From: Anna Petrosyan Date: Thu, 27 Jun 2024 11:58:13 +0400 Subject: [PATCH 06/10] Change header files Signed-off-by: Anna Petrosyan --- src/utl/include/utl/timer.h | 4 ++-- src/utl/src/timer.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utl/include/utl/timer.h b/src/utl/include/utl/timer.h index 2d179a2bcdd..0a96c05be65 100644 --- a/src/utl/include/utl/timer.h +++ b/src/utl/include/utl/timer.h @@ -35,8 +35,8 @@ #pragma once -#include -#include +#include +#include #include #include diff --git a/src/utl/src/timer.cpp b/src/utl/src/timer.cpp index 795001fee72..043d9b1b128 100644 --- a/src/utl/src/timer.cpp +++ b/src/utl/src/timer.cpp @@ -43,7 +43,7 @@ #if defined(__APPLE__) && defined(__MACH__) #include -#elif defined(__linux__) || defined(__linux) || defined(linux) \ +#elif defined(__linux) || defined(linux) \ || defined(__gnu_linux__) #include #include @@ -109,7 +109,7 @@ size_t ScopedStatistics::getStartRSZ() return (size_t) 0L; } return (size_t) info.resident_size / 1024; -#elif defined(__linux) || defined(__linux) || defined(linux) \ +#elif defined(__linux) || defined(linux) \ || defined(__gnu_linux__) int64_t rss = 0L; FILE* fp = fopen("/proc/self/statm", "r"); @@ -121,7 +121,7 @@ size_t ScopedStatistics::getStartRSZ() return (size_t) 0L; } fclose(fp); - return ((size_t) rss * (size_t) sysconf(_SC_PAGESIZE)) / (1024 * 1024); + return static_cast(rss) * static_cast(sysconf(_SC_PAGESIZE)) / (1024 * 1024); #else return (size_t) 0L; /* Unsupported. */ #endif From 2fba1c35c5132124082098bb0513430ae439cbec Mon Sep 17 00:00:00 2001 From: Anna Petrosyan Date: Thu, 27 Jun 2024 12:54:20 +0400 Subject: [PATCH 07/10] Improve format Signed-off-by: Anna Petrosyan --- src/utl/include/utl/timer.h | 3 +-- src/utl/src/timer.cpp | 9 ++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/utl/include/utl/timer.h b/src/utl/include/utl/timer.h index 0a96c05be65..3d4c4649554 100644 --- a/src/utl/include/utl/timer.h +++ b/src/utl/include/utl/timer.h @@ -35,10 +35,9 @@ #pragma once +#include #include #include - -#include #include #include "utl/Logger.h" diff --git a/src/utl/src/timer.cpp b/src/utl/src/timer.cpp index 043d9b1b128..17bb370a559 100644 --- a/src/utl/src/timer.cpp +++ b/src/utl/src/timer.cpp @@ -43,8 +43,7 @@ #if defined(__APPLE__) && defined(__MACH__) #include -#elif defined(__linux) || defined(linux) \ - || defined(__gnu_linux__) +#elif defined(__linux) || defined(linux) || defined(__gnu_linux__) #include #include #endif @@ -109,8 +108,7 @@ size_t ScopedStatistics::getStartRSZ() return (size_t) 0L; } return (size_t) info.resident_size / 1024; -#elif defined(__linux) || defined(linux) \ - || defined(__gnu_linux__) +#elif defined(__linux) || defined(linux) || defined(__gnu_linux__) int64_t rss = 0L; FILE* fp = fopen("/proc/self/statm", "r"); if (fp == nullptr) { @@ -121,7 +119,8 @@ size_t ScopedStatistics::getStartRSZ() return (size_t) 0L; } fclose(fp); - return static_cast(rss) * static_cast(sysconf(_SC_PAGESIZE)) / (1024 * 1024); + return static_cast(rss) * static_cast(sysconf(_SC_PAGESIZE)) + / (1024 * 1024); #else return (size_t) 0L; /* Unsupported. */ #endif From e18535d7ee77921157abe64dd7c0842e7f2e9973 Mon Sep 17 00:00:00 2001 From: Anna Petrosyan Date: Fri, 28 Jun 2024 10:35:53 +0400 Subject: [PATCH 08/10] Remove unused parameters Signed-off-by: Anna Petrosyan --- src/utl/include/utl/timer.h | 1 - src/utl/src/timer.cpp | 9 +++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utl/include/utl/timer.h b/src/utl/include/utl/timer.h index 3d4c4649554..c9a018dd8e1 100644 --- a/src/utl/include/utl/timer.h +++ b/src/utl/include/utl/timer.h @@ -92,7 +92,6 @@ class ScopedStatistics : public Timer std::string msg_; size_t start_rsz_; - size_t start_vsz_; utl::Logger* logger_; clock_t cpu_start_; }; diff --git a/src/utl/src/timer.cpp b/src/utl/src/timer.cpp index 17bb370a559..02166ae22bc 100644 --- a/src/utl/src/timer.cpp +++ b/src/utl/src/timer.cpp @@ -51,6 +51,7 @@ #endif namespace utl { +const size_t FRACTION = 1024; void Timer::reset() { @@ -107,7 +108,7 @@ size_t ScopedStatistics::getStartRSZ() (task_info_t) &info, &info_count) { return (size_t) 0L; } - return (size_t) info.resident_size / 1024; + return (size_t) info.resident_size / FRACTION; #elif defined(__linux) || defined(linux) || defined(__gnu_linux__) int64_t rss = 0L; FILE* fp = fopen("/proc/self/statm", "r"); @@ -120,7 +121,7 @@ size_t ScopedStatistics::getStartRSZ() } fclose(fp); return static_cast(rss) * static_cast(sysconf(_SC_PAGESIZE)) - / (1024 * 1024); + / (FRACTION * FRACTION); #else return (size_t) 0L; /* Unsupported. */ #endif @@ -135,9 +136,9 @@ size_t ScopedStatistics::getPeakRSZ() return (size_t) 0L; } #if defined(__APPLE__) && defined(__MACH__) - return ((size_t) rsg.ru_maxrss) / (1024 * 1024); + return ((size_t) rsg.ru_maxrss) / (FRACTION * FRACTION); #else - return (size_t) rsg.ru_maxrss / 1024; + return (size_t) rsg.ru_maxrss / FRACTION; #endif #endif } From d1014706710bc8e2a6e8471ecbb2453046bdfc3b Mon Sep 17 00:00:00 2001 From: Anna Petrosyan Date: Fri, 28 Jun 2024 12:16:40 +0400 Subject: [PATCH 09/10] Changes related to defines Signed-off-by: Anna Petrosyan --- src/utl/src/timer.cpp | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/src/utl/src/timer.cpp b/src/utl/src/timer.cpp index 02166ae22bc..b1b026db892 100644 --- a/src/utl/src/timer.cpp +++ b/src/utl/src/timer.cpp @@ -43,7 +43,14 @@ #if defined(__APPLE__) && defined(__MACH__) #include -#elif defined(__linux) || defined(linux) || defined(__gnu_linux__) +#elif (defined(_AIX) || defined(__TOS__AIX__)) \ + || (defined(__sun__) || defined(__sun) \ + || defined(sun) && (defined(__SVR4) || defined(__svr4__))) +#include +#include + +#elif defined(__linux__) || defined(__linux) || defined(linux) \ + || defined(__gnu_linux__) #include #include #endif @@ -51,7 +58,7 @@ #endif namespace utl { -const size_t FRACTION = 1024; +const size_t kFactor = 1024; void Timer::reset() { @@ -101,15 +108,16 @@ ScopedStatistics::ScopedStatistics(utl::Logger* logger, std::string msg) size_t ScopedStatistics::getStartRSZ() { -#if defined(__APPLE) && defined(__MACH__) +#if defined(__APPLE__) && defined(__MACH__) struct mach_task_basic_info info; mach_msg_type_number_t info_count = MACH_TASK_BASIC_INFO_COUNT; if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t) &info, &info_count) { return (size_t) 0L; } - return (size_t) info.resident_size / FRACTION; -#elif defined(__linux) || defined(linux) || defined(__gnu_linux__) + return (size_t) info.resident_size / kFactor; +#elif defined(__linux__) || defined(__linux) || defined(linux) \ + || defined(__gnu_linux__) int64_t rss = 0L; FILE* fp = fopen("/proc/self/statm", "r"); if (fp == nullptr) { @@ -120,8 +128,7 @@ size_t ScopedStatistics::getStartRSZ() return (size_t) 0L; } fclose(fp); - return static_cast(rss) * static_cast(sysconf(_SC_PAGESIZE)) - / (FRACTION * FRACTION); + return (size_t) rss * (size_t) sysconf(_SC_PAGESIZE) / (kFactor * kFactor); #else return (size_t) 0L; /* Unsupported. */ #endif @@ -129,17 +136,29 @@ size_t ScopedStatistics::getStartRSZ() size_t ScopedStatistics::getPeakRSZ() { -#if defined(__unix__) || defined(__unix) || defined(unix) \ +#if (defined(_AIX) || defined(__TOS__AIX__)) \ + || (defined(__sun__) || defined(__sun) \ + || defined(sun) && (defined(__SVR4) || defined(__svr4__))) + struct psinfo psinfo; + int fd = -1; + if ((fd = open("/proc/self/psinfo", O_RDONLY)) == -1) + return (size_t) 0L; /* Can't open? */ + if (read(fd, &psinfo, sizeof(psinfo)) != sizeof(psinfo)) { + close(fd); + return (size_t) 0L; /* Can't read? */ + } + close(fd); + return (size_t) (psinfo.pr_rssize * kFactor); +#elif defined(__unix__) || defined(__unix) || defined(unix) \ || (defined(__APPLE__) && defined(__MACH__)) struct rusage rsg; if (getrusage(RUSAGE_SELF, &rsg) != 0) { return (size_t) 0L; } -#if defined(__APPLE__) && defined(__MACH__) - return ((size_t) rsg.ru_maxrss) / (FRACTION * FRACTION); +#elif defined(__APPLE__) && defined(__MACH__) + return ((size_t) rsg.ru_maxrss) / (kFactor * kFactor); #else - return (size_t) rsg.ru_maxrss / FRACTION; -#endif + return (size_t) rsg.ru_maxrss / kFactor; #endif } From fd70ec056012004076f8b5ead7c0cf1ef6098ece Mon Sep 17 00:00:00 2001 From: Anna Petrosyan Date: Fri, 28 Jun 2024 13:19:03 +0400 Subject: [PATCH 10/10] Add checks for unsupported OS Signed-off-by: Anna Petrosyan --- src/utl/src/timer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utl/src/timer.cpp b/src/utl/src/timer.cpp index b1b026db892..ed0fa832822 100644 --- a/src/utl/src/timer.cpp +++ b/src/utl/src/timer.cpp @@ -160,6 +160,7 @@ size_t ScopedStatistics::getPeakRSZ() #else return (size_t) rsg.ru_maxrss / kFactor; #endif + return (size_t) 0L; /* Unsupported. */ } ScopedStatistics::~ScopedStatistics()