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

Optimistically read from /proc for process stats. #3374

Merged
merged 1 commit into from
Jun 11, 2024

Conversation

aee-google
Copy link
Contributor

b/341774149

@aee-google aee-google requested a review from jellefoks May 29, 2024 23:10
@aee-google
Copy link
Contributor Author

Remaining:

  • Find place to call ProcessMetricsHelper::PopulateClockTicksPerS()
  • Collect CPU usage over a time interval (preset intervals like 30s, 2s)
  • Use CVal to expose CPU usage stats to JavaScript

@aee-google aee-google enabled auto-merge (squash) June 3, 2024 15:58
@aee-google aee-google force-pushed the cpu-metric branch 3 times, most recently from 5cca730 to 194f29a Compare June 4, 2024 22:54
auto-merge was automatically disabled June 5, 2024 18:50

Pull Request is not mergeable

@aee-google aee-google force-pushed the cpu-metric branch 2 times, most recently from 6329fab to d27d65d Compare June 5, 2024 23:29
@aee-google aee-google enabled auto-merge (squash) June 6, 2024 17:51
starboard/shared/win32/test_filters.py Show resolved Hide resolved
cobalt/base/process/process_metrics_helper_test.cc Outdated Show resolved Hide resolved
base/process/internal_linux.cc Show resolved Hide resolved
if (open_parens_idx == std::string::npos ||
close_parens_idx == std::string::npos ||
open_parens_idx > close_parens_idx) {
size_t pid_end = stats_data.find(" (");
Copy link
Member

Choose a reason for hiding this comment

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

Is the existing logic broken in upstream, or is it not a "hard broken" and its just that the upstream returns the thread name with the parentheses and you changed that for us to leave those out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The pid has an extra space at the end. Everything else is parsed correctly.

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better to keep variable names the same where possible and keep our changes in STARBOARD/USE_COBALT_CUSTOMIZATIONS blocks, the only thing I see changing is comm_start

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need the start and end positions for pid and comm, and we need the start position for state.

open_parens_idx was the first occurrence of " (. This is the pid end. pid start position is 0. open_parens_idx is incremented and the pid substring is off by 1.

Naming the positions we need avoids the modifying the value and using it to represent two different things.

stats_data.substr(start, end - start) returns the value we want.

After the last ") ", the rest of the fields are space delimited.

If I wanted to leave the code mostly the same, I would need to either move the open_parens_idx++ after getting the pid or removing the increment and fix how comm is retrieved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another option is to parse the /proc/pid/stat in cobalt/base/process/process_metrics_helper.cc.

Copy link
Contributor

Choose a reason for hiding this comment

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

Unless we upstream this code (the ideal solution) or guard it with ifdefs (an easier immediate solution), someone will eventually try to revert this back to the original code i.e. during an update as right now it looks like a mistaken diff from the upstream. Using the ifdefs we usually use makes it clear to readers that it's a conscious decision instead

Copy link
Member

@jellefoks jellefoks left a comment

Choose a reason for hiding this comment

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

Thanks for making this work. This is great!

auto-merge was automatically disabled June 11, 2024 17:03

Pull Request is not mergeable

@sherryzy sherryzy self-requested a review June 11, 2024 19:04
Copy link
Contributor

@sherryzy sherryzy left a comment

Choose a reason for hiding this comment

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

Just left a few minor comments.

base/process/internal_linux.cc Show resolved Hide resolved
base/process/internal_linux.cc Show resolved Hide resolved
Copy link
Contributor

@andrewsavage1 andrewsavage1 left a comment

Choose a reason for hiding this comment

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

Mostly looks good, just a few smaller issues

base/process/internal_linux.cc Outdated Show resolved Hide resolved
if (open_parens_idx == std::string::npos ||
close_parens_idx == std::string::npos ||
open_parens_idx > close_parens_idx) {
size_t pid_end = stats_data.find(" (");
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better to keep variable names the same where possible and keep our changes in STARBOARD/USE_COBALT_CUSTOMIZATIONS blocks, the only thing I see changing is comm_start

base/process/internal_linux.h Outdated Show resolved Hide resolved
cobalt/base/process/process_metrics_helper.cc Outdated Show resolved Hide resolved
cobalt/base/process/process_metrics_helper_test.cc Outdated Show resolved Hide resolved
cobalt/base/process/process_metrics_helper_test.cc Outdated Show resolved Hide resolved
cobalt/base/process/process_metrics_helper_test.cc Outdated Show resolved Hide resolved
cobalt/base/process/process_metrics_helper_test.cc Outdated Show resolved Hide resolved
cobalt/base/process/process_metrics_helper_test.cc Outdated Show resolved Hide resolved
@aee-google aee-google enabled auto-merge (squash) June 11, 2024 22:39
@aee-google aee-google merged commit 6424e50 into youtube:main Jun 11, 2024
317 of 318 checks passed
@aee-google aee-google deleted the cpu-metric branch June 11, 2024 22:46
oxve pushed a commit to oxve/cobalt that referenced this pull request Jun 12, 2024
borongc added a commit to borongc/cobalt that referenced this pull request Jun 13, 2024
These two tests failed due to the PR (youtube#3374), and they should be re-enabled once it fixes.

b/346868673
borongc added a commit to borongc/cobalt that referenced this pull request Jun 13, 2024
These two tests failed due to the PR (youtube#3374), and they should be re-enabled once it fixes.

b/346868673
borongc added a commit that referenced this pull request Jun 13, 2024
These two tests failed due to the PR
(#3374), and they should be
re-enabled once it fixes.

b/346868673
@aee-google aee-google added the cp-25.lts.1+ Cherry Pick to the 25.lts.1+ branch label Jun 20, 2024
cobalt-github-releaser-bot pushed a commit that referenced this pull request Jun 20, 2024
aee-google added a commit that referenced this pull request Jun 20, 2024
…s. (#3607)

Refer to the original PR: #3374

b/341774149

Co-authored-by: aee <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cp-25.lts.1+ Cherry Pick to the 25.lts.1+ branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants