From 1a9a2ceaea22bca18424755becd4cb40e751a22b Mon Sep 17 00:00:00 2001 From: aarne Date: Sun, 4 Sep 2005 10:45:37 +0000 Subject: [PATCH] stat; type of imperatives in lib/resource --- doc/gf-history.html | 6 +++++ src/GF/Canon/MkGFC.hs | 6 ++--- src/GF/Grammar/PrGrammar.hs | 5 ++-- src/GF/Shell/HelpFile.hs | 5 ++-- src/GF/UseGrammar/Custom.hs | 8 +++--- src/GF/UseGrammar/Statistics.hs | 44 +++++++++++++++++++++++++++++++++ src/HelpFile | 1 + 7 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 src/GF/UseGrammar/Statistics.hs diff --git a/doc/gf-history.html b/doc/gf-history.html index 362109886..d079c3c2c 100644 --- a/doc/gf-history.html +++ b/doc/gf-history.html @@ -14,6 +14,12 @@ Changes in functionality since May 17, 2005, release of GF Version 2.2

+4/9 (AR) Added the option pg -printer=stat to show +statistics of gfc compilation result. To be extended with new information. +The most important stats now are the top-40 sized definitions. + +

+ 1/7 Release of GF 2.3.

diff --git a/src/GF/Canon/MkGFC.hs b/src/GF/Canon/MkGFC.hs index 81706e9b7..69ccc3034 100644 --- a/src/GF/Canon/MkGFC.hs +++ b/src/GF/Canon/MkGFC.hs @@ -5,16 +5,16 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/05/30 21:08:14 $ +-- > CVS $Date: 2005/09/04 11:45:38 $ -- > CVS $Author: aarne $ --- > CVS $Revision: 1.15 $ +-- > CVS $Revision: 1.16 $ -- -- (Description of the module) ----------------------------------------------------------------------------- module GF.Canon.MkGFC (prCanonModInfo, prCanon, prCanonMGr, canon2grammar, grammar2canon, -- buildCanonGrammar, - info2mod, + info2mod,info2def, trExp, rtExp, rtQIdent) where import GF.Canon.GFC diff --git a/src/GF/Grammar/PrGrammar.hs b/src/GF/Grammar/PrGrammar.hs index a5471d6ea..905eb39f4 100644 --- a/src/GF/Grammar/PrGrammar.hs +++ b/src/GF/Grammar/PrGrammar.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/05/30 18:39:44 $ +-- > CVS $Date: 2005/09/04 11:45:38 $ -- > CVS $Author: aarne $ --- > CVS $Revision: 1.15 $ +-- > CVS $Revision: 1.16 $ -- -- AR 7\/12\/1999 - 1\/4\/2000 - 10\/5\/2003 -- @@ -107,6 +107,7 @@ instance Print A.Case where prt = C.printTree instance Print A.CType where prt = C.printTree instance Print A.Label where prt = C.printTree instance Print A.Module where prt = C.printTree +instance Print A.Def where prt = C.printTree instance Print A.Canon where prt = C.printTree instance Print A.Sort where prt = C.printTree diff --git a/src/GF/Shell/HelpFile.hs b/src/GF/Shell/HelpFile.hs index 8d427753a..c530e459f 100644 --- a/src/GF/Shell/HelpFile.hs +++ b/src/GF/Shell/HelpFile.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/07/01 19:54:09 $ +-- > CVS $Date: 2005/09/04 11:45:38 $ -- > CVS $Author: aarne $ --- > CVS $Revision: 1.9 $ +-- > CVS $Revision: 1.10 $ -- -- Help on shell commands. Generated from HelpFile by 'make help'. -- PLEASE DON'T EDIT THIS FILE. @@ -523,6 +523,7 @@ txtHelpFile = "\n -printer=fullform full-form lexicon, short format" ++ "\n *-printer=xml XML: DTD for the pg command, object for st" ++ "\n -printer=old old GF: file readable by GF 1.2" ++ + "\n -printer=stat show some statistics of generated GFC" ++ "\n" ++ "\n-startcat, like -cat, but used in grammars (to avoid clash with keyword cat)" ++ "\n" ++ diff --git a/src/GF/UseGrammar/Custom.hs b/src/GF/UseGrammar/Custom.hs index 2e54bcb18..c952bcd5c 100644 --- a/src/GF/UseGrammar/Custom.hs +++ b/src/GF/UseGrammar/Custom.hs @@ -5,9 +5,9 @@ -- Stability : (stable) -- Portability : (portable) -- --- > CVS $Date: 2005/09/01 09:53:19 $ --- > CVS $Author: peb $ --- > CVS $Revision: 1.69 $ +-- > CVS $Date: 2005/09/04 11:45:38 $ +-- > CVS $Author: aarne $ +-- > CVS $Revision: 1.70 $ -- -- A database for customizable GF shell commands. -- @@ -61,6 +61,7 @@ import GF.Speech.PrSLF (slfPrinter) import GF.Data.Zipper +import GF.UseGrammar.Statistics import GF.UseGrammar.Morphology import GF.API.GrammarToHaskell -----import GrammarToCanon (showCanon, showCanonOpt) @@ -249,6 +250,7 @@ customGrammarPrinter = ,(strCI "opts", prOpts . stateOptions) ,(strCI "words", unwords . stateGrammarWords) ,(strCI "printnames", C.prPrintnamesGrammar . stateGrammarST) + ,(strCI "stat", prStatistics . stateGrammarST) {- ---- (strCI "gf", prt . st2grammar . stateGrammarST) -- DEFAULT ,(strCI "canon", showCanon "Lang" . stateGrammarST) diff --git a/src/GF/UseGrammar/Statistics.hs b/src/GF/UseGrammar/Statistics.hs new file mode 100644 index 000000000..46e4fcc3b --- /dev/null +++ b/src/GF/UseGrammar/Statistics.hs @@ -0,0 +1,44 @@ +---------------------------------------------------------------------- +-- | +-- Module : Statistics +-- Maintainer : AR +-- Stability : (stable) +-- Portability : (portable) +-- +-- > CVS $Date: 2005/09/04 11:45:38 $ +-- > CVS $Author: aarne $ +-- > CVS $Revision: 1.1 $ +-- +-- statistics on canonical grammar: amounts of generated code +-- AR 4\/9\/2005. +-- uses canonical grammar +----------------------------------------------------------------------------- + +module GF.UseGrammar.Statistics (prStatistics) where + +import GF.Infra.Modules +import GF.Infra.Option +import GF.Grammar.PrGrammar +import GF.Canon.GFC +import GF.Canon.MkGFC + +import GF.Data.Operations + +import Data.List (sortBy) + +-- | the top level function +prStatistics :: CanonGrammar -> String +prStatistics can = unlines $ [ + show (length mods) ++ "\t\t modules", + show chars ++ "\t\t gfc size", + "", + "Top 40 definitions" + ] ++ + [show d ++ "\t\t " ++ f | (d,f) <- tops] + where + tops = take 40 $ reverse $ sortBy (\ (i,_) (j,_) -> compare i j) defs + defs = [(length (prt (info2def j)), name m j) | (m,j) <- infos] + infos = [(m,j) | (m,ModMod mo) <- mods, j <- tree2list (jments mo)] + name m (f,_) = prt m ++ "." ++ prt f + mods = modules can + chars = length $ prCanon can diff --git a/src/HelpFile b/src/HelpFile index 299655688..edc5bef9c 100644 --- a/src/HelpFile +++ b/src/HelpFile @@ -494,6 +494,7 @@ q, quit: q -printer=fullform full-form lexicon, short format *-printer=xml XML: DTD for the pg command, object for st -printer=old old GF: file readable by GF 1.2 + -printer=stat show some statistics of generated GFC -startcat, like -cat, but used in grammars (to avoid clash with keyword cat)