From 4f73e0850e13a8a15ce5a0234697126b737b29a9 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 28 Aug 2014 22:10:39 -0400 Subject: [PATCH] Improve verilator_profcfunc time attributions. --- Changes | 2 ++ bin/verilator_profcfunc | 16 ++++++++++- test_regress/t/t_case_huge.pl | 10 +++---- test_regress/t/t_case_huge_prof.pl | 44 ++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 6 deletions(-) create mode 100755 test_regress/t/t_case_huge_prof.pl diff --git a/Changes b/Changes index fff4d3836..b66625da0 100644 --- a/Changes +++ b/Changes @@ -5,6 +5,8 @@ indicates the contributor was also the author of the fix; Thanks! * Verilator 3.863 devel +**** Improve verilator_profcfunc time attributions. [Jonathon Donaldson] + **** Fix duplicate anonymous structures in $root, bug788. [Bob Newgard] **** Fix mis-optimization of bit-swap in wide signal, bug800. [Jie Xu] diff --git a/bin/verilator_profcfunc b/bin/verilator_profcfunc index 46d253a93..ac1d16334 100755 --- a/bin/verilator_profcfunc +++ b/bin/verilator_profcfunc @@ -118,6 +118,18 @@ sub profcfunc { $groups{type}{"Common code under $design"} += $pct; $groups{design}{$design} += $pct; $groups{module}{$design." common code"} += $pct; + } elsif ($func =~ /^VL_[A-Z0-9_]+/ + || $func =~ /^_?vl_[a-zA-Z0-9_]+/ + || $func =~ /^verilated/i) { + $vfunc = sprintf("VLib %s", $func); + $groups{type}{'VLib'} += $pct; + $groups{design}{'VLib'} += $pct; + $groups{module}{'VLib'} += $pct; + } elsif ($func =~ /^_mcount_private/) { + $vfunc = sprintf("Prof %s", $func); + $groups{type}{'Prof'} += $pct; + $groups{design}{'Prof'} += $pct; + $groups{module}{'Prof'} += $pct; } else { $vfunc = sprintf("C++ %s", $func); $groups{type}{'C++'} += $pct; @@ -129,7 +141,7 @@ sub profcfunc { } - foreach my $type qw(type design module) { + foreach my $type (qw(type design module)) { my $missing = 100; foreach (sort (keys %{$groups{$type}})) { $missing -= $groups{$type}{$_}; @@ -150,8 +162,10 @@ sub profcfunc { print("Verilog code profile:\n"); print(" These are split into three categories:\n"); print(" C++: Time in non-Verilated C++ code\n"); + print(" Prof: Time in profile overhead\n"); print(" VBlock: Time attributable to a block in a Verilog file and line\n"); print(" VCommon: Time in a Verilated module, due to all parts of the design\n"); + print(" VLib: Time in Verilated common libraries, called by the Verilated code\n"); print("\n"); print(" % cumulative self \n"); diff --git a/test_regress/t/t_case_huge.pl b/test_regress/t/t_case_huge.pl index 4d285b7b8..e29a6c00c 100755 --- a/test_regress/t/t_case_huge.pl +++ b/test_regress/t/t_case_huge.pl @@ -8,17 +8,17 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di # Version 2.0. compile ( - verilator_flags2 => ["--stats --profile-cfuncs"], - ); + verilator_flags2 => ["--stats"], + ); if ($Self->{vlt}) { file_grep ($Self->{stats}, qr/Optimizations, Tables created\s+(\d+)/i, 10); - file_grep ($Self->{stats}, qr/Optimizations, Combined CFuncs\s+(\d+)/i, 10); + file_grep ($Self->{stats}, qr/Optimizations, Combined CFuncs\s+(\d+)/i, 9); } execute ( - check_finished=>1, - ); + check_finished=>1, + ); ok(1); 1; diff --git a/test_regress/t/t_case_huge_prof.pl b/test_regress/t/t_case_huge_prof.pl new file mode 100755 index 000000000..d75393067 --- /dev/null +++ b/test_regress/t/t_case_huge_prof.pl @@ -0,0 +1,44 @@ +#!/usr/bin/perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003 by Wilson Snyder. This program is free software; you can +# redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. + +$Self->{vlt} or $Self->skip("Verilator only test"); + +top_filename("t/t_case_huge.v"); + +compile ( + verilator_flags2 => ["--stats --profile-cfuncs -CFLAGS '-pg' -LDFLAGS '-pg'"], + ); + +if ($Self->{vlt}) { + file_grep ($Self->{stats}, qr/Optimizations, Tables created\s+(\d+)/i, 10); + file_grep ($Self->{stats}, qr/Optimizations, Combined CFuncs\s+(\d+)/i, 10); +} + +unlink $_ foreach (glob "$Self->{obj_dir}/gmon.out.*"); +$ENV{GMON_OUT_PREFIX} = "$Self->{obj_dir}/gmon.out"; + +execute ( + check_finished=>1, + ); + +my $gmon_path; +$gmon_path = $_ foreach (glob "$Self->{obj_dir}/gmon.out.*"); +$gmon_path or $Self->error("Profiler did not create a gmon.out"); +(my $gmon_base = $gmon_path) =~ s!.*[/\\]!!; + +$Self->_run(cmd=>["cd $Self->{obj_dir} && gprof $Self->{VM_PREFIX} $gmon_base > gprof.out"], + check_finished=>0); + +$Self->_run(cmd=>["cd $Self->{obj_dir} && $ENV{VERILATOR_ROOT}/bin/verilator_profcfunc gprof.out > cfuncs.out"], + check_finished=>0); + +file_grep ("$Self->{obj_dir}/cfuncs.out", qr/Overall summary by/); + +ok(1); +1;