Closed
Bug 1466783
Opened 6 years ago
Closed 6 years ago
Avoid copying while passing the profiler data with IPC
Categories
(Core :: Gecko Profiler, enhancement)
Core
Gecko Profiler
Tracking
()
RESOLVED
FIXED
mozilla63
Tracking | Status | |
---|---|---|
firefox63 | --- | fixed |
People
(Reporter: canova, Assigned: canova)
References
Details
Attachments
(1 file)
See bug 1458246 comment 10 for explanation. We can avoid copying the data. Currently we have 2 places that we can fix. One is in ChunkedJSONWriteFunc::CopyData() and the other one is in CollectProfileOrEmptyString.
Comment hidden (mozreview-request) |
Comment 2•6 years ago
|
||
mozreview-review |
Comment on attachment 8987554 [details] Bug 1466783 - Avoid copying while passing the profiler data with IPC https://reviewboard.mozilla.org/r/252796/#review261602 Looks good. I don't know how I feel about embedding knowledge about Shmem allocation so deeply inside the profiler code. It's probably not going to make it easier to move the profiler code out of libxul (bug 1437245), but on the other hand, I don't like any of the ideas that I had for making this API more generic. Here's such an idea that uses a lambda to delegate the allocation of the buffer to the caller: Shmem shmem; profiler_get_profile_json_into_lazily_allocated_buffer([&](size_t allocationSize) { if (AllocShmem(allocationSize, SharedMemory::TYPE_BASIC, &shmem)) { return shmem.get<char>(); } return nullptr; }); // use shmem here ::: tools/profiler/core/platform.cpp:2663 (Diff revision 1) > delete samplerThread; > } > } > > -UniquePtr<char[]> > -profiler_get_profile(double aSinceTime, bool aIsShuttingDown) > +static bool > +profiler_fill_profiler_json_writer(SpliceableChunkedJSONWriter& aWriter, This function is not exposed in GeckoProfiler.h, so let's use a more normal name for it. We only use the "profiler_*" pattern for public functions in GeckoProfiler.h. For this function, I suggest WriteProfileToJSONWriter. ::: tools/profiler/core/platform.cpp:2692 (Diff revision 1) > +profiler_get_profile(double aSinceTime, bool aIsShuttingDown) > +{ > + LOG("profiler_get_profile"); > + > + SpliceableChunkedJSONWriter b; > + if(!profiler_fill_profiler_json_writer(b, aSinceTime, aIsShuttingDown)) { Missing a space after "if" ::: tools/profiler/core/platform.cpp:2705 (Diff revision 1) > + double aSinceTime, bool aIsShuttingDown) > +{ > + LOG("profiler_get_profile_shmem"); > + > + SpliceableChunkedJSONWriter b; > + if(!profiler_fill_profiler_json_writer(b, aSinceTime, aIsShuttingDown)) { Missing space here, too
Attachment #8987554 -
Flags: review?(mstange) → review+
Comment hidden (mozreview-request) |
Assignee | ||
Comment 4•6 years ago
|
||
I procrastinated the Shmem allocation to ProfilerChild.cpp. So we were able to get rid of the Shmem and allocator from other files. There are a few changes, could you review again Markus?
Assignee | ||
Comment 5•6 years ago
|
||
mozreview-review-reply |
Comment on attachment 8987554 [details] Bug 1466783 - Avoid copying while passing the profiler data with IPC https://reviewboard.mozilla.org/r/252796/#review261602 > Missing space here, too Ugh, there is no C++ linter command in the mach, right? It would be great to catch these before sending the patch. I miss the `./mach test-tidy` on servo :)
Assignee | ||
Comment 6•6 years ago
|
||
mozreview-review |
Comment on attachment 8987554 [details] Bug 1466783 - Avoid copying while passing the profiler data with IPC https://reviewboard.mozilla.org/r/252796/#review261724 ::: tools/profiler/gecko/ProfilerChild.cpp:105 (Diff revision 2) > + return shmem.get<char>(); > + } > + return nullptr; > + }, > + /* aSinceTime */ 0, /* aIsShuttingDown */ false); > + aResolve(std::move(shmem)); I had to move the shmem here since GatherProfileResolver only allows r-value reference as the argument. But I think this is the right approach. There are also some examples on the existing code: https://searchfox.org/mozilla-central/search?q=move%5C(.*shmem%5C)&case=false®exp=true&path=
Comment hidden (mozreview-request) |
Assignee | ||
Comment 8•6 years ago
|
||
(Updated the patch after `./mach clang-format` enlightenment. Thanks `./mach help`!)
Comment 9•6 years ago
|
||
mozreview-review |
Comment on attachment 8987554 [details] Bug 1466783 - Avoid copying while passing the profiler data with IPC https://reviewboard.mozilla.org/r/252796/#review261798 ::: tools/profiler/core/ProfileJSONWriter.h:44 (Diff revision 3) > void Write(const char* aStr) override; > + void CopyDataIntoLazilyAllocatedBuffer( > + std::function<char*(size_t)> aAllocator) const; > mozilla::UniquePtr<char[]> CopyData() const; > void Take(ChunkedJSONWriteFunc&& aOther); > + size_t GetTotalLength() const; Since this method is now public, let's add a comment to it. // Returns the byte length of the complete combined string, including the null terminator byte. ::: tools/profiler/core/platform.cpp:2699 (Diff revision 3) > return b.WriteFunc()->CopyData(); > } > > void > +profiler_get_profile_json_into_lazily_allocated_buffer( > + std::function<char*(size_t)> aAllocator, Let's change this to a const reference of std::function, I think that saves a potential copy of the lambda and expresses that we don't intend to store the lambda anywhere. Here and in the CopyDataIntoLazilyAllocatedBuffer method ::: tools/profiler/gecko/ProfilerChild.cpp:106 (Diff revision 3) > + } > + return nullptr; > + }, > + /* aSinceTime */ 0, > + /* aIsShuttingDown */ false); > + aResolve(std::move(shmem)); Yes, moving the shmem is the right thing to do.
Comment hidden (mozreview-request) |
Comment 11•6 years ago
|
||
Pushed by canaltinova@gmail.com: https://hg.mozilla.org/integration/autoland/rev/463f7fc23171 Avoid copying while passing the profiler data with IPC r=mstange
Comment 12•6 years ago
|
||
Backed out for build bustages on OS X Cross Compiled debug and OS X Cross Compiled NoOpt debug Push that started the failures: https://treeherder.mozilla.org/#/jobs?repo=autoland&revision=463f7fc231716e0158225544a1903b6727ee1efa Failure log: https://treeherder.mozilla.org/logviewer.html#?job_id=186569045&repo=autoland&lineNumber=998 Backout: https://hg.mozilla.org/integration/autoland/rev/6792d723a2b1d4f2ff2a702f7ae1f4c52fa32346
Flags: needinfo?(canaltinova)
Assignee | ||
Comment 13•6 years ago
|
||
Oh, I forgot to add a reference after adding `const` to arguments. Will fix.
Flags: needinfo?(canaltinova)
Comment hidden (mozreview-request) |
Comment 15•6 years ago
|
||
Pushed by canaltinova@gmail.com: https://hg.mozilla.org/integration/autoland/rev/90f004457128 Avoid copying while passing the profiler data with IPC r=mstange
Comment 16•6 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/90f004457128
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
status-firefox63:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla63
You need to log in
before you can comment on or make changes to this bug.
Description
•