Skip to content

Commit 7638e5f

Browse files
committed
Add serialisation code for required types.
- Locking travis to stackage. - Fixed coverall.io integration. closes #1
1 parent 952a89f commit 7638e5f

File tree

12 files changed

+592
-82
lines changed

12 files changed

+592
-82
lines changed

.ghci

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
import System.FSNotify
2-
import Data.String
3-
import Control.Concurrent.MVar
4-
import Control.Concurrent
5-
61
:{
7-
:def test const (withManager (\manager ->
8-
do putStrLn "Listening to changes, press any key to stop..."
9-
lock <- newEmptyMVar
10-
watchTree manager (fromString ".") (const True) (const $ putMVar lock True)
11-
forkIO (getLine >> putMVar lock False)
12-
rerun <- readMVar lock
13-
return $ if rerun
14-
then ":reload \n :main \n :test"
15-
else ""
16-
))
2+
:def test const (
3+
do putStrLn "Press any key to run tests, q to stop..."
4+
x <- getLine
5+
return $ if (x == "q")
6+
then ""
7+
else ":reload \n :main \n :test"
8+
)
179
:}

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@ cabal-dev
99
.hpc
1010
cabal.sandbox.config
1111
*.log
12-
.#*
12+
.#*
13+
*.iml
14+
q/
15+
.idea
16+
out/
17+
report.html

.travis.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ before_install:
55
- cabal install hpc-coveralls --avoid-reinstalls
66

77
script:
8+
- cat cabal.config >> ~/.cabal/config # use stackage - find a better way to do this
9+
- cabal update
10+
- cabal install --only-dependencies --enable-tests
811
- cabal configure --enable-tests --enable-library-coverage
912
- cabal build
1013
- run-cabal-test --show-details=always
1114

1215
after_script:
13-
- hpc-coveralls --exclude-dir=tests kdb-haskell-hpc
16+
- hpc-coveralls --exclude-dir=tests kdb-haskell-tests

benchmarks/Benchmark.hs

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE BangPatterns, OverloadedStrings #-}
12
-----------------------------------------------------------------------------
23
-- |
34
-- Module : Benchmark
@@ -11,15 +12,80 @@
1112
module Main where
1213

1314
import Criterion.Main
15+
import Data.Int (Int16)
16+
import Database.Kdb.Internal.Types (Value(..), cV, s, li)
17+
import Foreign.C.Types (CChar)
18+
import Text.Printf (printf)
19+
import qualified Control.Monad as CM (forM_)
20+
import qualified Data.ByteString.Char8 as C
21+
import qualified Data.Vector as V
22+
import qualified Data.Vector.Storable as SV
23+
import qualified Data.Vector.Storable.Mutable as MSV
24+
import qualified Database.Kdb.Internal.Types as KT
25+
import qualified Database.Kdb.Internal.IPC as IPC
1426

15-
fib :: Int -> Int
16-
fib 0 = 0
17-
fib 1 = 1
18-
fib n = fib (n-1) + fib (n-2)
27+
-- Unsafe stuff
28+
import System.IO.Unsafe (unsafePerformIO)
29+
30+
-- Networking
31+
import Network.Socket hiding (recv)
32+
import Network.Socket.ByteString (recv, sendAll)
33+
34+
fillS :: [[CChar]] -> Value
35+
fillS x = let (x',y') = createS x
36+
in SV x' y'
37+
{-# INLINE fillS #-}
38+
39+
createS :: [[CChar]] -> (Int, SV.Vector CChar)
40+
createS cl = unsafePerformIO $ do
41+
v <- MSV.new (Prelude.length . Prelude.concat $ cl)
42+
fill v 0 $ Prelude.concat cl
43+
SV.unsafeFreeze v >>= \x -> return (Prelude.length cl,x)
44+
where
45+
fill _ _ [] = return ()
46+
fill v i (x:xs) = MSV.unsafeWrite v i x >> fill v (i + 1) xs
47+
48+
-- | Constructor for T - a Q table - we must always build it using this function
49+
-- 2 bytes for table header - 1 additional byte for dict type header
50+
fillT :: V.Vector Value -> Value
51+
fillT !xs = T (V.foldl' (\x y -> x + KT.size y) 3 xs) xs
52+
{-# INLINE fillT #-}
53+
54+
-- function to convert list of bytestring into hex digits - useful for debugging kx IPC bytes
55+
bprint :: C.ByteString -> String
56+
bprint x = ("0x" ++ ) $ foldl (++) "" $ fmap (printf "%02x") $ C.unpack x
1957

2058
main :: IO ()
21-
main = defaultMain [
22-
bench "fib 10" $ nf (\n -> fib (10+n-n)) 10
23-
, bench "fib 30" $ nf (\n -> fib (30+n-n)) 30
24-
, bench "fib 35" $ nf (\n -> fib (35+n-n)) 35
59+
main = do
60+
let shortv = HV (SV.fromList[1..10]) -- short list - for benchmark testing
61+
il1 = IV $ SV.enumFromN 1 5000000 -- list of int
62+
il2 = IV $ SV.enumFromN 1 5000000 -- list of int
63+
il3 = IV $ SV.enumFromN 1 5000000 -- list of int
64+
l1 = L (V.fromList [il1,il2,il3]) -- general list of int
65+
sl1 = fillS [[97,0],[98,0],[99,0]] -- symbol list: `a`b`c
66+
t = fillT (V.fromList [sl1,l1]) -- table t:([] a:til 5000000;b:til 5000000;c:til 5000000)
67+
sl2 = s "t" -- atomic symbol `t
68+
cl1 = cV "insert" -- string ".u.insert"
69+
gl1 = li [cl1,sl2,t] -- general list (".u.insert";`t;t). t is the table from above
70+
{--
71+
defaultMain [
72+
bench "ShortV" $ whnf SV.fromList ([1..10]::[Int16])
73+
,bench "IPC.qIPC ShortV" $ whnf (IPC.qIPC 0) (HV (SV.fromList[1..10]))
74+
--,bench "foldl T" $ whnf (V.foldl' (\x y -> x + size y) 3) (V.fromList [sl1,l1])
75+
,bench "fillT" $ whnf fillT (V.fromList [sl1,l1])
76+
,bench "fillS" $ whnf fillS [[97,0],[98,0],[99,0]]
77+
,bench "IPC.qIPC Taable" $ whnf (IPC.qIPC 0) t
78+
,bench "IPC.qIPC General List" $ whnf (IPC.qIPC 0) gl1
2579
]
80+
--}
81+
addrinfos <- getAddrInfo Nothing (Just "127.0.0.1") (Just "7777")
82+
let serveraddr = head addrinfos
83+
sock <- socket (addrFamily serveraddr) Stream defaultProtocol
84+
connect sock (addrAddress serveraddr)
85+
sendAll sock "user:pwd\1\0"
86+
msg <- recv sock 1024
87+
print "Received authentication"
88+
print $ bprint msg
89+
CM.forM_ [1..1] $ \x -> sendAll sock $ IPC.asyncIPC gl1
90+
sClose sock
91+

cabal.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- Lock the package database
2+
remote-repo: stackage:http://www.stackage.org/stackage/7cbdc905d399a45de2128a2d8e67e22636f309a1

kdb-haskell.cabal

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
name: kdb-haskell
23
version: 0.1.0
34
synopsis: Haskell bindings for KDB+.
@@ -29,67 +30,47 @@ flag documentation
2930
False
3031

3132
library
32-
exposed-modules: Database.Kdb.Types
33+
exposed-modules:
34+
other-modules: Database.Kdb.Internal.Types
35+
, Database.Kdb.Internal.IPC
3336
default-language: Haskell2010
3437
build-depends: base >= 4 && < 5
3538
, mtl
3639
, bytestring
40+
, vector
3741
, text
3842
, containers
3943
, binary
4044
, lens
41-
, QuickCheck == 2.6.*
45+
, QuickCheck
4246
, directory
4347
hs-source-dirs: src
4448
ghc-options: -Wall
4549
-fwarn-incomplete-patterns
4650
-funbox-strict-fields
4751

48-
test-suite kdb-haskell-hpc
49-
main-is: Test.hs
50-
type: exitcode-stdio-1.0
51-
build-depends: base
52-
, bytestring
53-
, containers
54-
, text
55-
, time
56-
, binary
57-
, mtl
58-
, lens
59-
, tasty == 0.8
60-
, tasty-quickcheck == 0.8
61-
, QuickCheck == 2.6.*
62-
, Cabal >= 1.9.2
63-
Ghc-Options: -Wall
64-
-O0
65-
-fhpc
66-
-hpcdir
67-
dist/hpc/mix/kdb-haskell-hpc
68-
-funbox-strict-fields
69-
hs-source-dirs: src
70-
, tests
71-
7252
test-suite kdb-haskell-tests
7353
hs-source-dirs: src
7454
, tests
7555
main-is: Test.hs
7656
type: exitcode-stdio-1.0
7757
build-depends: base
7858
, bytestring
59+
, base16-bytestring
7960
, containers
61+
, vector
8062
, text
8163
, time
8264
, binary
8365
, mtl
8466
, lens
85-
, tasty == 0.8
86-
, tasty-quickcheck == 0.8
87-
, QuickCheck == 2.6.*
88-
, Cabal >= 1.9.2
89-
-- Dependencies for rerunning tests in ghci
90-
, fsnotify >= 0.0.11
91-
, system-filepath >= 0.4.7
92-
Ghc-Options: -Wall
67+
-- Testing
68+
, tasty
69+
, tasty-quickcheck
70+
, tasty-hunit
71+
, QuickCheck
72+
, Cabal
73+
Ghc-Options: -Wall
9374
-O0
9475
-funbox-strict-fields
9576

@@ -100,6 +81,9 @@ benchmark kdb-haskell-benchmark
10081
main-is: Benchmark.hs
10182
build-depends: base
10283
, mtl
84+
, vector
85+
, bytestring
86+
, network
10387
, criterion
10488
, random
10589
ghc-options: -Wall

0 commit comments

Comments
 (0)