# Profiling \`sh\` invocations with \`fakesh\`

**URL:** <https://discuss.kakoune.com/t/profiling-sh-invocations-with-fakesh/1806>\
**Category:** Terminal Tools\
**Tags:** scripting, plugins\
**Created:** [July 3, 2021, 9:30am UTC](https://discuss.kakoune.com/t/profiling-sh-invocations-with-fakesh/1806 "2021-07-03T09:30:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![almr](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/almr/32/934_2.png) [@almr](https://discuss.kakoune.com/u/almr)\
**Post date:** [July 3, 2021, 9:30am UTC](https://discuss.kakoune.com/t/profiling-sh-invocations-with-fakesh/1806/1 "2021-07-03T09:30:21Z")

</div>

I’ve updated [`f8ksh`](https://gitlab.com/kstr0k/f8ksh) (previous [announcement](https://discuss.kakoune.com/t/shebangs-in-sh/1800)) to enable invocation logging and counting (in addition to parsing shebang lines in commands — %sh{#! perl} …). Basically,

```auto
F8KSH_FAKESH_COUNT=true [F8KSH_FAKESH_DEBUG=true F8KSH_FAKESH_DATE="date +%s%N"] \
  KAKOUNE_POSIX_SHELL=~/src/fakesh.sh kak

```

… will generate a counter in `/tmp/fakesh_cnt.log`, and a timestamped log (including scripts being executed) in `/tmp/fakesh.log` (formatted itself as a shell script). You can even monitor plugins’ dirty work 😆 in real time with

```auto
tail -f /tmp/fakesh.log

```

Then,

```auto
cd /tmp
fakesh-log-conv --create-sql --logfunc=2sql <fakesh.log >fakesh.sql
sqlite3 /tmp/fakesh.sqlite3 <fakesh.sql

```

will load the logs in an sqlite3 database where they can be further disected.

Or don’t enable `_DEBUG` and just use the counter, it will reduce the Heisenberg effect.

One thing I found out is that Kakoune runs considerably **faster using busybox** (`KAKOUNE_POSIX_SHELL=/bin/static-sh`, at least on Debians; you may want to change fakesh’s own shebang when profiling). This is because `busybox` provides `sed`, `grep`, `awk`, `tail` and many more as builtins.

Full docs at the project homepage; also see the [scripting with external tools](https://discuss.kakoune.com/t/scripting-kakoune-with-external-tools/1779) thread. I’m going to look into profiling `kak` startup and some common plugins as time permits.

Note that `fakesh` is not Kakoune-specific — you can use it with `vim`, or any other tool that makes shell calls.

> **[kstr0k / f8ksh · GitLab](https://gitlab.com/kstr0k/f8ksh)**
>
> POSIX shell logging / profiling wrapper (optional: obeys in-script shebangs)

---

<div class="post-metadata">

**Author:** ![Ordovician\_Dawn](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/o/82dd89/32.png) [@Ordovician\_Dawn](https://discuss.kakoune.com/u/Ordovician_Dawn)\
**Post date:** [August 4, 2021, 10:28pm UTC](https://discuss.kakoune.com/t/profiling-sh-invocations-with-fakesh/1806/2 "2021-08-04T22:28:16Z")

</div>

This is great—hopefully, I’ll be able to use it to profile my plugins and make them run buttery smooth.  
Going to install and try it now.

EDIT: This is brilliant both for powering up your kak scripting and for digging in deep and learning about the internal operations of shell scripting! Really glad I followed the link on this one.
