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

Incorrect result #48

Open
eldar-mustafayev opened this issue Oct 4, 2021 · 6 comments
Open

Incorrect result #48

eldar-mustafayev opened this issue Oct 4, 2021 · 6 comments

Comments

@eldar-mustafayev
Copy link
Contributor

The bug
In the function below the plugin calculated that memory usage is less than one MB. However, when I print the actual size of the array it is between 7 and 8 MB. I assume it is related to the memory_profiler, because I experienced similar result when using it.

def test_extension():
    ROWS = 1000000000
    data = np.empty(ROWS)
    with open('temp.txt', 'w') as out:
        out.write(str(sys.getsizeof(data)))

    assert True

Desktop:

  • OS: Fedora 34
  • pytest-monitor: 1.6.2
  • pytest: 6.2.5
  • python: 3.8.6
  • numpy: 1.21.2
@js-dieu
Copy link
Collaborator

js-dieu commented Oct 5, 2021

Hello @eldar-mustafayev

Thanks for reporting :) The plugin reports memory used in MB.
I just tried it with your snippet (thanks for providing it btw!)

Here are the results:

bash $> sqlite3 .pymon
sqlite> select TOTAL_TIME, USER_TIME, KERNEL_TIME, MEM_USAGE, CPU_USAGE, ITEM, ITEM_PATH  from TEST_METRICS where ITEM_PATH = 'pkg1.test_mb';
TOTAL_TIME|USER_TIME|KERNEL_TIME|MEM_USAGE|CPU_USAGE|ITEM|ITEM_PATH
0.00799322128295898|0.018202272|0.004366944|13.4453125|2.82354450115326|test_extension|pkg1.test_mb

As you can see, your function consumes 13MB. This includes: namespaces, imports and datas.
I think you just got confused with the unit size for memory report.

I let you close, unless I misunderstood your problem or something else lies beneath this issue :)

@eldar-mustafayev
Copy link
Contributor Author

Hi @js-dieu. Thanks for the reply. Actually it's quite interesting, because I am still getting a result lower than 1 MB. What do you think about that? What am I doing wrong?

(venv) [root@vultr ~]# sqlite3 .test
SQLite version 3.36.0 2021-06-18 18:36:39
Enter ".help" for usage hints.
sqlite> select TOTAL_TIME, USER_TIME, KERNEL_TIME, MEM_USAGE, CPU_USAGE, ITEM, ITEM_PATH  from TEST_METRICS where ITEM_PATH = 'pkg1.test_mb';
0.209692239761353|0.16|0.02|0.53125|0.858400865024167|test_extension|pkg1.test_mb

@js-dieu
Copy link
Collaborator

js-dieu commented Oct 6, 2021

Hello @eldar-mustafayev

Something lies in your environment and yet ... it remains unexplained :)
Can you print the output of the following lines (in the environment you use to obtain such results!)

import numpy as np
np.show_config()

Also, if you can make a strace of the pytest run (with only that test) it would be for sure usefull...

@eldar-mustafayev
Copy link
Contributor Author

eldar-mustafayev commented Oct 7, 2021

Hello @js-dieu . Thanks for help, I printed logs you asked for. Hope, this will be helpful. :)

Pytest trace:

(venv) [root@vultr ~]# export PYTHONPATH="$(pwd)/module" && pytest module/pkg1/test_mb.py --db .test
============================= test session starts ==============================
platform linux -- Python 3.8.6, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: /root/project, configfile: pyproject.toml
plugins: xdist-2.3.0, typeguard-2.12.1, asyncio-0.15.1, forked-1.3.0, monitor-1.6.2, parallel-0.1.0, json-report-1.2.4, cov-2.11.0, metadata-1.11.0
collected 1 item

module/pkg1/test_mb.py  .                                    [100%]

Numpy configs:

blas_info:
    libraries = ['cblas', 'blas', 'cblas', 'blas']
    library_dirs = ['/root/miniconda3/envs/venv/lib']
    include_dirs = ['/root/miniconda3/envs/venv/include']
    language = c
    define_macros = [('HAVE_CBLAS', None)]
blas_opt_info:
    define_macros = [('NO_ATLAS_INFO', 1), ('HAVE_CBLAS', None)]
    libraries = ['cblas', 'blas', 'cblas', 'blas']
    library_dirs = ['/root/miniconda3/envs/venv/lib']
    include_dirs = ['/root/miniconda3/envs/venv/include']
    language = c
lapack_info:
    libraries = ['lapack', 'blas', 'lapack', 'blas']
    library_dirs = ['/root/miniconda3/envs/venv/lib']
    language = f77
lapack_opt_info:
    libraries = ['lapack', 'blas', 'lapack', 'blas', 'cblas', 'blas', 'cblas', 'blas']
    library_dirs = ['/root/miniconda3/envs/venv/lib']
    language = c
    define_macros = [('NO_ATLAS_INFO', 1), ('HAVE_CBLAS', None)]
    include_dirs = ['/root/miniconda3/envs/venv/include']
Supported SIMD extensions in this NumPy install:
    baseline = SSE,SSE2,SSE3
    found = SSSE3,SSE41,POPCNT,SSE42,AVX,F16C,FMA3,AVX2,AVX512F,AVX512CD,AVX512_SKX
    not found = AVX512_KNL,AVX512_KNM,AVX512_CLX,AVX512_CNL,AVX512_ICL

@js-dieu
Copy link
Collaborator

js-dieu commented Oct 8, 2021

Thanks for reporting @eldar-mustafayev

However, I was refering to strace program which can trace all sys calls from an executable, not the log of pytest. Can you do the necessary ?

@eldar-mustafayev
Copy link
Contributor Author

Sorry for late response. I hope this will help to identify the problem:
trace.txt

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