Created
July 24, 2019 01:04
-
-
Save enolan/55c7288fbdd1c08d11bd1393f2dc1d2b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stack | |
-- stack --resolver lts-13.29 script --package regex-tdfa,conduit,bytestring,random-fu | |
-- Given a perf 'script', as emitted by 'perf script -i perf.data', subsample | |
-- at 0.1 probability to make the script small enough to load into e.g. | |
-- speedscope. | |
{-# LANGUAGE OverloadedStrings, ScopedTypeVariables #-} | |
import Conduit | |
import Data.ByteString (ByteString) | |
import Data.Random | |
import Data.Random.Distribution | |
import Data.Random.Distribution.Bernoulli | |
main = runConduit $ stdinC .| linesUnboundedAsciiC .| splitSamples .| unlinesAsciiC .| stdoutC | |
splitSamples :: ConduitT ByteString ByteString IO () | |
splitSamples = do | |
done <- nullC | |
if not done | |
then do | |
take :: Bool <- lift $ sample $ bernoulli (0.1 :: Float) | |
if take | |
then do | |
takeWhileC (/= "") | |
takeC 1 | |
splitSamples | |
else do | |
dropWhileC (/= "") | |
dropC 1 | |
splitSamples | |
else pure () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment