From 3cd67c0f8d541aac8419ab589621450aaede8165 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Fri, 6 Oct 2017 11:45:26 -0700 Subject: [PATCH] Stat node counts of term and diff --- src/Semantic.hs | 5 ++++- src/Semantic/Task.hs | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Semantic.hs b/src/Semantic.hs index b75ac4d05..5cde16a70 100644 --- a/src/Semantic.hs +++ b/src/Semantic.hs @@ -16,6 +16,7 @@ import Data.ByteString (ByteString) import Data.Diff import Data.Functor.Both as Both import Data.Output +import Data.Bifoldable import Data.Record import Data.Syntax.Algebra import Data.Term @@ -26,6 +27,7 @@ import qualified Language import Parser import Renderer import Semantic.Task as Task +import Semantic.Stat as Stat -- This is the primary interface to the Semantic library which provides two -- major classes of functionality: semantic parsing and diffing of source code @@ -108,11 +110,12 @@ diffBlobPair renderer blobs = case (renderer, effectiveLanguage) of (Blob { blobPath = path }, _) -> (path, Nothing) syntaxParser = effectiveLanguage >>= parserForLanguage - run :: Functor syntax => (Blob -> Task (Term syntax ann)) -> (Term syntax ann -> Term syntax ann -> Diff syntax ann ann) -> (Diff syntax ann ann -> output) -> Task output + run :: (Foldable syntax, Functor syntax) => (Blob -> Task (Term syntax ann)) -> (Term syntax ann -> Term syntax ann -> Diff syntax ann ann) -> (Diff syntax ann ann -> output) -> Task output run parse diff renderer = do terms <- distributeFor blobs parse time "diff" languageTag $ do diff <- runBothWith (diffTermPair blobs diff) terms + writeStat (Stat.count "diff.nodes" (bilength diff) languageTag) render renderer diff where showLanguage = pure . (,) "language" . show diff --git a/src/Semantic/Task.hs b/src/Semantic/Task.hs index fc90f35df..5100b56d7 100644 --- a/src/Semantic/Task.hs +++ b/src/Semantic/Task.hs @@ -216,6 +216,7 @@ runParser Options{..} blob@Blob{..} = go for_ (errors term) $ \ err -> do writeStat (Stat.increment "parse.parse_errors" languageTag) writeLog Warning (Error.formatError optionsPrintSource (optionsIsTerminal && optionsEnableColour) blob err) (("tag", "assign") : blobFields) + writeStat (Stat.count "parse.nodes" (length term) languageTag) pure term TreeSitterParser tslanguage -> time "parse.tree_sitter_parse" languageTag $