hs-speedscope 0.2 → 0.2.1
raw patch · 4 files changed
+37/−22 lines, 4 filesdep ~ghc-eventsnew-uploaderPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: ghc-events
API changes (from Hackage documentation)
- HsSpeedscope: EL :: Maybe String -> Maybe (Version, String) -> Maybe Word64 -> [CostCentre] -> [Sample] -> EL
+ HsSpeedscope: EL :: Maybe Text -> Maybe (Version, Text) -> Maybe Word64 -> [CostCentre] -> [Sample] -> EL
- HsSpeedscope: IgnoreUntil :: String -> ReadState -> ReadState
+ HsSpeedscope: IgnoreUntil :: Text -> ReadState -> ReadState
- HsSpeedscope: ReadUntil :: String -> ReadState -> ReadState
+ HsSpeedscope: ReadUntil :: Text -> ReadState -> ReadState
- HsSpeedscope: SSOptions :: FilePath -> Maybe String -> Maybe String -> SSOptions
+ HsSpeedscope: SSOptions :: FilePath -> Maybe Text -> Maybe Text -> SSOptions
- HsSpeedscope: [isolateEnd] :: SSOptions -> Maybe String
+ HsSpeedscope: [isolateEnd] :: SSOptions -> Maybe Text
- HsSpeedscope: [isolateStart] :: SSOptions -> Maybe String
+ HsSpeedscope: [isolateStart] :: SSOptions -> Maybe Text
- HsSpeedscope: [prog_name] :: EL -> Maybe String
+ HsSpeedscope: [prog_name] :: EL -> Maybe Text
- HsSpeedscope: [rts_version] :: EL -> Maybe (Version, String)
+ HsSpeedscope: [rts_version] :: EL -> Maybe (Version, Text)
- HsSpeedscope: convertToSpeedscope :: (Maybe String, Maybe String) -> EventLog -> Value
+ HsSpeedscope: convertToSpeedscope :: (Maybe Text, Maybe Text) -> EventLog -> Value
- HsSpeedscope: initState :: Maybe String -> Maybe String -> ReadState
+ HsSpeedscope: initState :: Maybe Text -> Maybe Text -> ReadState
- HsSpeedscope: mkProfile :: String -> Word64 -> (Capset, [[Int]]) -> Value
+ HsSpeedscope: mkProfile :: Text -> Word64 -> (Capset, [[Int]]) -> Value
- HsSpeedscope: parseIdent :: String -> Maybe (Version, String)
+ HsSpeedscope: parseIdent :: Text -> Maybe (Version, Text)
- HsSpeedscope: transition :: String -> ReadState -> ReadState
+ HsSpeedscope: transition :: Text -> ReadState -> ReadState
Files
- CHANGELOG.md +4/−0
- README.md +10/−1
- hs-speedscope.cabal +2/−2
- src/HsSpeedscope.hs +21/−19
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for hs-speedscope +## 0.2.1 -- 2020-12-19++* Support ghc-events 0.13, 0.14 and 0.15.+ ## 0.2 -- 2020-03-21 * Add --start and --end options which allow a profile to be filtered by
README.md view
@@ -10,6 +10,15 @@ 2. Run `hs-speedscope` on the resulting eventlog `hs-speedscope program.eventlog`. 3. Load the resulting `program.eventlog.json` file into [speedscope](https://speedscope.app) to visualise the profile. +## Installation++```shell+cabal update+cabal install exe:hs-speedscope+```++This will install to cabal's per-user default location: `~/.cabal/bin/hs-speedscope`.+ ## Filtering an eventlog It is sometimes useful to isolate a specific part of the sample, for example, when@@ -26,7 +35,7 @@ For example, the following invocation will filter the profile between the START and END markers. -```+```shell hs-speedscope File.eventlog --start START --end END ```
hs-speedscope.cabal view
@@ -4,7 +4,7 @@ -- http://haskell.org/cabal/users-guide/ name: hs-speedscope-version: 0.2+version: 0.2.1 synopsis: Convert an eventlog into the speedscope json format description: Convert an eventlog into the speedscope json format. The interactive visualisation displays an approximate trace of the program and summary views akin to .prof files.@@ -32,7 +32,7 @@ -- other-modules: -- other-extensions: build-depends: base >= 4.12.0.0 && < 5,- ghc-events >= 0.11 && < 0.13,+ ghc-events >= 0.13 && < 0.16, aeson >= 1.4, text >= 1.2, vector >= 0.12,
src/HsSpeedscope.hs view
@@ -8,6 +8,7 @@ import Data.Word import Data.Text (Text)+import qualified Data.Text import qualified Data.Vector.Unboxed as V import Data.Maybe import Data.List.Extra@@ -20,12 +21,11 @@ import Options.Applicative hiding (optional) import qualified Options.Applicative as O-import Data.Semigroup ((<>)) data SSOptions = SSOptions { file :: FilePath- , isolateStart :: Maybe String- , isolateEnd :: Maybe String+ , isolateStart :: Maybe Text+ , isolateEnd :: Maybe Text } deriving Show @@ -59,8 +59,8 @@ data ReadState = ReadAll -- Ignore all future- | IgnoreUntil String ReadState- | ReadUntil String ReadState+ | IgnoreUntil Text ReadState+ | ReadUntil Text ReadState | IgnoreAll deriving Show shouldRead :: ReadState -> Bool@@ -68,18 +68,18 @@ shouldRead (ReadUntil {}) = True shouldRead _ = False -transition :: String -> ReadState -> ReadState+transition :: Text -> ReadState -> ReadState transition s r = case r of- (ReadUntil is n) | is `isPrefixOf` s -> n- (IgnoreUntil is n) | is `isPrefixOf` s -> n+ (ReadUntil is n) | is `Data.Text.isPrefixOf` s -> n+ (IgnoreUntil is n) | is `Data.Text.isPrefixOf` s -> n _ -> r -initState :: Maybe String -> Maybe String -> ReadState+initState :: Maybe Text -> Maybe Text -> ReadState initState Nothing Nothing = ReadAll initState (Just s) e = IgnoreUntil s (initState Nothing e) initState Nothing (Just e) = ReadUntil e IgnoreAll -convertToSpeedscope :: (Maybe String, Maybe String) -> EventLog -> Value+convertToSpeedscope :: (Maybe Text, Maybe Text) -> EventLog -> Value convertToSpeedscope (is, ie) (EventLog _h (Data (sortOn evTime -> es))) = case el_version of Just (ghc_version, _) | ghc_version < makeVersion [8,9,0] ->@@ -142,7 +142,7 @@ (UserMarker m) -> (transition m do_sample, el) _ -> (do_sample, el) -mkProfile :: String -> Word64 -> (Capset, [[Int]]) -> Value+mkProfile :: Text -> Word64 -> (Capset, [[Int]]) -> Value mkProfile pname interval (_n, samples) = object [ "type" .= ("sampled" :: String) , "unit" .= ("nanoseconds" :: String)@@ -155,23 +155,25 @@ sample_weights :: [Word64] sample_weights = replicate (length samples) interval -parseIdent :: String -> Maybe (Version, String)-parseIdent s = listToMaybe $ flip readP_to_S s $ do+parseIdent :: Text -> Maybe (Version, Text)+parseIdent s = convert $ listToMaybe $ flip readP_to_S (Data.Text.unpack s) $ do void $ string "GHC-" [v1, v2, v3] <- replicateM 3 (intP <* optional (char '.')) skipSpaces- return (makeVersion [v1,v2,v3])+ return $ makeVersion [v1,v2,v3] where intP = do x <- munch1 isDigit return $ read x + convert x = (\(a, b) -> (a, Data.Text.pack b)) <$> x+ data EL = EL {- prog_name :: Maybe String- , rts_version :: Maybe (Version, String)- , prof_interval :: Maybe Word64- , cost_centres :: [CostCentre]- , el_samples :: [Sample]+ prog_name :: Maybe Text+ , rts_version :: Maybe (Version, Text)+ , prof_interval :: Maybe Word64+ , cost_centres :: [CostCentre]+ , el_samples :: [Sample] } data CostCentre = CostCentre Word32 Text Text Text deriving Show