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

feat(crit): add SearchPattern method on MemoryReader #163

Merged
merged 2 commits into from
Jul 28, 2024

Conversation

behouba
Copy link
Contributor

@behouba behouba commented Mar 6, 2024

I am currently working on a feature to allow users to search for a pattern within process memory pages, as suggested by @rst0git last year. This could be used to extend checkpointctl memparse with search capability.

Currently, the method SearchPattern(pattern string) (uint64, error) takes the pattern to search as an argument and returns the address of the first match along with an error if the pattern is not found. I am not sure about the implementation yet, and I'm considering alternative approaches:

  • Instead of providing just the address of the first match, should we consider returning the entire memory pages where the pattern is found?

  • Another consideration is whether to return not just the first match but all occurrences of the pattern.

@rst0git, @adrianreber , @snprajwal PTAL.

Copy link

codecov bot commented Mar 6, 2024

Codecov Report

Attention: Patch coverage is 84.00000% with 8 lines in your changes missing coverage. Please review.

Project coverage is 50.82%. Comparing base (ce0a56d) to head (20dfec8).
Report is 5 commits behind head on master.

Files Patch % Lines
crit/mempages.go 84.00% 5 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #163      +/-   ##
==========================================
+ Coverage   48.13%   50.82%   +2.68%     
==========================================
  Files          21       21              
  Lines        2279     1948     -331     
==========================================
- Hits         1097      990     -107     
+ Misses       1050      819     -231     
- Partials      132      139       +7     

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

crit/mempages.go Outdated Show resolved Hide resolved
@adrianreber
Copy link
Member

Another consideration is whether to return not just the first match but all occurrences of the pattern.

That would kind of match the behaviour of grep. That is also what I would expect when searching for a pattern.

Instead of providing just the address of the first match, should we consider returning the entire memory pages where the pattern is found?

Maybe not as default, but with an additional option. Maybe like the context option from grep. Where you can say how many lines before and after the match. A whole page on the terminal sounds a lot, so if you let the user select how many bytes to show, that sounds like a useful option to me.

@behouba behouba force-pushed the search-memory-pages branch 3 times, most recently from 2ae58cb to bdf1795 Compare March 11, 2024 22:25
@rst0git rst0git mentioned this pull request Mar 14, 2024
@behouba behouba force-pushed the search-memory-pages branch 5 times, most recently from 3fac1c7 to 4fc6dbc Compare March 17, 2024 04:32
@behouba
Copy link
Contributor Author

behouba commented Mar 17, 2024

I have updated the SearchPattern method. Now, the function takes both the pattern and a context (specified by the number of bytes before and after the pattern). I opted for byte counts instead of line counts, considering the content of pages-*.img files, which doesn't neatly correspond to lines.
Also, the function now returns a slice of strings representing all occurrences of the pattern found in memory.

cc: @adrianreber , @rst0git , @snprajwal

crit/mempages.go Outdated Show resolved Hide resolved
crit/mempages.go Outdated Show resolved Hide resolved
@behouba behouba marked this pull request as ready for review March 17, 2024 22:55
crit/mempages.go Outdated Show resolved Hide resolved
@snprajwal
Copy link
Member

@behouba dropping a note to check if you're still working on this :)

@behouba
Copy link
Contributor Author

behouba commented Jul 15, 2024

@behouba dropping a note to check if you're still working on this :)

Hi @snprajwal! Yes, I am still working on it :)
I will soon open a draft PR on checkpointctl so we can assess the potential performance issues with the current implementation.

crit/mempages.go Outdated Show resolved Hide resolved
crit/mempages.go Outdated Show resolved Hide resolved
@behouba behouba force-pushed the search-memory-pages branch 3 times, most recently from 6b29382 to fdc9e7d Compare July 22, 2024 00:58
crit/mempages.go Outdated Show resolved Hide resolved
crit/mempages.go Outdated Show resolved Hide resolved
Copy link
Member

@snprajwal snprajwal left a comment

Choose a reason for hiding this comment

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

LGTM

@rst0git
Copy link
Member

rst0git commented Jul 25, 2024

@behouba Thank you for working on this feature and updating the pull request!
Would it be possible to apply the recent changes in the PR for checkpointctl to test it before we merge this pull request?

This commit adds a new method `SearchPattern` to `MemoryReader` to search
for patterns inside the process memory pages. This method accept regular
expressions for flexible pattern matching, a context (number of bytes
before and after the pattern match), and a size of memory chunk to be
read at a time.

Signed-off-by: Kouame Behouba Manasse <[email protected]>
Copy link
Member

@rst0git rst0git left a comment

Choose a reason for hiding this comment

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

LGTM

@rst0git rst0git merged commit a9064d7 into checkpoint-restore:master Jul 28, 2024
15 checks passed
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.

4 participants