Skip to content

Get render process information from ICoreWebView2 object #3298

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

Open
ztextplus opened this issue Mar 13, 2023 · 14 comments
Open

Get render process information from ICoreWebView2 object #3298

ztextplus opened this issue Mar 13, 2023 · 14 comments
Assignees
Labels
feature request feature request tracked We are tracking this work internally.

Comments

@ztextplus
Copy link

ztextplus commented Mar 13, 2023

Is your feature request related to a problem? Please describe.
We have multiple features that use the browser function, and now we really want to have such a requirement.

We want to count the CPU and Memory usage of each feature, that is, count the CPU and Memory usage of a certain feature for the Render process. So I hope that Webview2 can provide an interface to get the corresponding set of Render process IDs from the ICoreWebView2 object.
If this interface is provided, the usage process is as follows:

  1. Get feature1's ICoreWebView2 object.
  2. Call API GetRenderProssesprovided by ICoreWebView2 object.
  3. Calculate the memory usage of the process returned by GetRenderProsses.

Although Webview2 provides the GetProcessInfos interface, this interface obtains all the process information related to Webview2, we still cannot know the Render process information corresponding to an ICoreWebView2.

AB#44641334

@ztextplus ztextplus added the feature request feature request label Mar 13, 2023
@aluhrs13
Copy link
Contributor

aluhrs13 commented Mar 13, 2023

@ztextplus - CoreWebView2ProcessKind is included in the result of CoreWebView2ProcessInfo for this purpose.

@novac42
Copy link
Contributor

novac42 commented Mar 14, 2023

Hi @ztextplus , does andy's reply above solve the problem? If yes can the issue be closed?

@novac42 novac42 self-assigned this Mar 14, 2023
@ztextplus
Copy link
Author

ztextplus commented Mar 14, 2023

@aluhrs13 @novac42
Sorry, I don't think my question was answered.
For example:
image
Calling GetProcessInfos I will get an array of processes with two render processes (37696 and 21020), now the problem is:
how could I know:
37696 corresponds to the render process of featrue1
21020 corresponds to the render process of featrue2
or
37696 corresponds to the render process of featrue2
21020 corresponds to the render process of featrue1

Why is there such a requirement? We want to count the memory and CPU usage of featrue1 and featrue2 respectively.
If this interface is provided:
I can obtain the render process of featrue1 through the ICoreWebView2 object of featrue1, and the render process of featrue2 through the ICoreWebView2 object of featrue2, and then count their memory usage respectively.

@aluhrs13
Copy link
Contributor

@ztextplus can you check out #3234? That is in-progress and might fit your need.

@JosephJin0815
Copy link
Contributor

JosephJin0815 commented Mar 14, 2023

Hi, @ztextplus can you explain more about feature1/feature2? Are they created from same ICoreWebView2 with child iframes? Like

[main frame 
        [child_iframe1: feature1], 
        [child_iframe2: feature2],
        [child_frame...:]
 ]

FYI, IFrameMemoryUsage API provides method to get renderer process id for each iframe/main frame.

@ztextplus
Copy link
Author

@aluhrs13 @novac42 @JosephJin0815
As shown in the figure below, I have two features, which are feature1 and feature2, and created two browsers to correspond to these two features. But in the process manager on the right, we can only know that these two features have created four render processes. Now the question is how to confirm:

Among the four render processes, which are created by the browser corresponding to feature 1 and which are created by the browser corresponding to feature 2

Using GetProcessInfos, you can get all process IDs, but you cannot get the corresponding relationship between feature1 and Render processes.

At present, the way I can think of is to kill a render. At this time, if feature1 does not display normally, I know that the render I just killed corresponds to feature1.

image

@JosephJin0815
Copy link
Contributor

JosephJin0815 commented Mar 15, 2023

I don't think this API support your case. There're different cases one browser have many renderer process. This api will support only iframe case, which you create iframes inside that main page, and then you can get renderer process id for that main page(ICoreWebView2) and iframe(ICoreWebView2Frame). See code example in spec review #3234 for more details.

@ztextplus
Copy link
Author

@novac42 @JosephJin0815 @aluhrs13
Is there any update, we really want this feature, we use multiple features in our app, and each feature corresponds to one or more render processes.

In actual use, we will find that the CPU and Memory usage of a certain render process is very high, and we really want to locate which feature this rendering process corresponds to. If this API can be provided, it will be very convenient for us to locate the problem.

@novac42 novac42 added the tracked We are tracking this work internally. label May 15, 2023
@novac42
Copy link
Contributor

novac42 commented May 15, 2023

@ztextplus Sorry for the wait. Right now we don't have this feature, I've added it to our backlog and will evaluate the priority in grooming.

@nishitha-burman nishitha-burman assigned aluhrs13 and unassigned novac42 Aug 23, 2023
@dfghj44444
Copy link

dfghj44444 commented Jun 20, 2024

I have same issue, and the workroud mentioned above is for C#, how does it work on C++ @novac42

@JosephJin0815 JosephJin0815 self-assigned this Jun 20, 2024
@JosephJin0815
Copy link
Contributor

Hi @ztextplus,
You can check GetProcessExtendedInfos(C++) API, which provides the mapping between renderer process Id and associated frame Info.

And each ICoreWebView2/ICoreWebView2Frame has the FrameId property now, so you should at least able to know the corresponding two renderer for the ICoreWebView2 object you created for each feature.

Also a reference about Process model for WebView2 apps

@JosephJin0815
Copy link
Contributor

@dfghj44444 Do you mean CoreWebView2ProcessKind?
Here's the C++ API reference ICoreWebView2ProcessInfo

@dfghj44444
Copy link

dfghj44444 commented Jun 24, 2024

@JosephJin0815 In fact I want to get all render process ids(including the main frame and all sub-iframes) which belong to a web-page, thus I could calc the cpu and memory usage of a web-page.

@JosephJin0815
Copy link
Contributor

Hi @dfghj44444
The GetProcessExtendedInfos API enables you to retrieve all renderer processes info with associated frame info including main frame and all sub-frames. To group sub-frames under their respective main frames, you can use ParentFrameInfo property. In scenarios where there are multiple main frames, the FrameId property is useful for identifying a specific main frame.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request feature request tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

6 participants