This is an archive of the discontinued LLVM Phabricator instance.

LNT: Fix Perf profiling support
ClosedPublic

Authored by tnfchris on Dec 11 2020, 6:02 AM.

Details

Reviewers
thopre
Summary

In Python3 the C interface has changed. [1]

During the upgrade the Creation of the perf
interface was upgraded to Python3 but the initialization
itself was not. As a consequence the module was not actually
registered and trying to use perf results in an error.

This would not be noticed as the import in the Python module
has the import in a try: .. except: pass block presumably
because perf support is optional.

[1] http://python3porting.com/cextensions.html

Diff Detail

Event Timeline

tnfchris requested review of this revision.Dec 11 2020, 6:02 AM
tnfchris created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 11 2020, 6:02 AM
thopre added inline comments.Dec 11 2020, 6:46 AM
lnt/testing/profile/perf.py
15

Why did Python2 not require this? Is there some sort of module path set somewhere that does not work for Python3?

tnfchris added inline comments.Dec 11 2020, 6:48 AM
lnt/testing/profile/perf.py
15

from what I understood, C Python code will be created in the same folder as it's defined in and those folder become the module path.
I don't know the semantics of Python 2 as I didn't look at it, but 3 would require the full path or module path set somewhere.

I had looked through the configuration and this was not set anywhere so I opted for using the full import.

thopre added inline comments.Dec 11 2020, 6:52 AM
lnt/testing/profile/perf.py
15

Oh I think it's because Python2 defaults to relative import before full import. I would therefore suggest to use instead:

from . import cPerf

tnfchris added inline comments.Dec 11 2020, 8:24 AM
lnt/testing/profile/perf.py
15

fancy.. didn't know that, thanks.

thopre added inline comments.Dec 11 2020, 8:27 AM
lnt/testing/profile/perf.py
15

FYI: https://docs.python.org/3/reference/import.html#package-relative-imports

There's a PEP somewhere with more details, couldn't find the link in less than 10s so I got lazy.

tnfchris updated this revision to Diff 311234.Dec 11 2020, 8:32 AM

use package relative import syntax

thopre added inline comments.Dec 11 2020, 8:35 AM
lnt/testing/profile/perf.py
10–17

Sorry I forgot to mention that the relative import syntax is available in Python 2.7. So you can just change the import cPerf into from . import cPerf and nothing else (i.e. 1 line change)

tnfchris updated this revision to Diff 311245.Dec 11 2020, 9:03 AM
thopre accepted this revision.Dec 11 2020, 10:17 AM

LGTM

This revision is now accepted and ready to land.Dec 11 2020, 10:17 AM
tnfchris closed this revision.Dec 13 2020, 6:19 AM