This is an archive of the discontinued LLVM Phabricator instance.

WIP: [llvm-locstats] Add the llvm-locstats tool
AbandonedPublic

Authored by djtodoro on Aug 1 2019, 9:07 AM.

Details

Summary

As we discussed, I am sharing the patch that introduces the llvm-locstats tool.

(I am copying the summary from the README from https://github.com/djolertrk/llvm-locstats).

This tool calculates and reports verbose output for the debug location coverage of a binary.

It is very similar to a tool (locstats) from the Elfutils package, but the tool is not being maintained and released for a long time.

The llvm-locstats for each variable or formal parameter DIE computes what percentage from the code section bytes, where it is in scope, it has location description. There are options to ignore inlined instances or/and entry value locations. The line 0 shows the number (and the percentage) of DIEs with no location information, but the line 100 shows the number (and the percentage) of DIEs where there is location information in all code section bytes (where the variable or parameter is in the scope). The line 51..59 shows the number (and the percentage) of DIEs where the location information is in between 51 and 59 percentage of its scope covered.
...
Using the tool

Running the tool on a simple test case:
bin/llvm-locstats test

=================================================
          Debug Location Statistics
=================================================
  cov%          samples       percentage
-------------------------------------------------
    0                1              25%
    1..9             0               0%
    11..19           0               0%
    21..29           0               0%
    31..39           0               0%
    41..49           0               0%
    51..59           0               0%
    61..69           0               0%
    71..79           0               0%
    81..89           0               0%
    91..99           0               0%
    100              3              75%
=================================================
  -the number of debug variables processed: 4
  -the average coverage per var: ~ 75%
=================================================

Running the tool on the GDB 7.11 binary:
bin/llvm-locstats gdb

=================================================
          Debug Location Statistics
=================================================
  cov%          samples       percentage
-------------------------------------------------
    0             8495               8%
    1..9          3037               3%
    11..19        3015               3%
    21..29        2769               2%
    31..39        2802               2%
    41..49        2766               2%
    51..59        3141               3%
    61..69        3173               3%
    71..79        3923               3%
    81..89        4948               5%
    91..99        7354               7%
    100          53433              54%
=================================================
  -the number of debug variables processed: 98856
  -the average coverage per var: ~ 76%
=================================================

Running the tool on the GDB 7.11 binary by ignoring debug entry values:
bin/llvm-locstats --ignore-entry-values gdb

=================================================
          Debug Location Statistics
=================================================
  cov%          samples       percentage
-------------------------------------------------
    0             8765               8%
    1..9          3948               3%
    11..19        4436               4%
    21..29        4152               4%
    31..39        4107               4%
    41..49        3846               3%
    51..59        4490               4%
    61..69        4140               4%
    71..79        4998               5%
    81..89        7072               7%
    91..99       15478              15%
    100          33424              33%
=================================================
  -the number of debug variables processed: 98856
  -the average coverage per var: ~ 69%
=================================================

Diff Detail

Event Timeline

djtodoro created this revision.Aug 1 2019, 9:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2019, 9:07 AM

As David said, this does look like it could fit into dwarfdump --statistics (tools/llvm-dwarfdump/Statistics.cpp).

@aprantl Thanks for your comment. WDYT about implementing this as a llvm-dwarfdump subtool?

I think that having a tool where we can add options to operate and output a verbose info on the debug location generated would be useful. As I said on the mailing list, not only reporting the results by ignoring some kind of debug location entry (inlined or entry values) is interested. Interested will be calculating what is the number of entry values that have corresponding call_site_param info, and calculate a new kind of stats (such as valuable entry values) and that is some kind of evaluation of the debug location generated. We can add more options that evaluate some other interesting things regarding the debug location, not only regarding the debug entry values feature. I agree that every single functionality I described can be embedded into the llvm-dwarfdump, but maybe the subtool can be a better solution.

MaskRay added inline comments.Aug 4 2019, 11:45 PM
llvm/tools/llvm-locstats/llvm-locstats.cpp
29

largest category -> number of categories

32

constexpr?

44

list<std::string>?

116

Place if inside LLVM_DEBUG otherwise gcc -Wall warns [-Wunused-variable]

120

[&](StringRef D)

123

clang-format this line

125

Delete IsEntryVal

138

if (auto FormValue = ...)

145

auto -> DWARFDebugLoc::Entry

147

IsEntryValue(Entry.Loc)

(I just changed the type of Loc to SmallString.)

183

++CumulNumOfVars;

228

auto -> DWARFAddressRange

243

for (DWARFDie Child : Die)

264

formatv(" {0,8} {1,8}", ..., ...) might be clearer

294

std::vector<int> LocStatistics(largest_cov_category, 0);

317

This function is also a candidate for inlining.

328

Can this function be inlined? (only called once)

331

Indent this line

334

*Buffer -> **BuffOrErr and delete Buffer.

358

Ideally these switches can be ORed together.

372

Trailing space.

@MaskRay Thanks for your review! We are still discussing on the llvm-dev mailing list how we should continue with this. As soon as we finished, I will start cleaning up the code and addressing comments.

@aprantl, @vsk,
IIUC, I can abandon this patch and make a separate patch(es) for adding additional fields into the llvm-dwarfdump stats output, and then make a script (and put into the utils/) parsing the fields by doing the locstats job?

vsk added a comment.Aug 7 2019, 10:53 AM

@aprantl, @vsk,
IIUC, I can abandon this patch and make a separate patch(es) for adding additional fields into the llvm-dwarfdump stats output, and then make a script (and put into the utils/) parsing the fields by doing the locstats job?

+ 1, I think that would be great.

djtodoro abandoned this revision.Aug 21 2019, 4:55 AM

I am abandoning this and creating new revisions for the tool implemented as an utility (within utils/).

(back in the office now, sorry for the late response)

ikudrin removed a subscriber: ikudrin.