-
Notifications
You must be signed in to change notification settings - Fork 24
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
Implement -find-nonatomic-writes filter #9
Conversation
This works well for me: normal ghc
fixed ghc
Note the difference in the fixed one: It has no |
Tangential, but very interesting, is that tracing the new GHC is almost 10x faster (2 seconds vs 17 seconds). Using -90.73 4.769502 1 3552745 28 ptrace
+54.17 0.560906 1 417026 28 ptrace Because we use By printing counts of bytes peeked, we investigated which syscalls are responsible for the difference. It turns out it's On older GHCs, access patterns look like this:
and for the new one:
Note how the old GHC This suggests that the new one is somehow much smarter at getting the relevant data out. We also checked which exact program it is that does the reading; that's What could create this difference? One thing I know is that my new-GHC build may be a It seems worth investigating this to know what change/difference makes for this big difference in IO and thus compiler build performance. CC @bgamari Edit: I filed GHC issue https://gitlab.haskell.org/ghc/ghc/issues/16515 for this. |
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.
Reviewed 4 of 4 files at r1.
Reviewable status: all files reviewed, 9 unresolved discussions (waiting on @qrilka)
src/System/Hatrace.hs, line 980 at r1 (raw file):
| FileWrite | FileClose | FileRename ByteString
Haddock if it's the old or new name
src/System/Hatrace.hs, line 988 at r1 (raw file):
-- * only calls to `write` are currently used as a marker for writes and syscalls -- `pwrite`, `writev`, `pwritev` are not taken into account fileWritesConduit :: (MonadIO m) => ConduitT (CPid, TraceEvent) (FilePath, FileWriteEvent) m ()
Add nice explanation
src/System/Hatrace.hs, line 1019 at r1 (raw file):
yieldFdEvent pid fd FileClose DetailedSyscallEnter_rename SyscallEnterDetails_rename { oldpathBS, newpathBS } -> do path <- liftIO $ resolveToPidCwd pid (T.unpack $ T.decodeUtf8 oldpathBS)
decodeUtf8
is partial and doens't have HasCallStack
yet; add wrapper
src/System/Hatrace.hs, line 1032 at r1 (raw file):
yield (path, event) o_WRONLY = 0o00000001 o_RDWR = 0o00000002
Link some source
src/System/Hatrace.hs, line 1067 at r1 (raw file):
checkWrites' (FileWrite:es) = checkWrites' es checkWrites' (FileClose:es) = checkRename es checkWrites' (e: _) = unexpected "FileClose or FileWrite" e
case
for better readability? Nicer tnames to reflect semantics?
src/System/Hatrace.hs, line 1068 at r1 (raw file):
checkWrites' (FileClose:es) = checkRename es checkWrites' (e: _) = unexpected "FileClose or FileWrite" e checkRename (FileRename path:es) =
Explain this; perhaps :
for readability
src/System/Hatrace.hs, line 1088 at r1 (raw file):
extract <$> (fileWritesConduit .| foldlC collectWrite mempty) where collectWrite m (fp, e) = Map.alter (Just . maybe [e] (e:)) fp m
I recommend some types on the helper functions
src/System/Hatrace.hs, line 1093 at r1 (raw file):
partitionEithers . map (analyzeWrites' . second reverse) $ Map.toList m in Map.fromList noRenames <> Map.fromList (map (second AtomicWrite) renames) analyzeWrites' (src, es) = case analyzeWrites es of
Explain a bit
src/System/Hatrace.hs, line 1094 at r1 (raw file):
in Map.fromList noRenames <> Map.fromList (map (second AtomicWrite) renames) analyzeWrites' (src, es) = case analyzeWrites es of AtomicWrite target -> Right (target, src)
Terminology rename()
further up, then here AtomicWrite
, and then renames
again -- warrants 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.
Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @qrilka)
src/System/Hatrace.hs, line 980 at r1 (raw file):
Previously, nh2 (Niklas Hambüchen) wrote…
Haddock if it's the old or new name
Done
src/System/Hatrace.hs, line 1019 at r1 (raw file):
Previously, nh2 (Niklas Hambüchen) wrote…
decodeUtf8
is partial and doens't haveHasCallStack
yet; add wrapper
Done
Here's the output of the new tool on Click to expand outputs
To be analysed in and after commercialhaskell/stack#4559 (comment). |
Using this filtering on other syscalls requires tracking file open modes which complicate the code
88f7ca1
to
d76f533
Compare
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.
Reviewable status: 0 of 5 files reviewed, 6 unresolved discussions (waiting on @nh2)
src/System/Hatrace.hs, line 988 at r1 (raw file):
Previously, nh2 (Niklas Hambüchen) wrote…
Add nice explanation
Done.
src/System/Hatrace.hs, line 1032 at r1 (raw file):
Previously, nh2 (Niklas Hambüchen) wrote…
Link some source
removed in the end
src/System/Hatrace.hs, line 1068 at r1 (raw file):
Previously, nh2 (Niklas Hambüchen) wrote…
Explain this; perhaps
:
for readability
Done.
src/System/Hatrace.hs, line 1088 at r1 (raw file):
Previously, nh2 (Niklas Hambüchen) wrote…
I recommend some types on the helper functions
Done.
src/System/Hatrace.hs, line 1093 at r1 (raw file):
Previously, nh2 (Niklas Hambüchen) wrote…
Explain a bit
Done.
src/System/Hatrace.hs, line 1094 at r1 (raw file):
Previously, nh2 (Niklas Hambüchen) wrote…
Terminology
rename()
further up, then hereAtomicWrite
, and thenrenames
again -- warrants comment
Done.
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.
Reviewable status: 0 of 5 files reviewed, 6 unresolved discussions (waiting on @nh2)
src/System/Hatrace.hs, line 1032 at r1 (raw file):
Previously, qrilka (Kirill Zaborsky) wrote…
removed in the end
Done.
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.
Reviewed 1 of 5 files at r2, 3 of 4 files at r3, 1 of 1 files at r5.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @qrilka)
src/System/Hatrace.hs, line 1007 at r5 (raw file):
deriving (Eq, Ord, Show) -- | Uses raw trace events to produces more focused events aimed at analysing file writes.
typo produce
src/System/Hatrace.hs, line 1095 at r5 (raw file):
unexpected : _ -> unexpectedEvent "FileClose or FileWrite" unexpected -- when it happens that a path gets more than 1 sequence open-write-close -- for it we need to check whethere there was a `rename` after the 1st one
typo whether
d76f533
to
73c4f0d
Compare
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.
Reviewed 1 of 1 files at r6.
Reviewable status: complete! all files reviewed, all discussions resolved
I filed GHC issue https://gitlab.haskell.org/ghc/ghc/issues/16515 for the investigation of GHC linker performance. |
stack run -- hatrace --find-nonatomic-writes stack test
onhatrace
itself ended up withtest failure and many nonatomically written files
This change is