|
|
Created:
5 years, 2 months ago by Michael Hablich Modified:
5 years, 1 month ago CC:
v8-reviews_googlegroups.com Base URL:
https://chromium.googlesource.com/v8/v8.git@master Target Ref:
refs/pending/heads/master Project:
v8 Visibility:
Public. |
DescriptionProvide a counter for thrown JavaScript errors per context
This will be used as a data source for an
UMA histogram.
LOG=N
BUG=chromium:546603
R=jochen@chromium.org,yangguo@chromium.org
Committed: https://crrev.com/762777594889fd4f6520e65d23d0e558ff85defd
Cr-Commit-Position: refs/heads/master@{#31851}
Patch Set 1 #
Total comments: 1
Patch Set 2 : Transformed from counter to histogram #Patch Set 3 : not intended for review #Patch Set 4 : V8 thrown exceptions now reported per Isolate via Histogram #Patch Set 5 : Per context counting implemented #
Total comments: 12
Patch Set 6 : Adaptations to feedback and now all V8 exceptions are counted #
Total comments: 7
Patch Set 7 : Moved counting from creation to throwing again #
Total comments: 6
Patch Set 8 : Adapted to Yang's feedback #
Total comments: 6
Patch Set 9 : Moved initialization #
Messages
Total messages: 42 (14 generated)
PTAL
Not sure whether counters are still used in Chrome. Jochen is probably more up-to-date on this. https://codereview.chromium.org/1413503007/diff/1/src/isolate.cc File src/isolate.cc (right): https://codereview.chromium.org/1413503007/diff/1/src/isolate.cc#newcode997 src/isolate.cc:997: this->counters()->exceptions_thrown()->Increment(); You can omit "this->" Putting the counter increment here would include every thrown exception, not just uncaught ones. The problem here is that throw is just normal Javascript syntax. Whether or how people use it in content scripts is entirely their choice. For example, you can (ab)use it for control flow, it's a perfectly valid and acceptable way to reject a Promise. If we decide to count all exceptions, maybe we can limit that to ones thrown by V8? A possible place to add the counter increment for this purpose is v8::internal::Runtime_FormatMessage.
counters aren't used. you'll have to count how often an exception was thrown, and then update an histogram with that number at certain points in time. i'm still highly skeptical of just counting exceptions.
On 2015/10/23 12:14:39, jochen wrote: > counters aren't used. > > you'll have to count how often an exception was thrown, and then update an > histogram with that number at certain points in time. > > i'm still highly skeptical of just counting exceptions. Only exceptions generated by V8 are counted and stored into a histogram. I also tried tried the following, more sophisticated solution: -Increment a counter each time an V8 exception is thrown -After parsing code (Parser::ParseProgram and Parser::ParseLazy) store the value of the counter in a histogram bucket -Unfortunately I couldn't access the value of the counter and I couldn't decipher how D8 is doing it.
I still don't understand how that value would be useful? you'll get a histogram, with a number of samples in one of the two buckets. What will that tell us?
On 2015/10/26 15:56:47, jochen wrote: > I still don't understand how that value would be useful? > > you'll get a histogram, with a number of samples in one of the two buckets. What > will that tell us? Well, I only want a simple counter but you told me Chromium needs the data stored in a histogram. Thinking about it, we only need one bucket because it should behave similar to the Chromium statistic Stability.* in the end. As mentioned during email conversation following the motivation behind it: -Early warning if we brake the web e.g. switching on sloppy scoping --We are not only relying on bug reports anymore -Metric can be used further to achieve the following: --E.g. run Telemetry tests on real world websites comparing two builds with and without staging flags quite easy (Telemetry is just an example) --Use the metric for Finch experiments e.g. if we start working on a new parser As already discussed it makes absolute sense to normalize the data with the help of pageloads similar to Renderer/Browser crashes on UMA.
Patchset #4 (id:60001) has been deleted
PTAL PS #4: As discussed offline with Jochen counting the exceptions per Isolate makes the most sense.
On 2015/10/28 at 12:41:39, hablich wrote: > PTAL PS #4: > > As discussed offline with Jochen counting the exceptions per Isolate makes the most sense. hum, sorry if that was unclear. I'd propose to count the exception per Context. also, I'm not sure whether 0..200 is the right range. what about using an exponential histogram? note that we can't change the buckets of a histogram later on, we'd have to introduce a new one if it turns out that 200 was too small.
Patchset #5 (id:100001) has been deleted
Patchset #5 (id:120001) has been deleted
On 2015/10/28 12:44:55, jochen wrote: > On 2015/10/28 at 12:41:39, hablich wrote: > > PTAL PS #4: > > > > As discussed offline with Jochen counting the exceptions per Isolate makes the > most sense. > > hum, sorry if that was unclear. I'd propose to count the exception per Context. > > also, I'm not sure whether 0..200 is the right range. what about using an > exponential histogram? note that we can't change the buckets of a histogram > later on, we'd have to introduce a new one if it turns out that 200 was too > small. PTAL #5: Counting now happens per context. Open questions: 1.) Function Runtime_FormatMessageString in runtime-internal works.cc great when running standalone but it does not count properly when running in Chromium. Any clue why this is the case? I couldn't identify any other way to only count thrown errors by us because the factory methods in runtime-internal.cc are never called. 2.) When is Bootstrapper.cc::DetachGlobalContext called in Chrome? When I create a test page with a frameset the errors in the referenced pages are never counted EXCEPT I reload the particular frame. Closing the tab also didn't work. 3.) Ignore the buckets in the histogram for now.
https://codereview.chromium.org/1413503007/diff/140001/src/isolate.cc File src/isolate.cc (right): https://codereview.chromium.org/1413503007/diff/140001/src/isolate.cc#newcode... src/isolate.cc:1023: PredictExceptionCatcher() != CAUGHT_BY_JAVASCRIPT); Notes about PredictExceptionCatcher: 1) Calling this method is not entirely for free. It will perform a stack-walk and lookups in handler tables. 2) It can only produce an estimate (i.e. educated guess) about whether the exception will be caught by JavaScript or not. The question whether an exception will be caught or not is undecidable here (i.e. at the throw-site).
https://codereview.chromium.org/1413503007/diff/140001/src/contexts.cc File src/contexts.cc (right): https://codereview.chromium.org/1413503007/diff/140001/src/contexts.cc#newcod... src/contexts.cc:593: if (!IsNativeContext()) return; just DCHECK(IsNativeContext()) https://codereview.chromium.org/1413503007/diff/140001/src/contexts.cc#newcod... src/contexts.cc:594: if (exceptions_thrown()->IsUndefined()) { just initialize exceptions_thrown() to 0 in Factory::NewNativeContext https://codereview.chromium.org/1413503007/diff/140001/src/contexts.cc#newcod... src/contexts.cc:606: if (!IsNativeContext()) return -1; should never happen https://codereview.chromium.org/1413503007/diff/140001/src/counters.h File src/counters.h (right): https://codereview.chromium.org/1413503007/diff/140001/src/counters.h#newcode487 src/counters.h:487: HR(exceptions_thrown_per_context, V8.ExceptionsThrownPerContext, -1, 200, 202) I'd use a non-linear histogram. 202 buckets is quite a lot... https://codereview.chromium.org/1413503007/diff/140001/src/isolate.cc File src/isolate.cc (right): https://codereview.chromium.org/1413503007/diff/140001/src/isolate.cc#newcode... src/isolate.cc:1025: if (exception_is_uncaught) context()->IncrementExceptionsThrown(); use native_context()
Patchset #6 (id:160001) has been deleted
On 2015/10/29 14:37:07, jochen wrote: > https://codereview.chromium.org/1413503007/diff/140001/src/contexts.cc > File src/contexts.cc (right): > > https://codereview.chromium.org/1413503007/diff/140001/src/contexts.cc#newcod... > src/contexts.cc:593: if (!IsNativeContext()) return; > just DCHECK(IsNativeContext()) > > https://codereview.chromium.org/1413503007/diff/140001/src/contexts.cc#newcod... > src/contexts.cc:594: if (exceptions_thrown()->IsUndefined()) { > just initialize exceptions_thrown() to 0 in Factory::NewNativeContext > > https://codereview.chromium.org/1413503007/diff/140001/src/contexts.cc#newcod... > src/contexts.cc:606: if (!IsNativeContext()) return -1; > should never happen > > https://codereview.chromium.org/1413503007/diff/140001/src/counters.h > File src/counters.h (right): > > https://codereview.chromium.org/1413503007/diff/140001/src/counters.h#newcode487 > src/counters.h:487: HR(exceptions_thrown_per_context, > V8.ExceptionsThrownPerContext, -1, 200, 202) > I'd use a non-linear histogram. 202 buckets is quite a lot... > > https://codereview.chromium.org/1413503007/diff/140001/src/isolate.cc > File src/isolate.cc (right): > > https://codereview.chromium.org/1413503007/diff/140001/src/isolate.cc#newcode... > src/isolate.cc:1025: if (exception_is_uncaught) > context()->IncrementExceptionsThrown(); > use native_context() PTAL PS #6. Still, the open question is if this works properly with framesets or do I need to count the the sum per page myself?
https://codereview.chromium.org/1413503007/diff/140001/src/contexts.cc File src/contexts.cc (right): https://codereview.chromium.org/1413503007/diff/140001/src/contexts.cc#newcod... src/contexts.cc:593: if (!IsNativeContext()) return; On 2015/10/29 14:37:07, jochen wrote: > just DCHECK(IsNativeContext()) Done. https://codereview.chromium.org/1413503007/diff/140001/src/contexts.cc#newcod... src/contexts.cc:594: if (exceptions_thrown()->IsUndefined()) { On 2015/10/29 14:37:07, jochen wrote: > just initialize exceptions_thrown() to 0 in Factory::NewNativeContext Done. https://codereview.chromium.org/1413503007/diff/140001/src/contexts.cc#newcod... src/contexts.cc:606: if (!IsNativeContext()) return -1; On 2015/10/29 14:37:07, jochen wrote: > should never happen Done. https://codereview.chromium.org/1413503007/diff/140001/src/counters.h File src/counters.h (right): https://codereview.chromium.org/1413503007/diff/140001/src/counters.h#newcode487 src/counters.h:487: HR(exceptions_thrown_per_context, V8.ExceptionsThrownPerContext, -1, 200, 202) On 2015/10/29 14:37:07, jochen wrote: > I'd use a non-linear histogram. 202 buckets is quite a lot... I adapted it. I think this needs further tuning. I will talk with rossberg@ regarding this. https://codereview.chromium.org/1413503007/diff/140001/src/isolate.cc File src/isolate.cc (right): https://codereview.chromium.org/1413503007/diff/140001/src/isolate.cc#newcode... src/isolate.cc:1023: PredictExceptionCatcher() != CAUGHT_BY_JAVASCRIPT); On 2015/10/29 13:42:55, Michael Starzinger wrote: > Notes about PredictExceptionCatcher: > > 1) Calling this method is not entirely for free. It will perform a stack-walk > and lookups in handler tables. > 2) It can only produce an estimate (i.e. educated guess) about whether the > exception will be caught by JavaScript or not. The question whether an exception > will be caught or not is undecidable here (i.e. at the throw-site). I moved the whole counting into the factory which should count the right things. https://codereview.chromium.org/1413503007/diff/140001/src/isolate.cc#newcode... src/isolate.cc:1025: if (exception_is_uncaught) context()->IncrementExceptionsThrown(); On 2015/10/29 14:37:07, jochen wrote: > use native_context() Done.
On 2015/10/29 15:23:34, Hablich wrote: > https://codereview.chromium.org/1413503007/diff/140001/src/contexts.cc > File src/contexts.cc (right): > > https://codereview.chromium.org/1413503007/diff/140001/src/contexts.cc#newcod... > src/contexts.cc:593: if (!IsNativeContext()) return; > On 2015/10/29 14:37:07, jochen wrote: > > just DCHECK(IsNativeContext()) > > Done. > > https://codereview.chromium.org/1413503007/diff/140001/src/contexts.cc#newcod... > src/contexts.cc:594: if (exceptions_thrown()->IsUndefined()) { > On 2015/10/29 14:37:07, jochen wrote: > > just initialize exceptions_thrown() to 0 in Factory::NewNativeContext > > Done. > > https://codereview.chromium.org/1413503007/diff/140001/src/contexts.cc#newcod... > src/contexts.cc:606: if (!IsNativeContext()) return -1; > On 2015/10/29 14:37:07, jochen wrote: > > should never happen > > Done. > > https://codereview.chromium.org/1413503007/diff/140001/src/counters.h > File src/counters.h (right): > > https://codereview.chromium.org/1413503007/diff/140001/src/counters.h#newcode487 > src/counters.h:487: HR(exceptions_thrown_per_context, > V8.ExceptionsThrownPerContext, -1, 200, 202) > On 2015/10/29 14:37:07, jochen wrote: > > I'd use a non-linear histogram. 202 buckets is quite a lot... > > I adapted it. I think this needs further tuning. I will talk with rossberg@ > regarding this. > > https://codereview.chromium.org/1413503007/diff/140001/src/isolate.cc > File src/isolate.cc (right): > > https://codereview.chromium.org/1413503007/diff/140001/src/isolate.cc#newcode... > src/isolate.cc:1023: PredictExceptionCatcher() != CAUGHT_BY_JAVASCRIPT); > On 2015/10/29 13:42:55, Michael Starzinger wrote: > > Notes about PredictExceptionCatcher: > > > > 1) Calling this method is not entirely for free. It will perform a stack-walk > > and lookups in handler tables. > > 2) It can only produce an estimate (i.e. educated guess) about whether the > > exception will be caught by JavaScript or not. The question whether an > exception > > will be caught or not is undecidable here (i.e. at the throw-site). > > I moved the whole counting into the factory which should count the right things. > > https://codereview.chromium.org/1413503007/diff/140001/src/isolate.cc#newcode... > src/isolate.cc:1025: if (exception_is_uncaught) > context()->IncrementExceptionsThrown(); > On 2015/10/29 14:37:07, jochen wrote: > > use native_context() > > Done. I talked with rossberg@ yesterday regarding a good number for the buckets. Unfortunately he too does not have a good number at hand. Let's try 200 maximum with 20 buckets for one week and than analyze the data and make changes. I know, this means the old data is not usable anymore.
https://codereview.chromium.org/1413503007/diff/180001/src/factory.cc File src/factory.cc (right): https://codereview.chromium.org/1413503007/diff/180001/src/factory.cc#newcode... src/factory.cc:1163: isolate()->native_context()->IncrementExceptionsThrown(); \ this looks wrong. It's not uncommon to do var a = new Error().stack; to capture e.g. the creation site of an object
assuming mstarzinger@ approves this lgtm
mstarzinger@chromium.org changed reviewers: + mstarzinger@chromium.org
No objects to the CL in it's current form. But I have no idea whether this counts the things we want it to count or not. :) https://codereview.chromium.org/1413503007/diff/180001/src/bootstrapper.cc File src/bootstrapper.cc (right): https://codereview.chromium.org/1413503007/diff/180001/src/bootstrapper.cc#ne... src/bootstrapper.cc:376: // add thrown javascript exceptions nit: Please capitalize and punctuate comment. https://codereview.chromium.org/1413503007/diff/180001/src/contexts.cc File src/contexts.cc (right): https://codereview.chromium.org/1413503007/diff/180001/src/contexts.cc#newcod... src/contexts.cc:591: nit: Two empty newlines between top-level declarations.
Description was changed from ========== Provide a counter for thrown JavaScript errors This will be used later as a data source for an UMA histogram. LOG=N BUG=chromium:546603 R=jochen@chromium.org,yangguo@chromium.org ========== to ========== Provide a counter for thrown JavaScript errors This will be used later as a data source for an UMA histogram. LOG=N BUG=chromium:546603 R=jochen@chromium.org,yangguo@chromium.org ==========
mstarzinger@chromium.org changed reviewers: - mstarzinger@chromium.org
https://codereview.chromium.org/1413503007/diff/180001/src/factory.cc File src/factory.cc (right): https://codereview.chromium.org/1413503007/diff/180001/src/factory.cc#newcode... src/factory.cc:1163: isolate()->native_context()->IncrementExceptionsThrown(); \ On 2015/10/30 12:13:38, jochen wrote: > this looks wrong. It's not uncommon to do > > var a = new Error().stack; > > to capture e.g. the creation site of an object As discussed offline, I suggested to do it in %FormatMessageString.
Patchset #7 (id:200001) has been deleted
PTAL latest patchset. I also tried it out with Jochens patch regarding DetachGlobal and it works. https://codereview.chromium.org/1413503007/diff/180001/src/bootstrapper.cc File src/bootstrapper.cc (right): https://codereview.chromium.org/1413503007/diff/180001/src/bootstrapper.cc#ne... src/bootstrapper.cc:376: // add thrown javascript exceptions On 2015/10/30 12:27:10, Michael Starzinger wrote: > nit: Please capitalize and punctuate comment. I removed the comment entirely because the code is already very easy to comprehend. https://codereview.chromium.org/1413503007/diff/180001/src/contexts.cc File src/contexts.cc (right): https://codereview.chromium.org/1413503007/diff/180001/src/contexts.cc#newcod... src/contexts.cc:591: On 2015/10/30 12:27:10, Michael Starzinger wrote: > nit: Two empty newlines between top-level declarations. Done. https://codereview.chromium.org/1413503007/diff/180001/src/factory.cc File src/factory.cc (right): https://codereview.chromium.org/1413503007/diff/180001/src/factory.cc#newcode... src/factory.cc:1163: isolate()->native_context()->IncrementExceptionsThrown(); \ On 2015/10/30 13:01:02, Yang wrote: > On 2015/10/30 12:13:38, jochen wrote: > > this looks wrong. It's not uncommon to do > > > > var a = new Error().stack; > > > > to capture e.g. the creation site of an object > > As discussed offline, I suggested to do it in %FormatMessageString. I moved the call to %FormatMessageString. During the build %FormatMessageString is run once and the result is stored. This resulted in the weird behavior I observed before. Initializing the counter with -1 fixes this.
https://codereview.chromium.org/1413503007/diff/220001/src/contexts.cc File src/contexts.cc (right): https://codereview.chromium.org/1413503007/diff/220001/src/contexts.cc#newcod... src/contexts.cc:596: int previous_value = Smi::cast(errors_thrown())->value(); this cast would be unnecessary if the type of this field is defined as Smi. https://codereview.chromium.org/1413503007/diff/220001/src/contexts.h File src/contexts.h (right): https://codereview.chromium.org/1413503007/diff/220001/src/contexts.h#newcode189 src/contexts.h:189: V(ERRORS_THROWN_INDEX, Object, errors_thrown) \ Can we make the type Smi? https://codereview.chromium.org/1413503007/diff/220001/src/factory.cc File src/factory.cc (right): https://codereview.chromium.org/1413503007/diff/220001/src/factory.cc#newcode732 src/factory.cc:732: context->set_errors_thrown(Smi::FromInt(-1)); This seems somewhat brittle. Could we move this line to bootstrapper.cc Genesis::Genesis, right after this: isolate->counters()->contexts_created_from_scratch()->Increment(); https://code.google.com/p/chromium/codesearch#chromium/src/v8/src/bootstrappe...
PTAL PS #8 https://codereview.chromium.org/1413503007/diff/220001/src/contexts.cc File src/contexts.cc (right): https://codereview.chromium.org/1413503007/diff/220001/src/contexts.cc#newcod... src/contexts.cc:596: int previous_value = Smi::cast(errors_thrown())->value(); On 2015/11/02 05:48:57, Yang wrote: > this cast would be unnecessary if the type of this field is defined as Smi. Done. https://codereview.chromium.org/1413503007/diff/220001/src/contexts.h File src/contexts.h (right): https://codereview.chromium.org/1413503007/diff/220001/src/contexts.h#newcode189 src/contexts.h:189: V(ERRORS_THROWN_INDEX, Object, errors_thrown) \ On 2015/11/02 05:48:57, Yang wrote: > Can we make the type Smi? Done. https://codereview.chromium.org/1413503007/diff/220001/src/factory.cc File src/factory.cc (right): https://codereview.chromium.org/1413503007/diff/220001/src/factory.cc#newcode732 src/factory.cc:732: context->set_errors_thrown(Smi::FromInt(-1)); On 2015/11/02 05:48:57, Yang wrote: > This seems somewhat brittle. > > Could we move this line to bootstrapper.cc Genesis::Genesis, right after this: > > isolate->counters()->contexts_created_from_scratch()->Increment(); > > https://code.google.com/p/chromium/codesearch#chromium/src/v8/src/bootstrappe... Thanks for the remark. I left the initialization in factory.cc because it should still create a valid Context. Additionally I re-initialize the the counter when a context is loaded from the snapshot.
LGTM if comments are addressed. https://codereview.chromium.org/1413503007/diff/230001/src/bootstrapper.cc File src/bootstrapper.cc (right): https://codereview.chromium.org/1413503007/diff/230001/src/bootstrapper.cc#ne... src/bootstrapper.cc:3160: isolate->native_context()->set_errors_thrown(Smi::FromInt(0)); Move this below please. Otherwise we would get wrong numbers if no snapshot was present. https://codereview.chromium.org/1413503007/diff/230001/src/bootstrapper.cc#ne... src/bootstrapper.cc:3200: isolate->counters()->contexts_created_from_scratch()->Increment(); Reinitalize counter here. https://codereview.chromium.org/1413503007/diff/230001/src/contexts.cc File src/contexts.cc (right): https://codereview.chromium.org/1413503007/diff/230001/src/contexts.cc#newcod... src/contexts.cc:585: set_errors_thrown(Smi::FromInt(previous_value+1)); I think "git cl format" would add spaces around +.
Description was changed from ========== Provide a counter for thrown JavaScript errors This will be used later as a data source for an UMA histogram. LOG=N BUG=chromium:546603 R=jochen@chromium.org,yangguo@chromium.org ========== to ========== Provide a counter for thrown JavaScript errors per context This will be used as a data source for an UMA histogram. LOG=N BUG=chromium:546603 R=jochen@chromium.org,yangguo@chromium.org ==========
Patchset #9 (id:250001) has been deleted
https://codereview.chromium.org/1413503007/diff/230001/src/bootstrapper.cc File src/bootstrapper.cc (right): https://codereview.chromium.org/1413503007/diff/230001/src/bootstrapper.cc#ne... src/bootstrapper.cc:3160: isolate->native_context()->set_errors_thrown(Smi::FromInt(0)); On 2015/11/05 07:50:01, Yang wrote: > Move this below please. Otherwise we would get wrong numbers if no snapshot was > present. After an offline discussion I now get it why it should be down there. Thanks. done. https://codereview.chromium.org/1413503007/diff/230001/src/bootstrapper.cc#ne... src/bootstrapper.cc:3200: isolate->counters()->contexts_created_from_scratch()->Increment(); On 2015/11/05 07:50:01, Yang wrote: > Reinitalize counter here. Done. https://codereview.chromium.org/1413503007/diff/230001/src/contexts.cc File src/contexts.cc (right): https://codereview.chromium.org/1413503007/diff/230001/src/contexts.cc#newcod... src/contexts.cc:585: set_errors_thrown(Smi::FromInt(previous_value+1)); On 2015/11/05 07:50:01, Yang wrote: > I think "git cl format" would add spaces around +. Done.
The CQ bit was checked by hablich@chromium.org
The patchset sent to the CQ was uploaded after l-g-t-m from jochen@chromium.org, yangguo@chromium.org Link to the patchset: https://codereview.chromium.org/1413503007/#ps270001 (title: "Moved initialization")
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1413503007/270001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1413503007/270001
The CQ bit was unchecked by commit-bot@chromium.org
Try jobs failed on following builders: v8_mac_rel on tryserver.v8 (JOB_TIMED_OUT, http://build.chromium.org/p/tryserver.v8/builders/v8_mac_rel/builds/11568)
The CQ bit was checked by hablich@chromium.org
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1413503007/270001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1413503007/270001
Message was sent while issue was closed.
Committed patchset #9 (id:270001)
Message was sent while issue was closed.
Patchset 9 (id:??) landed as https://crrev.com/762777594889fd4f6520e65d23d0e558ff85defd Cr-Commit-Position: refs/heads/master@{#31851} |