Skip to content

Commit f786752

Browse files
committed
Adding lua hello world
1 parent fff2cc8 commit f786752

File tree

3 files changed

+46
-16
lines changed

3 files changed

+46
-16
lines changed

FreeBSD/flamegraph.sh

+18-16
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ die() {
99
echo "$@" >&2
1010
exit 1
1111
}
12+
1213
if [ "$(id -u)" != "0" ]; then
1314
die "Need to be root for runnig pmcstat"
1415
fi
@@ -31,22 +32,23 @@ case "${cpu}" in
3132
die "Unknow CPU (${cpu})"
3233
esac
3334

34-
# Load Hardware Performance Monitoring Counter module
35-
kldstat -q -m hwpmc || kldload hwpmc
35+
echo "${cpu} detected, using ${counter} PMC counter"
36+
37+
if ! kldstat -q -m hwpmc; then
38+
echo "Loading Hardware Peformance Monitoring Counter (hwpmc) kernel module..."
39+
kldload hwpmc
40+
fi
3641

37-
# Delete existing log files
38-
for f in /tmp/pmc.*.log /tmp/flamegraph.svg; do
39-
rm -rf "${f}"
40-
done
42+
tmpdir=$(mktemp -d -t flame)
4143

42-
# Collect system stats
43-
pmcstat -z ${graphdepth} -l ${seconds} -S ${counter} -O /tmp/pmc.raw.log
44-
# Generate system-wide profile with callgraphs
45-
pmcstat -z ${graphdepth} -R /tmp/pmc.raw.log -G /tmp/pmc.callgraph.log
44+
echo "Collecting hwpmc for ${seconds} seconds..."
45+
pmcstat -z ${graphdepth} -l ${seconds} -S ${counter} -O ${tmpdir}/pmc.raw.log
46+
echo "Generate system-wide profile with callgraphs..."
47+
pmcstat -z ${graphdepth} -R ${tmpdir}/pmc.raw.log -G /${tmpdir}/pmc.callgraph.log
4648

47-
whereis -q stackcollapse-pmc.pl || die "Missing flamegraph package"
48-
# fold stack samples into single lines.
49-
stackcollapse-pmc.pl /tmp/pmc.callgraph.log > /tmp/pmc.folded.log
50-
# Generate flamegraph
51-
flamegraph.pl --title "counter: ${counter}" /tmp/pmc.folded.log > flamegraph.svg
52-
echo "Done: flamegraph generated as /tmp/flamegraph.svg"
49+
whereis -q stackcollapse-pmc.pl || die "Missing benchmarks/flamegraph package"
50+
echo "Fold stack samples into single lines..."
51+
stackcollapse-pmc.pl ${tmpdir}/pmc.callgraph.log > ${tmpdir}/pmc.folded.log
52+
echo "Generating flamegraph svg..."
53+
flamegraph.pl --title "counter: ${counter}" ${tmpdir}/pmc.folded.log > ${tmpdir}/flamegraph.svg
54+
echo "Done: flamegraph generated as ${tmpdir}/flamegraph.svg"

FreeBSD/lua/hello-world.lua

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/libexec/flua
2+
-- Discovering lua with a question: Could I use it to replace shell script?
3+
4+
-- function alias
5+
-- s for shell
6+
s=os.execute
7+
8+
-- Main function
9+
local function main()
10+
local argument1 = arg[1]
11+
local argument2 = arg[2]
12+
word1 = "Hello"
13+
word2 = "World"
14+
print (word1 .. ", " .. word2 .. "!")
15+
if argument1 then
16+
print ("arg1: " .. argument1)
17+
if argument2 then
18+
print ("arg2: " .. argument2)
19+
end
20+
end
21+
print( "HOME env: " .. os.getenv("HOME"))
22+
os.execute([[echo "echo called by" "os.execute()"]])
23+
-- os.execute is too long to type, could we use shorter alias?
24+
s([[echo "echo called by alias s()"]])
25+
end
26+
27+
main()

FreeBSD/packages.list

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ www/nginx
116116
www/node
117117
www/npm
118118
www/p5-WWW-Curl
119+
www/w3m-img
119120
x11-drivers/xf86-video-nv
120121
x11-drivers/xf86-video-scfb
121122
x11-drivers/xf86-video-vesa

0 commit comments

Comments
 (0)