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

slow get_cpu_info w/o pyinstaller #134

Open
FabioLuporini opened this issue Aug 28, 2019 · 8 comments
Open

slow get_cpu_info w/o pyinstaller #134

FabioLuporini opened this issue Aug 28, 2019 · 8 comments

Comments

@FabioLuporini
Copy link

FabioLuporini commented Aug 28, 2019

  • OS: various mac os's and ubuntu's
  • archs: various intel xeons
  • P3.6, P3.7
  • py-cpuinfo v5.0.0

Hi,

It takes more than a second for get_cpu_info to return w/o pyinstaller. See also here

I haven't profiled the code, but if I bypass that else calling _get_cpu_info_internal directly, it runs much quicker (in at most tens of ms).

I wonder whether we can improve this, at least on Linux/Darwin, where I seem to understand we could skip that else ? Would you accept a tiny patch that reads the OS name such that the if is entered if on Linux/Darwin ?

@workhorsy
Copy link
Owner

This sounds like a good thing to try. Other platforms shouldn't have to be penalized because of design flaws in Windows (not having proper forking). I'm open to you making a PR for it.

Thanks

@FabioLuporini
Copy link
Author

Turns out I was wrong and this:

I haven't profiled the code, but if I bypass that else calling _get_cpu_info_internal directly, it runs much quicker (in at most tens of ms).

is not the culprit

this function seems the one to be causing the slow down. What confused me originally is the fact that this slow down occurs non-deterministically. BTW, I reproduced it on multiple machines and OSs, including MacOS and Ubuntu.

Now, I've been using 5.0.0, but it seems that master is a bit ahead, so I'm not sure if the issue is still there with latest py-cpuinfo, but I wouldn't see why not after glancing at the code

I don't know what's the best course of action at this point. I'll try to dig a bit more if I find the time later in these days.

@workhorsy
Copy link
Owner

That is okay. Thanks anyway. Maybe you or someone will figure it out later.

BTW. The _get_cpu_info_from_cpuid function spawns a new process and runs the _get_cpu_info_from_cpuid_actual function inside it, then returns the result. This is done because running bytecode on the CPU could crash the whole Python process. The overhead may be from spawning a new process or from inter process communication. I'm not sure though. I don't have the time to do a proper test.

@FabioLuporini
Copy link
Author

FabioLuporini commented Sep 10, 2019

cpuinfo_v2.pdf

maybe this could help?

@FabioLuporini
Copy link
Author

FabioLuporini commented Sep 10, 2019

anyway, let me ask a question: I pretty much only need flags and brand. Do you think I could bypass some of the calls performed by get_cpu_info by directly using one of the private routines ?

@workhorsy
Copy link
Owner

Wow. What did you use to make that PDF?

@workhorsy
Copy link
Owner

You can call the internal functions directly. But it isn't recommended, because the internal functions are not API stable and may change in the future.

from cpuinfo import *

info = cpuinfo._get_cpu_info_from_registry()
print(info)

Other ones are

# Try the Windows wmic
_get_cpu_info_from_wmic()

# Try the Windows registry
_get_cpu_info_from_registry()

# Try /proc/cpuinfo
_get_cpu_info_from_proc_cpuinfo()

# Try cpufreq-info
_get_cpu_info_from_cpufreq_info()

# Try LSCPU
_get_cpu_info_from_lscpu()

# Try sysctl
_get_cpu_info_from_sysctl()

# Try kstat
_get_cpu_info_from_kstat()

# Try dmesg
_get_cpu_info_from_dmesg()

# Try /var/run/dmesg.boot
_get_cpu_info_from_cat_var_run_dmesg_boot()

# Try lsprop ibm,pa-features
_get_cpu_info_from_ibm_pa_features()

# Try sysinfo
_get_cpu_info_from_sysinfo()

@FabioLuporini
Copy link
Author

FabioLuporini commented Sep 16, 2019

Wow. What did you use to make that PDF?

Hi! I used Python's CProfile for data collection and gprof2dot to create the pdf. Here's a summary.

You can call the internal functions directly. But it isn't recommended, because the internal functions are not API stable and may change in the future.

yeah, that's why I was a bit hesitant to do it...

BTW, let me add an extra piece to the puzzle: not only is the slow-down not deterministic, but also the output -- the returned dictionary containing the platform information -- may differ from run to run. I recently noticed that some entries may be missing. To reproduce, but you can try running get_cpu_info() a few times on linux and you should be able to see it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants