Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Issue 2495173002: tracing: fix races in CategoryRegistry (Closed)

Created:
4 years, 1 month ago by Primiano Tucci (use gerrit)
Modified:
4 years, 1 month ago
CC:
chromium-reviews, tracing+reviews_chromium.org, wfh+watch_chromium.org, Lei Zhang
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

tracing: fix races in CategoryRegistry The previous CL crrev.com/2452063003 did introduce a subtle race and a more trivial test flakiness. 1) race in trace_log.cc: this is a classical time-of-check vs time-of-use from school books. The newly introduced GetOrCreateCategoryByName() API was badly designed. If two threads hit that concurrently only one of the two would see a true retval and initialize the category (good) but the other one will carry on and use the uninitialized category before the first one has completed the initialization from the TraceLog (bad). This was a consequence of trying to separate the locks between TraceLog and CategoryRegistry. The new design is simpler and more aligned with the old behavior. TraceLog is the only one handling a lock and CategoryRegistry expects the caller to serialize calls, exposing an explicit GetOrCreateCategoryLocked method. 2) flakiness in trace_category_unittest.cc: categories cannot be reset once they are created, even in tests. This is because the static pointers injected by the TRACE_EVENT macros cannot be reset once they have been initialized so once hit a category pointer must be stable for the entire lifetime of the process (this behavior predates crrev.com/2452063003 and isn't a recent change). Concretely this is causing an interference between the two new test fixtures recently introduced in crrev.com/2452063003 if they are ran in reverse order. Fixed by changing the prefix of the category names so they don't collide. BUG=659689 Committed: https://crrev.com/5a5b09bbda9a7399e602b4cc01e0c56bb187e651 Cr-Commit-Position: refs/heads/master@{#433601}

Patch Set 1 #

Patch Set 2 : . #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+72 lines, -50 lines) Patch
M base/trace_event/category_registry.h View 1 3 chunks +21 lines, -11 lines 1 comment Download
M base/trace_event/category_registry.cc View 1 5 chunks +22 lines, -28 lines 0 comments Download
M base/trace_event/trace_category_unittest.cc View 5 chunks +17 lines, -6 lines 0 comments Download
M base/trace_event/trace_log.cc View 1 chunk +12 lines, -5 lines 1 comment Download

Dependent Patchsets:

Messages

Total messages: 23 (15 generated)
Primiano Tucci (use gerrit)
Small fix. long flights are great to debug races.
4 years, 1 month ago (2016-11-13 06:43:17 UTC) #7
Primiano Tucci (use gerrit)
Adding some comment to explain the situation better https://codereview.chromium.org/2495173002/diff/20001/base/trace_event/trace_log.cc File base/trace_event/trace_log.cc (left): https://codereview.chromium.org/2495173002/diff/20001/base/trace_event/trace_log.cc#oldcode498 base/trace_event/trace_log.cc:498: CategoryRegistry::GetOrCreateCategoryByName(category_group, ...
4 years, 1 month ago (2016-11-16 16:46:54 UTC) #10
Primiano Tucci (use gerrit)
Simon, can I ask you to review this? Oystein went on holidays and this is ...
4 years, 1 month ago (2016-11-21 13:54:25 UTC) #13
shatch
On 2016/11/21 13:54:25, Primiano - slow(travelling) wrote: > Simon, can I ask you to review ...
4 years, 1 month ago (2016-11-21 15:54:28 UTC) #14
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2495173002/20001
4 years, 1 month ago (2016-11-21 17:55:26 UTC) #16
Lei Zhang
https://codereview.chromium.org/2495173002/diff/20001/base/trace_event/category_registry.h File base/trace_event/category_registry.h (right): https://codereview.chromium.org/2495173002/diff/20001/base/trace_event/category_registry.h#newcode21 base/trace_event/category_registry.h:21: // Allows fast and thread-safe acces to the state ...
4 years, 1 month ago (2016-11-21 19:11:13 UTC) #18
commit-bot: I haz the power
Committed patchset #2 (id:20001)
4 years, 1 month ago (2016-11-21 19:16:59 UTC) #21
commit-bot: I haz the power
4 years, 1 month ago (2016-11-21 19:21:33 UTC) #23
Message was sent while issue was closed.
Patchset 2 (id:??) landed as
https://crrev.com/5a5b09bbda9a7399e602b4cc01e0c56bb187e651
Cr-Commit-Position: refs/heads/master@{#433601}

Powered by Google App Engine
This is Rietveld 408576698