Closed Bug 1338957 Opened 7 years ago Closed 7 years ago

Simplify sleep handling in PseudoStack

Categories

(Core :: Gecko Profiler, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla54
Tracking Status
firefox54 --- fixed

People

(Reporter: n.nethercote, Assigned: n.nethercote)

References

Details

Attachments

(3 files, 1 obsolete file)

It's much more complex than it needs to be.
This patch:

- Reformats PseudoStack.h to more closely follow Mozilla style.

- Rewrites some comments to make them more readable, e.g. by properly
  delimiting sentences with upper-case letters and full stops.

- Replaces sMin() with std::min(), because <algorithm> no longer causes
  problems.

- Reorders PseudoStack so that all the data members are at the end, which makes
  them easier to see.
Attachment #8836564 - Flags: review?(mstange)
Assignee: nobody → n.nethercote
Status: NEW → ASSIGNED
Bug 1337189 part 17 was the change that made this comment no longer true.
Attachment #8836565 - Flags: review?(mstange)
Sleep handling is currently done with two counters (mSleepId, mSleepIdObserved)
and a boolean (mSleeping). This patch replaces it with a single tri-state
variable (mSleep), which is enough to replicate the functionality.

The patch also clearly documents how this variable is accessed from multiple
threads and the potential inaccuracies that can result from races.
Attachment #8836566 - Flags: review?(mstange)
mstange, I'm interested to hear if you think this (from part 3) is worth pursuing:

  // This latter inaccuracy could be avoided by moving the
  // CanDuplicateLastSampleDueToSleep() check within the thread-freezing code,
  // e.g. the section where Tick() is called. But that would reduce the
  // effectiveness of the optimization because more code would have to be run
  // before we can tell that duplication is allowed.

In case it helps, bug 963158 is the bug that introduced the sleep handling code, and bug 963158 comment 3 has some performance numbers, which I have not yet tried to replicate.
Fix a couple of minor things.
Attachment #8836591 - Flags: review?(mstange)
Attachment #8836566 - Attachment is obsolete: true
Attachment #8836566 - Flags: review?(mstange)
(In reply to Nicholas Nethercote [:njn] from comment #5)
> Created attachment 8836591 [details] [diff] [review]
> (part 3) - Simplify sleep handling in PseudoStack

nano-comment:
+  //   issues. (In actual fast, this case is impossible. In order to go from

s/fast/fact
Attachment #8836564 - Flags: review?(mstange) → review+
Attachment #8836565 - Flags: review?(mstange) → review+
Comment on attachment 8836591 [details] [diff] [review]
(part 3) - Simplify sleep handling in PseudoStack

Review of attachment 8836591 [details] [diff] [review]:
-----------------------------------------------------------------

Looks good! I accidentally reviewed the older version of this patch first, so I'm happy that you fixed the "minor" mistake of calling setAwake instead of setSleeping :)
Attachment #8836591 - Flags: review?(mstange) → review+
(In reply to Nicholas Nethercote [:njn] from comment #4)
> mstange, I'm interested to hear if you think this (from part 3) is worth
> pursuing:

I do not think this is worth pursuing. Sampling-based profilers have some inherent inaccuracy; this one is not a source of inaccuracy that's worth worrying about, in my opinion.
In fact, it's arguable whether this is even an inaccuracy at all. You could consider sampling to have two phases: (1) measuring the current state of the thread's stack, and (2) writing out the collected information to the buffer. Phase (2) could be delayed arbitrarily and we wouldn't care - as long as what we write out to the buffer reflects the truth at the time of measuring. In the sleeping case, the "measuring phase" is the time at which we call CanDuplicateLastSampleDueToSleep(), and it returns the truth as observed at that time.
> Looks good! I accidentally reviewed the older version of this patch first,
> so I'm happy that you fixed the "minor" mistake of calling setAwake instead
> of setSleeping :)

A try push showed that one quickly. Hooray for assertions!
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: