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): optimize sinsp_split, modify set_env/args #1962

Merged
merged 1 commit into from
Jul 23, 2024

Conversation

LucaGuerra
Copy link
Contributor

@LucaGuerra LucaGuerra commented Jul 17, 2024

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind cleanup

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area libsinsp

Does this PR require a change in the driver versions?

No

What this PR does / why we need it:

  • Optimize sinsp_split by not using a string stream and getline but a simple loop insteadl.
  • Simplify it and remove an exception that may or may not be thrown
  • Handle both null and non-null terminated cases depending on the code path

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

fix(libsinsp): simplify sinsp_split, modify set_env/args

@LucaGuerra
Copy link
Contributor Author

LucaGuerra commented Jul 22, 2024

re-read my PR, added a couple notes to check

/hold

@LucaGuerra
Copy link
Contributor Author

/milestone 0.18.0

@poiana poiana added this to the 0.18.0 milestone Jul 22, 2024
@LucaGuerra
Copy link
Contributor Author

/unhold

I think this one is ready.

Copy link

Perf diff from master - unit tests

     4.04%     +0.93%  [.] sinsp_evt::load_params
     0.49%     +0.82%  [.] sinsp_parser::event_cleanup
     1.26%     +0.79%  [.] std::_Hashtable<long, std::pair<long const, std::shared_ptr<sinsp_threadinfo> >, std::allocator<std::pair<long const, std::shared_ptr<sinsp_threadinfo> > >, std::__detail::_Select1st, std::equal_to<long>, std::hash<long>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_M_find_before_node
     0.22%     +0.77%  [.] sinsp_evt::is_filtered_out
     1.80%     -0.73%  [.] libsinsp::events::is_unknown_event
     7.75%     -0.69%  [.] sinsp::next
     1.20%     -0.59%  [.] sinsp_evt::get_direction
     5.03%     +0.59%  [.] sinsp_evt::get_type
     1.64%     -0.58%  [.] sinsp::fetch_next_event
    10.71%     -0.55%  [.] sinsp_parser::reset

Perf diff from master - scap file

    27.09%     -3.43%  [.] sinsp_evt_formatter::tostring_withformat
     6.77%     -2.29%  [.] sinsp_filter_check::get_field_info
     6.06%     -2.15%  [.] libsinsp::runc::match_container_id
    16.96%     -1.83%  [.] sinsp_filter_check::extract_nocache
     2.92%     +1.59%  [.] std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char const*>
     3.38%     +1.33%  [.] next
     3.37%     +1.29%  [.] std::_Hashtable<long, std::pair<long const, std::shared_ptr<sinsp_threadinfo> >, std::allocator<std::pair<long const, std::shared_ptr<sinsp_threadinfo> > >, std::__detail::_Select1st, std::equal_to<long>, std::hash<long>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_M_find_before_node
     3.39%     +1.15%  [.] 0x00000000000a7fe0
     6.77%     +0.94%  [.] sinsp_parser::reset
     3.37%     -0.37%  [.] sinsp_thread_manager::find_thread

Heap diff from master - unit tests

total runtime: -0.05s.
calls to allocation functions: 35550 (-683653/s)
temporary memory allocations: 98 (-1884/s)
peak heap memory consumption: 430B
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Heap diff from master - scap file

total runtime: 0.03s.
calls to allocation functions: 1906 (73307/s)
temporary memory allocations: 0 (0/s)
peak heap memory consumption: -160B
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

@LucaGuerra LucaGuerra changed the title fix(libsinsp): simplify sinsp_split, modify set_env/args fix(libsinsp): optimize sinsp_split, modify set_env/args Jul 22, 2024
Copy link

codecov bot commented Jul 22, 2024

Codecov Report

Attention: Patch coverage is 55.55556% with 32 lines in your changes missing coverage. Please review.

Project coverage is 50.98%. Comparing base (81f451e) to head (8c79e01).
Report is 1 commits behind head on master.

Files Patch % Lines
userspace/libsinsp/test/sinsp_utils.ut.cpp 44.89% 0 Missing and 27 partials ⚠️
userspace/libsinsp/threadinfo.cpp 66.66% 0 Missing and 3 partials ⚠️
userspace/libsinsp/event.h 75.00% 0 Missing and 1 partial ⚠️
userspace/libsinsp/utils.cpp 90.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1962      +/-   ##
==========================================
- Coverage   51.00%   50.98%   -0.02%     
==========================================
  Files         310      310              
  Lines       39570    39612      +42     
  Branches    17533    17629      +96     
==========================================
+ Hits        20184    20198      +14     
- Misses      14331    14362      +31     
+ Partials     5055     5052       -3     

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

Copy link

Perf diff from master - unit tests

     1.26%     +1.35%  [.] std::_Hashtable<long, std::pair<long const, std::shared_ptr<sinsp_threadinfo> >, std::allocator<std::pair<long const, std::shared_ptr<sinsp_threadinfo> > >, std::__detail::_Select1st, std::equal_to<long>, std::hash<long>, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<false, false, true> >::_M_find_before_node
    10.71%     -0.95%  [.] sinsp_parser::reset
     4.75%     -0.84%  [.] sinsp_parser::process_event
     3.54%     +0.79%  [.] std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release
     3.55%     +0.65%  [.] gzfile_read
     1.20%     -0.64%  [.] sinsp_evt::get_direction
     4.04%     +0.58%  [.] sinsp_evt::load_params
     0.11%     +0.56%  [.] sinsp_split[abi:cxx11]
     0.49%     +0.47%  [.] sinsp_parser::event_cleanup
     0.77%     +0.46%  [.] sinsp_threadinfo::~sinsp_threadinfo

Perf diff from master - scap file

    26.09%     -9.83%  [.] sinsp_evt_formatter::tostring_withformat
     2.82%     +2.79%  [.] std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char const*>
     3.27%     +2.66%  [.] sinsp_filter_check::tostring
     6.54%     -2.48%  [.] libsinsp::sinsp_suppress::process_event
     6.53%     -2.46%  [.] strcpy_sanitized
     6.52%     -2.44%  [.] sinsp_filter_check::get_field_info
     3.27%     +2.37%  [.] gzfile_read
    16.33%     -2.20%  [.] sinsp_filter_check::extract_nocache
     5.84%     -2.03%  [.] libsinsp::runc::match_container_id
     3.21%     +1.17%  [.] rawstring_check::extract_single

Heap diff from master - unit tests

total runtime: 0.03s.
calls to allocation functions: 36114 (1444560/s)
temporary memory allocations: 340 (13600/s)
peak heap memory consumption: 430B
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Heap diff from master - scap file

total runtime: 0.02s.
calls to allocation functions: 1906 (90761/s)
temporary memory allocations: 1 (47/s)
peak heap memory consumption: -160B
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

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 Jul 23, 2024

LGTM label has been added.

Git tree hash: 01e8c7eebed692a6d14714fd6fc2de3e9b56cc90

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
Copy link
Contributor

poiana commented Jul 23, 2024

[APPROVALNOTIFIER] This PR is APPROVED

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

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,LucaGuerra]

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

@poiana poiana merged commit 5c80f0e into falcosecurity:master Jul 23, 2024
46 checks passed
@LucaGuerra LucaGuerra deleted the fix/simplify-sinsp-split branch July 30, 2024 08:04
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