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

Tracing improvements #50

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

mganandraj
Copy link
Contributor

@mganandraj mganandraj commented Apr 1, 2021

This PR makes the following improvement to the ETW tracing,

  1. All traces are now correctly attributed to the right runtime.
  2. Fixes crash when multiple runtimes are registering the ETW provider.
  3. Enables overriding some arguments through system registry.
  4. Improvements to the powershell script to make the tracing easier.

I reformatted some of the files accidentally. I can't find an easy way to revert those formatting hcanges.

Microsoft Reviewers: Open in CodeFlow

@mganandraj mganandraj requested a review from tudorms April 1, 2021 08:12
@mganandraj mganandraj requested a review from a team April 2, 2021 15:21
@tudorms
Copy link
Member

tudorms commented Apr 2, 2021

Please also bump the version in config.json

#include <atomic>
#include <cstdlib>
#include <list>
#include <mutex>
#include <sstream>

#include "V8JsiRuntime_impl.h"
Copy link
Member

Choose a reason for hiding this comment

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

We typically want the main .h file to be the first one. It is also better to put all standard headers after custom header - this way we can partially ensure that custom headers have all required includes.

@vmoroz
Copy link
Member

vmoroz commented Apr 2, 2021

It is difficult to review changes because of the formatting changes in the same PR.
Please split the PR into two different PRs:

  • The first one one will be the formatting changes only. Note that the code is not foormatted using the clang format settings that we have. Open the folder in VS Code and format there - it should pickup the Clang format settings.
  • Then after the formatting change is merged - reformat your code using Clang format, and merge the previous PR. - After that we should see only your changes.

src/V8Platform.h Outdated
@@ -28,52 +28,37 @@ class ETWTracingController : public v8::TracingController {
ETWTracingController(bool enabled) : enabled_(enabled) {}
~ETWTracingController() = default;

const uint8_t *GetCategoryGroupEnabled(const char *category_group) override;
const uint8_t* GetCategoryGroupEnabled(const char* category_group) override;
Copy link
Member

Choose a reason for hiding this comment

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

const char* [](start = 41, length = 12)

Our clang format settings put the star on the right. What tool do you use to format code?

@@ -1574,12 +1572,54 @@ v8::Local<v8::Value> V8Runtime::valueRef(const jsi::Value &value) {
}
}

std::unique_ptr<jsi::Runtime> makeV8Runtime(V8RuntimeArgs &&args) {
void applyOverrides(V8RuntimeArgs& args) {
Copy link
Member

Choose a reason for hiding this comment

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

applyOverrides [](start = 5, length = 14)

It would be great to avoid this DLL accessing the registry. Can it be the application that does it?
The V8JSI is an open source project and it seems to be wrong to use MS Office key in the path and have a "backdoor" affecting any app in the system that uses this DLL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do partially agree Vladimir .. but having such control will be extremely helpful when building debugging and performance tooling. We can hopefully remove these once our tooling is matured. I'm removing the "Office" subpaths from the registry key.. Hope it works for you.

Copy link
Member

@vmoroz vmoroz Apr 3, 2021

Choose a reason for hiding this comment

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

Can we have a subkey per application? I.e. per executable file name that uses the V8JSI DLL.
E.g. L"SOFTWARE\Microsoft\V8JSI\foo.exe";


In reply to: 606578849 [](ancestors = 606578849)

Copy link
Member

Choose a reason for hiding this comment

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

Why is this needed at all? These values are already being passed through the arguments; the consumer is already capable of passing them in.


In reply to: 606610175 [](ancestors = 606610175,606578849)

@tudorms
Copy link
Member

tudorms commented Apr 2, 2021

Alternatively just reformat the code in vscode / clang format and push a PR interation here.


In reply to: 812684252 [](ancestors = 812684252)

@mganandraj
Copy link
Contributor Author

It is difficult to review changes because of the formatting changes in the same PR.
Please split the PR into two different PRs:

  • The first one one will be the formatting changes only. Note that the code is not foormatted using the clang format settings that we have. Open the folder in VS Code and format there - it should pickup the Clang format settings.
  • Then after the formatting change is merged - reformat your code using Clang format, and merge the previous PR. - After that we should see only your changes.

The code got (accidentally) formatted by VS using chromium formatting rules .. I realized the formatting changes after making a bunch of changes on top, and attempted reverting but it turned out to be very messy ..

I don't have strong opinions on the formatting rules. When we started this codebase, we roughly followed the V8 formatting rules for things such as the variable, function naming, which still stays. As we build the code alongside V8, and devs (incl. me) usually create one big VS solution of V8 with this JSI code as a subproject, the chromium formatting rules fits the best i think. But, that is a very subjective discussion which I don't want to get into.

I'm reformatting the code with VS code using our checked in clang format as @tudorms suggested which is the least expensive resolution. Hope it works for you.

@tudorms

@@ -28,7 +26,9 @@ using namespace facebook;

namespace v8runtime {

thread_local uint16_t V8Runtime::tls_isolate_usage_counter_ = 0;
thread_local uint16_t V8Runtime::tls_isolate_usage_counter_{0};
thread_local std::weak_ptr<V8Runtime::CounterStores>
Copy link
Member

Choose a reason for hiding this comment

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

weak_ptr [](start = 18, length = 8)

Ideally we should stop using TLS. In future we want to be able to use The V8 engine in scenarios without a dedicated JS thread. A better approach is to assciate the data with the Runtime, V8 context, or V8 isolate.
Anyway, there is no mechanism to call destructor on the TLS stored objects. Please reconsider having std::weak_ptr as TLS value. TLS is usually good only for simple values such as numbers or raw pointers.

Copy link
Member

@vmoroz vmoroz Apr 3, 2021

Choose a reason for hiding this comment

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

I looked through the code and still do not understand why we cannot associate counters with the Runtime or Isolate instead of TLS.


In reply to: 606609468 [](ancestors = 606609468)

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 to access the counters from the static callback functions that we register to the isolate .. Essentially, what we want is access to "this" runtime pointer in the static callbacks .. The access to counters starts even before the isolate is properly constructed, hence we can't use the isolate data slots ..

I was also hesistant to add tls data .. I initially had a unique instance id counter to uniquely identify an instance, instead of a thread id .. But it turned out to be a lot more code and uglier. .. As V8 isolates and a thread is 1:1 mapped, I think the tls is fine for our scenario.. Essentialy, we can treat the counters as per isolate counters, not really per-runtime counters ..

We are not really gaining anything by having the weak_ptr .. even a raw pointer in tls with the shared_ptr member for lifetime manager suffice for us .. But, i made this change to weak_ptr just before the CR to make the code look nicer :) the naked pointer looks bad .. But as you suggested this, i'll revert the tls entry to a nake pointer.

@@ -572,19 +589,22 @@ void V8Runtime::initializeV8() {
}

V8Runtime::V8Runtime(V8RuntimeArgs &&args) : args_(std::move(args)) {
counter_stores_ = std::make_shared<CounterStores>();
tls_counter_stores_ = counter_stores_;
Copy link
Member

Choose a reason for hiding this comment

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

Why do we create them in two places: here in constructor and in the CreateNewIsolate() method? In most cases the CreateNewIsolate will override values created here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah .. This was a mistake .. Thanks !

std::unique_ptr<jsi::Runtime> makeV8Runtime(V8RuntimeArgs &&args) {
applyOverrides(args);
Copy link
Member

Choose a reason for hiding this comment

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

applyOverrides(args);

Can you submit the rest of the changes besides this registry functionality (I think this is the only sticking point of the PR and we can revisit it later). There's a formatting PR in the pipeline and merging that would be painful after the fact.

@shivenmian shivenmian self-assigned this Oct 8, 2021
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