-
Notifications
You must be signed in to change notification settings - Fork 33
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
Refactor #22
Refactor #22
Conversation
@kvelicka Would you mind reviewing this PR because it does break your incremental parser API? |
I've only had a first pass at the code but the first impression is 👍 I'll try to look into it more later in the week. |
See haskell/ghc-events#22 for the changes in ghc-events.
I made a change in threadscope for this refactor: haskell/ThreadScope@master...maoe:ghc-events-refactor. Basically nothing has changed. |
Done leftover -> Right (header, BL.Chunk leftover bytes) | ||
_ -> fail "readHeader: unexpected decoder" | ||
Consume k -> case bytes of | ||
BL.Empty -> fail "readHeader: not enough bytes" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that a caller has to supply a ByteString containing (at least) all of the header in one go? In other words, is reading the header non-incremental?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right. For incremental parsing of a header, one should use decodeHeader
. Maybe I should mention this behavior in the Haddock comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a note about this in 53f2872.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very nice, good job!
Admittedly I haven't tested this myself but given that the tests pass (and the fact that you seem to be using the library in your own code), I am quite confident in the correctness of the patch. I've had a couple of questions here and there but they're mostly minor things.
src/GHC/RTS/Events/Incremental.hs
Outdated
-- | Serialises an 'EventLog' back to a 'ByteString', usually for writing it | ||
-- back to a file. | ||
serialiseEventLog :: EventLog -> BL.ByteString | ||
serialiseEventLog el@(EventLog _ (Data events)) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tested serialising at all? I think it'd be a good thing to write some tests for!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, not really because it hasn't changed aside some code formatting and renaming (isCap
-> mkCap
).
I agree that it's a good thing to write some tests. I guess we start by fixing #14.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this test would be a good intermediate step to fixing it -- currently I'm not sure whether the bug is in the writing or merging code (or both!)
src/GHC/RTS/Events.hs
Outdated
@@ -1,6 +1,7 @@ | |||
{-# LANGUAGE CPP,BangPatterns #-} | |||
{-# LANGUAGE OverloadedStrings #-} | |||
{-# LANGUAGE MultiWayIf #-} | |||
{-# OPTIONS_GHC -fsimpl-tick-factor=150 #-} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find much on what this means -- can you elaborate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we delete this line, GHC fails to compile this module like this:
ghc: panic! (the 'impossible' happened)
(GHC version 8.0.2 for x86_64-apple-darwin):
Simplifier ticks exhausted
When trying UnfoldingDone $fNumInt_$c+
To increase the limit, use -fsimpl-tick-factor=N (default 100)
If you need to do this, let GHC HQ know, and what factor you needed
To see detailed counts use -ddump-simpl-stats
Total ticks: 196000
See -fsimpl-tick-factor for the explanation of this flag. I've increased it from 100 to 150 to avoid this panic. https://ghc.haskell.org/trac/ghc/ticket/11263 is a similar issue.
I haven't tracked down the root cause but I think it's benign as we have neither custom RULES
nor INLINE
s in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for reviewing this. I'm going to extend the Haddock comment on readHeader
.
Done leftover -> Right (header, BL.Chunk leftover bytes) | ||
_ -> fail "readHeader: unexpected decoder" | ||
Consume k -> case bytes of | ||
BL.Empty -> fail "readHeader: not enough bytes" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right. For incremental parsing of a header, one should use decodeHeader
. Maybe I should mention this behavior in the Haddock comment.
src/GHC/RTS/Events/Incremental.hs
Outdated
-- | Serialises an 'EventLog' back to a 'ByteString', usually for writing it | ||
-- back to a file. | ||
serialiseEventLog :: EventLog -> BL.ByteString | ||
serialiseEventLog el@(EventLog _ (Data events)) = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, not really because it hasn't changed aside some code formatting and renaming (isCap
-> mkCap
).
I agree that it's a good thing to write some tests. I guess we start by fixing #14.
src/GHC/RTS/Events.hs
Outdated
@@ -1,6 +1,7 @@ | |||
{-# LANGUAGE CPP,BangPatterns #-} | |||
{-# LANGUAGE OverloadedStrings #-} | |||
{-# LANGUAGE MultiWayIf #-} | |||
{-# OPTIONS_GHC -fsimpl-tick-factor=150 #-} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we delete this line, GHC fails to compile this module like this:
ghc: panic! (the 'impossible' happened)
(GHC version 8.0.2 for x86_64-apple-darwin):
Simplifier ticks exhausted
When trying UnfoldingDone $fNumInt_$c+
To increase the limit, use -fsimpl-tick-factor=N (default 100)
If you need to do this, let GHC HQ know, and what factor you needed
To see detailed counts use -ddump-simpl-stats
Total ticks: 196000
See -fsimpl-tick-factor for the explanation of this flag. I've increased it from 100 to 150 to avoid this panic. https://ghc.haskell.org/trac/ghc/ticket/11263 is a similar issue.
I haven't tracked down the root cause but I think it's benign as we have neither custom RULES
nor INLINE
s in the code.
Thanks for adding the comment. 👍 from me |
Thanks! I'm going to merge this. |
This PR aims to
In order to achieve these, I did
GHC.RTS.Events.Incremental
GHC.RTS.Events.Binary
, which is a hidden module (for now)Also I did some small cleanup and fixed a space leak.
As for reviews, I guess it's easier to understand if you look at each commit in order. The first 9 commits implement the new incremental API, then 3dd58cf and bcb4595 make the API closer to v0.4. Other commits are small cleanup etc.
GHC.RTS.Events.Incremental
While I'm implementing
ghc-events gc (pause|interval)
commands in my gc-stats branch, I found that the current incremental API is a bit awkward to use becausereadEventLogFromFile
has been deprecated and it cannot stream output as it reads events. It cannot stream output because it has toreverse
events.The new incremental API allows
readEventLogFromFile
to stream output and events don't have to be reversed. Also I've retracted the deprecation onreadEventLogFromFile
as it's now able to stream output.GHC.RTS.Events.Binary
This module was necessary to make the API closer to the previous version of ghc-events. I found it a bit strange that the
Incremental
(andEventsIncremental
) module exports eventlog serializers because the serializers don't have anything to do with the incremental decoder.I made the
GHC.RTS.Events.Binary
module and moved all serializers/deserializers into it so it can be used either fromGHC.RTS.Events
andGHC.RTS.Events.Incremental
.Now that we can move the I/O interface (read/writeEventLogFromFile) back to
GHC.RTS.Events
.Breaking changes
GHC.RTS.EventsIncremental
has been rewritten asGHC.RTS.Events.Incremental
ghc-events show
GHC.RTS.Events
doesn't export the parsersPerformance
The performance characteristics of
ghc-events show
has changed. Heap allocation has been greatly reduced. Unfortunately due to the use ofsortEvents
,ghc-events show
still can't run in constant space though.The runtime of
ghc-events inc
has been improved a bit: