This is an archive of the discontinued LLVM Phabricator instance.

[trace][intelpt] Added total memory usage by decoded trace
ClosedPublic

Authored by zrthxn on Mar 20 2022, 12:32 AM.

Details

Summary

This fails currently but the basics are there

Diff Detail

Event Timeline

zrthxn created this revision.Mar 20 2022, 12:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 20 2022, 12:32 AM
zrthxn requested review of this revision.Mar 20 2022, 12:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 20 2022, 12:32 AM
zrthxn updated this revision to Diff 416764.Mar 20 2022, 2:12 AM

Clean up, works fine now

zrthxn updated this revision to Diff 416765.Mar 20 2022, 2:17 AM

Fixed trace info test for this

wallace requested changes to this revision.Mar 20 2022, 10:47 AM

Pretty nice! just some details i've noticed when reading your diff and good to go

lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
123–128

you might be able to do something like

// As calculating the size used by error instructions is very difficult, because errors
// are dynamic objects, we just discard them from our calculations because errors
// are supposed to be rare and not really contribute much to the total memory usage.
size_t non_error_instructions = count(m_instructions.begin(), m_instructions.end(), [](const IntelPTInstruction& insn) {!insn.IsError();});

return IntelPTInstruction::GetNonErrorMemoryUsage() * non_error_instructions + GetRawTraceSize();

notice that we need the actual GetRawTraceSize() and not sizeof(m_raw_trace_size), because the latter will always give you 8 bytes on an x86_64 machine, regardless of how much data it is actually consuming.

lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
85–95

I made a mistake. I didn't notice that there's an m_error member, whose size is dynamic, because it might hold a string message.
However, the number of errors should be negligible compared to the total number of correct instructions, so, for global calculations, let's assume that all instructions are fine and they are not errors.

120
158–162

We can put all the documentation in the \return section to avoid redundancy.

Let's also use the word Calculate instead of Get because Get is supposed to be used for cheap operations and Calculate for maybe not so trivial ones.

lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
113–114

print this in KB, as it will be readability. You can assume that this number will always be an integer because the raw trace size by definition in the kernel is a multiple of 4KB.

115

better print KB instead of bytes. you can use a double with two digits of precision

This revision now requires changes to proceed.Mar 20 2022, 10:47 AM
wallace added inline comments.Mar 20 2022, 10:50 AM
lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
123–128

sorry, it should be

return IntelPTInstruction::GetNonErrorMemoryUsage() * non_error_instructions + GetRawTraceSize() + sizeof(DecodedThread);

notice the sizeof(DecodedThread) portion that accounts for the the m_thread_sp. The actual storage of the Thread * is somewhere else, and DecodedThread is just keeping a reference to it, so sizeof() is enough for this.

lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
162–165
zrthxn marked 8 inline comments as done.Mar 20 2022, 12:24 PM
zrthxn updated this revision to Diff 416797.Mar 20 2022, 12:44 PM

Changed to KiB and fixed how caclulation is done

wallace requested changes to this revision.Mar 20 2022, 5:13 PM

just some few remaining nits

lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
85
86–88

move the implementation of this this method to the corresponding cpp file. We try to keep all headers just as declarations to reduce the binary size, unless we try to achieve an optimization

119
lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
108–114

only calculate the memory usage if used, which happens after the early terminated if

118

use double instead of float. double has more precision

This revision now requires changes to proceed.Mar 20 2022, 5:13 PM
zrthxn marked 4 inline comments as done.Mar 20 2022, 11:28 PM
zrthxn added inline comments.
lldb/source/Plugins/Trace/intel-pt/TraceIntelPT.cpp
118

But since we're showing only two decimal places, which gets rounded up, the precision eventually gets thrown away... doesn't it?

zrthxn updated this revision to Diff 416825.Mar 20 2022, 11:31 PM
zrthxn marked an inline comment as done.

Cosmetic and minor changes

wallace requested changes to this revision.Mar 20 2022, 11:55 PM
wallace added inline comments.
lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
123–130

as discussed offline, this should just be

This revision now requires changes to proceed.Mar 20 2022, 11:55 PM
zrthxn updated this revision to Diff 416826.EditedMar 20 2022, 11:57 PM

Ignore errored instructions

zrthxn marked an inline comment as done.Mar 20 2022, 11:59 PM
wallace accepted this revision.Mar 21 2022, 12:01 AM

great!

This revision is now accepted and ready to land.Mar 21 2022, 12:01 AM
This revision was automatically updated to reflect the committed changes.