Skip to content

Instantly share code, notes, and snippets.

@enolan
Created July 24, 2019 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enolan/55c7288fbdd1c08d11bd1393f2dc1d2b to your computer and use it in GitHub Desktop.
Save enolan/55c7288fbdd1c08d11bd1393f2dc1d2b to your computer and use it in GitHub Desktop.
#!/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