Skip to content

Commit

Permalink
Update profiling result printer
Browse files Browse the repository at this point in the history
Signed-off-by: yamacir-kit <[email protected]>
  • Loading branch information
yamacir-kit committed Jun 5, 2022
1 parent e1373bf commit 62fbc31
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ sudo rm -rf /usr/local/share/meevax

| Target Name | Description
|:-------------------|:--
| `all` (default) | Build shared-library `libmeevax.0.4.38.so` and executable `meevax`.
| `all` (default) | Build shared-library `libmeevax.0.4.39.so` and executable `meevax`.
| `test` | Test executable `meevax`.
| `package` | Generate debian package `meevax_0.4.38_amd64.deb`.
| `package` | Generate debian package `meevax_0.4.39_amd64.deb`.
| `install` | Copy files into `/usr/local` __(1)__.
| `install.deb` | `all` + `package` + `sudo apt install <meevax>.deb`
| `safe-install.deb` | `all` + `test` + `package` + `sudo apt install <meevax>.deb`
Expand All @@ -120,7 +120,7 @@ __(1)__ Meevax installed by `make install` cannot be uninstalled by the system's
## Usage

```
Meevax Lisp System, version 0.4.38
Meevax Lisp System, version 0.4.39
Usage: meevax [OPTION...] [FILE...]
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.38
0.4.39
9 changes: 5 additions & 4 deletions include/meevax/kernel/heterogeneous.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ inline namespace kernel
template <typename Bound, typename... Us>
static auto allocate(Us&&... xs)
{
#if PROFILE_ALLOCATION
current_profiler().by_type[typeid(typename std::decay<Bound>::type)].allocation++;
current_profiler().by_type[typeid(void)].allocation++;
#endif
if constexpr (profiler::count_allocations)
{
current_profiler().allocation_counts[typeid(Bound)]++;
current_profiler().allocation_counts[typeid(void)]++;
}

if constexpr (std::is_same_v<Bound, Top>)
{
Expand Down
2 changes: 0 additions & 2 deletions include/meevax/kernel/overview.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

#define NIL /* nothing */

#define PROFILE_ALLOCATION true

namespace meevax
{
inline namespace kernel
Expand Down
7 changes: 2 additions & 5 deletions include/meevax/kernel/profiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ inline namespace kernel
{
struct profiler
{
struct topic
{
std::size_t allocation = 0;
};
static constexpr auto count_allocations = false;

std::unordered_map<std::type_index, topic> by_type;
std::unordered_map<std::type_index, std::size_t> allocation_counts;

~profiler();
};
Expand Down
20 changes: 12 additions & 8 deletions src/kernel/profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
limitations under the License.
*/

#include <fstream>
#include <sstream>

#include <meevax/kernel/profiler.hpp>
#include <meevax/utility/demangle.hpp>
Expand All @@ -37,17 +37,21 @@ inline namespace kernel

profiler::~profiler()
{
if (auto file = std::ofstream("/tmp/meevax-profile-by-type.txt"); file)
if (auto ss = std::stringstream(); not std::empty(allocation_counts))
{
for (auto&& [type, topic] : by_type)
for (auto&& [type, value] : allocation_counts)
{
file << topic.allocation << "\t" << demangle(type.name()) << "\n";
ss << demangle(type.name()) << "\t" << value << "\n";
}
}

sh("cat /tmp/meevax-profile-by-type.txt | sed 's/meevax::kernel:://g' \
| sort -rn \
| column -t -s'\t'");
sh("echo \"" + ss.str() + "\" | sed 's/meevax::kernel:://g' \
| sort --field-separator='\t' \
--key=2 \
--numeric-sort \
--reverse \
| echo \"TYPENAME\tALLOCATION COUNT\n$(cat -)\" \
| column -t -s'\t'");
}
}

auto current_profiler() -> profiler &
Expand Down

0 comments on commit 62fbc31

Please sign in to comment.