Skip to content

Commit e6c314f

Browse files
committed
getLastBuildKeys
1 parent f9bec8b commit e6c314f

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

hls-graph/src/Development/IDE/Graph/Database.hs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ module Development.IDE.Graph.Database(
88
shakeRunDatabase,
99
shakeRunDatabaseForKeys,
1010
shakeProfileDatabase,
11-
) where
11+
shakeLastBuildKeys) where
1212

1313
import Data.Dynamic
1414
import Data.Maybe
15-
import Development.IDE.Graph.Classes ()
15+
import Development.IDE.Graph.Classes ()
1616
import Development.IDE.Graph.Internal.Action
1717
import Development.IDE.Graph.Internal.Database
1818
import Development.IDE.Graph.Internal.Options
19-
import Development.IDE.Graph.Internal.Profile (writeProfile)
19+
import Development.IDE.Graph.Internal.Profile (getLastBuildKeys,
20+
writeProfile)
2021
import Development.IDE.Graph.Internal.Rules
2122
import Development.IDE.Graph.Internal.Types
2223

@@ -38,6 +39,10 @@ shakeNewDatabase opts rules = do
3839
shakeRunDatabase :: ShakeDatabase -> [Action a] -> IO ([a], [IO ()])
3940
shakeRunDatabase = shakeRunDatabaseForKeys Nothing
4041

42+
shakeLastBuildKeys :: ShakeDatabase -> IO [Key]
43+
shakeLastBuildKeys (ShakeDatabase _ _ db) = getLastBuildKeys db
44+
45+
4146
-- Only valid if we never pull on the results, which we don't
4247
unvoid :: Functor m => m () -> m a
4348
unvoid = fmap undefined

hls-graph/src/Development/IDE/Graph/Internal/Profile.hs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{-# LANGUAGE CPP #-}
2+
{-# LANGUAGE DeriveFunctor #-}
23
{-# LANGUAGE RecordWildCards #-}
34
{-# LANGUAGE ViewPatterns #-}
45

56
{- HLINT ignore "Redundant bracket" -} -- a result of CPP expansion
67

7-
module Development.IDE.Graph.Internal.Profile (writeProfile) where
8+
module Development.IDE.Graph.Internal.Profile (writeProfile,getProfile,getLastBuildKeys) where
89

910
import Data.Bifunctor
1011
import qualified Data.ByteString.Lazy.Char8 as LBS
@@ -41,17 +42,28 @@ import Data.FileEmbed
4142
import Language.Haskell.TH.Syntax (runIO)
4243
#endif
4344

44-
-- | Generates an report given some build system profiling data.
45-
writeProfile :: FilePath -> Database -> IO ()
46-
writeProfile out db = do
45+
getLastBuildKeys :: Database -> IO [Key]
46+
getLastBuildKeys db = do
47+
(rpt, _) <- getProfile db
48+
return [ prfName p | p <- rpt, prfBuilt p == 0]
49+
50+
getProfile :: Database -> IO ([ProfileEntry Key], Maybe [Int])
51+
getProfile db = do
4752
dirtyKeys <- readIORef (databaseDirtySet db)
4853
(report, mapping) <- toReport db
4954
let dirtyKeysMapped = mapMaybe (`IntMap.lookup` mapping) . Set.toList <$> dirtyKeys
50-
rpt <- generateHTML (sort <$> dirtyKeysMapped) report
55+
return (report, dirtyKeysMapped)
56+
57+
-- | Generates an report given some build system profiling data.
58+
writeProfile :: FilePath -> Database -> IO ()
59+
writeProfile out db = do
60+
(report, dirtyKeysMapped) <- getProfile db
61+
rpt <- generateHTML (sort <$> dirtyKeysMapped) ((fmap.fmap) show report)
5162
LBS.writeFile out rpt
5263

53-
data ProfileEntry = ProfileEntry
54-
{prfName :: !String, prfBuilt :: !Int, prfChanged :: !Int, prfVisited :: !Int, prfDepends :: [[Int]], prfExecution :: !Seconds}
64+
data ProfileEntry a = ProfileEntry
65+
{prfName :: !a, prfBuilt :: !Int, prfChanged :: !Int, prfVisited :: !Int, prfDepends :: [[Int]], prfExecution :: !Seconds}
66+
deriving Functor
5567

5668
-- | Eliminate all errors from the database, pretending they don't exist
5769
-- resultsOnly :: Map.HashMap Id (Key, Status) -> Map.HashMap Id (Key, Result (Either BS.ByteString Value))
@@ -104,7 +116,7 @@ prepareForDependencyOrder db = do
104116
<$> Ids.toList (databaseValues db)
105117

106118
-- | Returns a list of profile entries, and a mapping linking a non-error Id to its profile entry
107-
toReport :: Database -> IO ([ProfileEntry], IntMap Int)
119+
toReport :: Database -> IO ([ProfileEntry Key], IntMap Int)
108120
toReport db = do
109121
status <- prepareForDependencyOrder db
110122
let order = let shw i = maybe "<unknown>" (show . fst) $ Map.lookup i status
@@ -118,7 +130,7 @@ toReport db = do
118130
in Map.fromList $ zip (sortBy (flip compare) xs) [0..]
119131

120132
f (k, Result{..}) = ProfileEntry
121-
{prfName = show k
133+
{prfName = k
122134
,prfBuilt = fromStep resultBuilt
123135
,prfVisited = fromStep resultVisited
124136
,prfChanged = fromStep resultChanged
@@ -134,7 +146,7 @@ alwaysRerunResult current = Result (Value $ toDyn "<alwaysRerun>") (Step 0) (Ste
134146
readDataFileHTML :: FilePath -> IO LBS.ByteString
135147
readDataFileHTML file = LBS.readFile =<< getDataFile ("html" </> file)
136148

137-
generateHTML :: Maybe [Int] -> [ProfileEntry] -> IO LBS.ByteString
149+
generateHTML :: Maybe [Int] -> [ProfileEntry String] -> IO LBS.ByteString
138150
generateHTML dirtyKeys xs = do
139151
report <- readDataFileHTML "profile.html"
140152
let f "data/profile-data.js" = pure $ LBS.pack $ "var profile =\n" ++ generateJSONProfile xs
@@ -146,7 +158,7 @@ generateJSONBuild :: Maybe [Ids.Id] -> String
146158
generateJSONBuild (Just dirtyKeys) = jsonList [jsonList (map show dirtyKeys)]
147159
generateJSONBuild Nothing = jsonList []
148160

149-
generateJSONProfile :: [ProfileEntry] -> String
161+
generateJSONProfile :: [ProfileEntry String] -> String
150162
generateJSONProfile = jsonListLines . map showEntry
151163
where
152164
showEntry ProfileEntry{..} = jsonList $

0 commit comments

Comments
 (0)