Julia functions to calculate
- Shannon Entropy
- Monte Carlo Pi-Deviation
- Chi-Squard
- Install julia from source or with your preferred package manager.
julia -e 'using Pkg; Pkg.add(PackageSpec(url="https://github.com/z4rd0s/StreamStats.jl"))'
- Execute julia
using StreamStats
random(n) = rand(UInt8, n)
data = StreamStats.get_all(random(1000))
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
python -c "import julia; julia.install()"
Python 3.6.10 (default, Jan 16 2020, 09:12:04) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> from julia.api import Julia
>>> Julia(compiled_modules=False)
>>> from julia import StreamStats
>>> import os
>>> data = bytearray(os.urandom(1000))
>>> stats = StreamStats.get_all(data)
- Precompile StreamStats.jl
cd bin
cp ../src/StreamStats.jl .
julia --startup-file=no --trace-compile=StreamStats_precompile.jl StreamStats.jl "<anyfile.bin>example.pdf"
- Generate Custom Julia Image containing Precompiled
julia --startup-file=no -J"<path to julia/sys.so>/usr/share/julia-1.4.2/lib/julia/sys.so" --output-o StreamStats-sys.o StreamStats_image_generator.jl
gcc -shared -o StreamStats-sys.so -fPIC -Wl,--whole-archive StreamStats-sys.o -Wl,--no-whole-archive -L"<path to julia/lib>/usr/share/julia-1.4.2/lib/" -ljulia
- Building the executable
gcc -DJULIAC_PROGRAM_LIBNAME=\"StreamStats-sys.so\" -o StreamStats.bin StreamStats.c StreamStats-sys.so -O2 -fPIE -I'<path to julia>/usr/share/julia-1.4.2/include/julia' -L'<path to julia binary>/usr/share/julia-1.4.2/lib' -ljulia -Wl,-rpath,'<path to julia binary at remote destination>/usr/share/julia-1.4.2/lib:$ORIGIN'
- Run the executable StreamStats.bin and StreamStats-sys.so must be executed within the same directory
$ ./StreamStats.bin <path to any file>
import subprocess
import logging
import json
def run(cmd: str) -> bool:
"""Executes a command line locally
:param cmd: The command line string
:type cmd: str
:return: Returns True if the commandline could be exectued
successfully, otherwise False
:rtype: bool
"""
try:
proc = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = proc.communicate(timeout=15)
if proc.returncode == 0:
return output
logging.error("Command <%s> failed", cmd)
return False
except subprocess.TimeoutExpired:
proc.kill()
logging.error("Command <%s> timed out", cmd, exc_info=True)
return False
except Exception:
logging.error("Command <%s> failed", cmd, exc_info=True)
return False
cmd_StreamStats = ["./bin/StreamStats.bin", "./bin/example.pdf"]
data = json.loads(run(cmd_StreamStats))