Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wip #1850

Merged
merged 13 commits into from
Sep 21, 2024
Merged

Wip #1850

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
191 changes: 191 additions & 0 deletions scripts/compare_ut_performance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
#!/bin/ruby

require "nokogiri"

# Collect files from command line

files = []
time_class = :wall
sort_key = :name

ARGV.each do |arg|
if arg =~ /^--help|-h/
puts <<"END"
#{$0} [options] <file1> <file2> ...

The files are XML files produced by "ut_runner" with the -a option.

Options are:

-w Use wall time (default)
-u Use user time
-s Sort by average time, lowest first
+s Sort by average time, largest first

The script reads these files are compares performance (user and wall times)
of the different tests.
END
exit(0)
elsif arg == "-w"
time_class = :wall
elsif arg == "-u"
time_class = :user
elsif arg == "-s"
sort_key = :time_up
elsif arg == "+s"
sort_key = :time_down
elsif arg =~ /^-/
puts("*** ERROR: unknown option #{arg}. Use -h for help.")
exit(1)
else
files << arg
end
end


# A class representing the data from one test

class TestData

def initialize(file)

@file = file
@data = {}

File.open(file) do |f|

doc = Nokogiri::XML(f)

doc.xpath("//testsuite").each do |testsuite|
ts_name = testsuite.at_xpath("@name").content
testsuite.xpath("testcase").each do |testcase|
tc_name = testcase.at_xpath("@name").content
times = testcase.at_xpath("x-testcase-times")
if times
wall_time = times.at_xpath("@wall").content.to_f
user_time = times.at_xpath("@user").content.to_f
@data[ [ts_name, tc_name] ] = [ wall_time, user_time ]
end
end
end

end

end

def file
@file
end

def keys
@data.keys
end

def times(key)
@data[key]
end

end


# Read the tests

tests = []
files.each do |f|
puts("Reading test file #{f} ..")
tests << TestData::new(f)
end

puts "Reading done."
puts ""


# Build the comparison table

all_tests = {}

tests.each_with_index do |test,index|
test.keys.each do |k|
all_tests[k] ||= [nil] * tests.size
all_tests[k][index] = test.times(k)
end
end


# print the result

tests.each_with_index do |test,index|
puts "(#{index + 1}) #{test.file}"
end

puts ""

time_index = 0
if time_class == :wall
puts "Wall times"
elsif time_class == :user
time_index = 1
puts "User times"
end

puts ""

l1 = all_tests.keys.collect { |k| k[0].size }.max
l2 = all_tests.keys.collect { |k| k[1].size }.max

fmt = "%-#{l1}s %-#{l2}s " + (["%15s"] * tests.size).join(" ") + " %15s %15s %10s"

title = fmt % ([ "Testsuite", "Test", ] + tests.each_with_index.collect { |t,i| "(#{i + 1})" } + [ "Min", "Max", "Delta" ])
puts title
puts "-" * title.size

total = [0.0] * tests.size

lines = []

all_tests.keys.sort { |a,b| a <=> b }.each do |k|

times = all_tests[k].collect { |t| t && t[time_index] }

min = max = delta = nil
if ! times.index(nil)
times.each_with_index do |t,i|
total[i] += t
end
min = times.min
max = times.max
if times.size > 1 && (max + min).abs > 1.0
delta = (max - min) / 0.5 / (max + min)
end
end

line = fmt % (k + times.collect { |t| t ? ("%.6f" % t) : "" } + [ min ? "%.6f" % min : "", max ? "%.6f" % max : "", delta ? "%.2f%%" % (delta * 100) : ""])

if sort_key == :time_up
lines << [ min && max ? min + max : 0.0, line ]
elsif sort_key == :time_down
lines << [ min && max ? -(min + max) : 0.0, line ]
else
lines << [ k, line ]
end

end

lines.sort { |a,b| a[0] <=> b[0] }.each do |k,line|
puts line
end


# Add total row

min = total.min
max = total.max
delta = nil
if total.size > 1 && (max + min).abs > 1.0
delta = (max - min) / 0.5 / (max + min)
end

puts ""
puts fmt % ([ "Total" , "" ] + total.collect { |t| t ? ("%.6f" % t) : "" } + [ min ? "%.6f" % min : "", max ? "%.6f" % max : "", delta ? "%.2f%%" % (delta * 100) : ""])


3 changes: 3 additions & 0 deletions src/db/db/dbLayout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2876,6 +2876,9 @@ Layout::get_context_info (cell_index_type cell_index, LayoutOrCellContextInfo &i

// one level of library indirection
ly = &lib->layout ();
if (! ly->is_valid_cell_index (lib_proxy->library_cell_index ())) {
return any_meta; // abort
}
cptr = &ly->cell (lib_proxy->library_cell_index ());
info.lib_name = lib->get_name ();

Expand Down
19 changes: 10 additions & 9 deletions src/db/db/dbLibraryProxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ LibraryProxy::get_layer_indices (db::Layout &layout, db::ImportLayerMapping *lay

Library *lib = LibraryManager::instance ().lib (lib_id ());
tl_assert (lib != 0);
tl_assert (lib->layout ().is_valid_cell_index (library_cell_index ()));

const db::Cell &cell = lib->layout ().cell (library_cell_index ());

Expand Down Expand Up @@ -247,11 +248,11 @@ LibraryProxy::get_basic_name () const
{
Library *lib = LibraryManager::instance ().lib (lib_id ());
if (lib) {
const db::Cell *lib_cell = &lib->layout ().cell (library_cell_index ());
if (! lib_cell) {
if (! lib->layout ().is_valid_cell_index (library_cell_index ())) {
return "<defunct>";
} else {
return lib_cell->get_basic_name ();
const db::Cell &lib_cell = lib->layout ().cell (library_cell_index ());
return lib_cell.get_basic_name ();
}
} else {
return Cell::get_basic_name ();
Expand All @@ -263,11 +264,11 @@ LibraryProxy::get_display_name () const
{
Library *lib = LibraryManager::instance ().lib (lib_id ());
if (lib) {
const db::Cell *lib_cell = &lib->layout ().cell (library_cell_index ());
if (! lib_cell) {
if (! lib->layout ().is_valid_cell_index (library_cell_index ())) {
return lib->get_name () + "." + "<defunct>";
} else {
return lib->get_name () + "." + lib_cell->get_display_name ();
const db::Cell &lib_cell = lib->layout ().cell (library_cell_index ());
return lib->get_name () + "." + lib_cell.get_display_name ();
}
} else {
return Cell::get_display_name ();
Expand All @@ -279,11 +280,11 @@ LibraryProxy::get_qualified_name () const
{
Library *lib = LibraryManager::instance ().lib (lib_id ());
if (lib) {
const db::Cell *lib_cell = &lib->layout ().cell (library_cell_index ());
if (! lib_cell) {
if (! lib->layout ().is_valid_cell_index (library_cell_index ())) {
return lib->get_name () + "." + "<defunct>";
} else {
return lib->get_name () + "." + lib_cell->get_qualified_name ();
const db::Cell &lib_cell = lib->layout ().cell (library_cell_index ());
return lib->get_name () + "." + lib_cell.get_qualified_name ();
}
} else {
return Cell::get_qualified_name ();
Expand Down
35 changes: 34 additions & 1 deletion src/db/db/dbReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ join_layer_names (std::string &s, const std::string &n)
// ReaderBase implementation

ReaderBase::ReaderBase ()
: m_warnings_as_errors (false), m_warn_level (1)
: m_warnings_as_errors (false), m_warn_level (1), m_warn_count_for_same_message (0), m_first_warning (true)
{
}

Expand All @@ -79,6 +79,39 @@ void
ReaderBase::init (const db::LoadLayoutOptions &options)
{
m_warn_level = options.warn_level ();
m_last_warning.clear ();
m_warn_count_for_same_message = 0;
m_first_warning = true;
}

bool
ReaderBase::first_warning ()
{
bool f = m_first_warning;
m_first_warning = false;
return f;
}

int
ReaderBase::compress_warning (const std::string &msg)
{
const int max_warnings = 10;

if (! msg.empty () && msg == m_last_warning) {
if (m_warn_count_for_same_message < max_warnings) {
++m_warn_count_for_same_message;
return -1;
} else if (m_warn_count_for_same_message == max_warnings) {
++m_warn_count_for_same_message;
return 0;
} else {
return 1;
}
} else {
m_last_warning = msg;
m_warn_count_for_same_message = 0;
return -1;
}
}

// ---------------------------------------------------------------
Expand Down
15 changes: 15 additions & 0 deletions src/db/db/dbReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,27 @@ class DB_PUBLIC ReaderBase
return m_warn_level;
}

/**
* @brief Returns true (once) if this is the first warning
*/
bool first_warning ();

/**
* @brief Returns a value indicating whether to compress the given warning
*
* The return value is either -1 (do not skip), 0 (first warning not to be shown), 1 (warning not shown(.
*/
int compress_warning (const std::string &msg);

protected:
virtual void init (const db::LoadLayoutOptions &options);

private:
bool m_warnings_as_errors;
int m_warn_level;
std::string m_last_warning;
int m_warn_count_for_same_message;
bool m_first_warning;
};

/**
Expand Down
Loading
Loading