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

fix python3 py_test_histogram failure #1686

Merged
merged 1 commit into from
Apr 17, 2018
Merged

fix python3 py_test_histogram failure #1686

merged 1 commit into from
Apr 17, 2018

Conversation

yonghong-song
Copy link
Collaborator

With python3 (specifically 3.6.3), py_test_histogram failed with:
Traceback (most recent call last):
File "./test_histogram.py", line 106, in test_multiple_key
bucket_sort_fn=bucket_sort)
File "/usr/lib/python3.6/site-packages/bcc/table.py", line 318, in print_log2_hist
buckets = bucket_sort_fn(buckets)
File "./test_histogram.py", line 98, in bucket_sort
buckets.sort()
AttributeError: 'dict_keys' object has no attribute 'sort'

The reason is for a dictionary tmp, tmp.keys() returns an object
of keys (a list) instead of the list itself for python3.
Using list(tmp.keys()) seems working for both python2 and python3.

Signed-off-by: Yonghong Song [email protected]

@goldshtn
Copy link
Collaborator

goldshtn commented Apr 16, 2018 via email

@yonghong-song
Copy link
Collaborator Author

The test failure is fc27,

3: -------------------------------------------------------------------------------
3: test attach perf event
3: -------------------------------------------------------------------------------
3: /home/fedora/jenkins/workspace/bcc-pr/label/fc27/tests/cc/test_perf_event.cc:90
3: ...............................................................................
3: 
3: /home/fedora/jenkins/workspace/bcc-pr/label/fc27/tests/cc/test_perf_event.cc:134: FAILED:
3:   REQUIRE( counter.enabled >= 1000000000 )
3: with expansion:
3:   999605995 (0x3b94c6eb)
3:   >=
3:   1000000000 (0x3b9aca00)
3: 

The source code is

127 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
128   auto counter_table =
129       bpf.get_hash_table<int, struct bpf_perf_event_value>("counter");
130   auto counter = counter_table[0];
131   auto ret = bpf.get_hash_table<int, int>("ret");
132   REQUIRE(ret[0] == 0);
133   REQUIRE(counter.counter >= 0);
134   REQUIRE(counter.enabled >= 1000000000);
135   REQUIRE(counter.running >= 0);
136   REQUIRE(counter.running <= counter.enabled);
137 #endif

The test is only enabled for 4.15 and later, probably newer fc27.
The code to attach and detach perf event:

116   res = bpf.attach_perf_event(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK,
117                               "on_event", 0, 1000);
118   REQUIRE(res.code() == 0);
119   sleep(1);
120   res = bpf.detach_perf_event(PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK);
121   REQUIRE(res.code() == 0);

For the failure below,

134   REQUIRE(counter.enabled >= 1000000000);

The VM counter read is slightly less

3:   999605995 (0x3b94c6eb)

It is possible that this is related to VM setup and how perf works for SW_CPU_CLOCK.
Will do an experiment separately.

Rerun the test for this patch.

@yonghong-song
Copy link
Collaborator Author

[buildbot, ok to test]

With python3 (specifically 3.6.3), py_test_histogram failed with:
  Traceback (most recent call last):
  File "./test_histogram.py", line 106, in test_multiple_key
    bucket_sort_fn=bucket_sort)
  File "/usr/lib/python3.6/site-packages/bcc/table.py", line 318, in print_log2_hist
    buckets = bucket_sort_fn(buckets)
  File "./test_histogram.py", line 98, in bucket_sort
    buckets.sort()
  AttributeError: 'dict_keys' object has no attribute 'sort'

The reason is for a dictionary tmp, tmp.keys() returns an object
of keys (a list) instead of the list itself for python3.
Using list(tmp.keys()) seems working for both python2 and python3.

Signed-off-by: Yonghong Song <[email protected]>
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

Successfully merging this pull request may close these issues.

3 participants