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(libsinsp/state): ensure deep copy semantics and proper memory ownership in dynamic structs #2026

Merged
merged 1 commit into from
Aug 28, 2024

Conversation

jasondellaluce
Copy link
Contributor

What type of PR is this?

/kind bug

Any specific area of the project related to this PR?

/area libsinsp

/area tests

Does this PR require a change in the driver versions?

What this PR does / why we need it:

With some random tests I figured that dynamic structs implemented shallow copy semantics, whereas the intended behavior was deep copy of the allocated values. For example, storing a dynamic field in the file descriptor subtable would end up having lost information when cloning file descriptor infos during the parsing phase of fork-family syscalls.

Tests have been added.

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

fix(libsinsp/state): ensure deep copy semantics and proper memory ownership in dynamic structs

…ership in dynamic structs

Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
Copy link

Perf diff from master - unit tests

     9.06%     +2.02%  [.] sinsp_parser::reset
     6.52%     -1.35%  [.] next
     3.05%     +0.93%  [.] gzfile_read
     3.09%     +0.68%  [.] sinsp_thread_manager::get_thread_ref
     1.58%     +0.67%  [.] sinsp::fetch_next_event
     4.67%     -0.67%  [.] sinsp_parser::process_event
     0.98%     -0.59%  [.] libsinsp::runc::match_container_id
     0.65%     +0.54%  [.] std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*>
     1.95%     -0.50%  [.] sinsp_evt::get_ts
     1.09%     -0.46%  [.] sinsp_filter_check::parse_field_name

Heap diff from master - unit tests

peak heap memory consumption: 79.66K
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Heap diff from master - scap file

peak heap memory consumption: 8.26K
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Benchmarks diff from master

Comparing gbench_data.json to /root/actions-runner/_work/libs/libs/build/gbench_data.json
Benchmark                                                         Time             CPU      Time Old      Time New       CPU Old       CPU New
----------------------------------------------------------------------------------------------------------------------------------------------
BM_sinsp_split_mean                                            -0.0108         -0.0106           149           147           149           147
BM_sinsp_split_median                                          -0.0132         -0.0129           149           147           149           147
BM_sinsp_split_stddev                                          +0.6815         +0.6995             0             1             0             1
BM_sinsp_split_cv                                              +0.6999         +0.7178             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_mean                  +0.0000         +0.0003            42            42            42            42
BM_sinsp_concatenate_paths_relative_path_median                +0.0064         +0.0066            42            42            42            42
BM_sinsp_concatenate_paths_relative_path_stddev                -0.7313         -0.7309             1             0             1             0
BM_sinsp_concatenate_paths_relative_path_cv                    -0.7313         -0.7310             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_mean                     +0.0266         +0.0268            17            17            17            17
BM_sinsp_concatenate_paths_empty_path_median                   +0.0433         +0.0434            17            18            17            18
BM_sinsp_concatenate_paths_empty_path_stddev                   +0.9506         +0.9552             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_cv                       +0.9000         +0.9042             0             0             0             0
BM_sinsp_concatenate_paths_absolute_path_mean                  -0.1294         -0.1292            49            43            49            43
BM_sinsp_concatenate_paths_absolute_path_median                -0.1292         -0.1290            50            43            50            43
BM_sinsp_concatenate_paths_absolute_path_stddev                -0.2540         -0.2573             0             0             0             0
BM_sinsp_concatenate_paths_absolute_path_cv                    -0.1432         -0.1471             0             0             0             0
BM_sinsp_split_container_image_mean                            -0.0048         -0.0047           354           353           354           353
BM_sinsp_split_container_image_median                          -0.0032         -0.0032           354           353           354           353
BM_sinsp_split_container_image_stddev                          -0.1519         -0.1470             2             2             2             2
BM_sinsp_split_container_image_cv                              -0.1477         -0.1430             0             0             0             0

Copy link

codecov bot commented Aug 27, 2024

Codecov Report

Attention: Patch coverage is 97.56098% with 2 lines in your changes missing coverage. Please review.

Project coverage is 74.26%. Comparing base (89edd36) to head (c1e16b2).
Report is 1 commits behind head on master.

Files Patch % Lines
userspace/libsinsp/state/table_adapters.h 0.00% 1 Missing ⚠️
userspace/libsinsp/test/state.ut.cpp 98.18% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2026      +/-   ##
==========================================
+ Coverage   74.20%   74.26%   +0.05%     
==========================================
  Files         253      253              
  Lines       30832    30903      +71     
  Branches     5394     5414      +20     
==========================================
+ Hits        22880    22949      +69     
- Misses       7934     7949      +15     
+ Partials       18        5      -13     
Flag Coverage Δ
libsinsp 74.26% <97.56%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@FedeDP
Copy link
Contributor

FedeDP commented Aug 28, 2024

/milestone 0.18.0

@poiana poiana added this to the 0.18.0 milestone Aug 28, 2024
Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@poiana
Copy link
Contributor

poiana commented Aug 28, 2024

LGTM label has been added.

Git tree hash: d8532ed2b1c8a0bbcb74a4636189aef8eba910fc

Copy link
Member

@Andreagit97 Andreagit97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@poiana poiana merged commit db631fa into master Aug 28, 2024
45 of 46 checks passed
@poiana
Copy link
Contributor

poiana commented Aug 28, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Andreagit97, FedeDP, jasondellaluce

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [Andreagit97,FedeDP,jasondellaluce]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@poiana poiana deleted the fix/dynamic-struct-mem-ownership-copy branch August 28, 2024 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants