mirror of
https://git.planet-casio.com/Lephenixnoir/libprof.git
synced 2025-05-09 19:39:24 +02:00
Compare commits
16 commits
Author | SHA1 | Date | |
---|---|---|---|
|
6df36ce8d3 | ||
|
5b669e5529 | ||
|
6d82009532 | ||
|
b6657c0834 | ||
|
ac348bce34 | ||
|
c0d5b053d9 | ||
|
fd90842b82 | ||
|
08ee98cef1 | ||
|
a9f1dc3ec8 | ||
|
8c34abe3ca | ||
|
6b5685a35e | ||
|
91bb658d6c | ||
|
02774004a2 | ||
|
05e6463139 | ||
|
a15c193ab7 | ||
|
7ae42ac662 |
8 changed files with 134 additions and 73 deletions
7
.gitignore
vendored
7
.gitignore
vendored
|
@ -1,3 +1,6 @@
|
|||
# Build files
|
||||
build/
|
||||
libprof.a
|
||||
build*/
|
||||
|
||||
# GiteaPC configuration files
|
||||
giteapc-config-*.make
|
||||
giteapc-config.make
|
||||
|
|
21
CMakeLists.txt
Normal file
21
CMakeLists.txt
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Build system for the libprof library for gint
|
||||
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
project(libprof VERSION 2.4.0 LANGUAGES C)
|
||||
find_package(Gint 2.4.0 REQUIRED)
|
||||
|
||||
configure_file(libprof.h libprof.h)
|
||||
|
||||
set(NAME "prof-${FXSDK_PLATFORM}")
|
||||
add_library(${NAME} STATIC libprof.c)
|
||||
|
||||
target_compile_options(${NAME} PUBLIC -Wall -Wextra -std=c11 -Os)
|
||||
target_include_directories(${NAME} PUBLIC "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
target_link_libraries(${NAME} Gint::Gint)
|
||||
|
||||
install(TARGETS ${NAME}
|
||||
DESTINATION "${FXSDK_LIB}")
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libprof.h"
|
||||
DESTINATION "${FXSDK_INCLUDE}")
|
||||
install(FILES cmake/FindLibProf.cmake
|
||||
DESTINATION "${FXSDK_CMAKE_MODULE_PATH}")
|
46
Makefile
46
Makefile
|
@ -1,46 +0,0 @@
|
|||
#! /usr/bin/make -f
|
||||
# libprof Makefile
|
||||
|
||||
cflags := -m3 -mb -ffreestanding -nostdlib -fstrict-volatile-bitfields -Wall \
|
||||
-Wextra -Os -I .
|
||||
target ?= sh-elf
|
||||
lib := libprof.a
|
||||
header := libprof.h
|
||||
|
||||
PREFIX ?= $(shell $(target)-gcc -print-search-dirs | grep install \
|
||||
| sed 's/install: //')
|
||||
|
||||
ifeq "$(PREFIX)" ""
|
||||
$(error "Cannot determine compiler install path")
|
||||
endif
|
||||
|
||||
src := $(wildcard *.c)
|
||||
obj := $(src:%=build/%.o)
|
||||
|
||||
# Rules
|
||||
|
||||
all: $(lib)
|
||||
|
||||
$(lib): $(obj)
|
||||
$(target)-ar rcs $@ $^
|
||||
|
||||
build/%.c.o: %.c | build/
|
||||
$(target)-gcc -c $< -o $@ $(cflags)
|
||||
|
||||
# Misc rules
|
||||
|
||||
clean:
|
||||
@ rm -rf build
|
||||
distclean: clean
|
||||
@ rm -f $(lib)
|
||||
|
||||
%/:
|
||||
mkdir -p $@
|
||||
|
||||
.PRECIOUS: %/
|
||||
|
||||
# Install
|
||||
|
||||
install: $(lib)
|
||||
cp $(lib) $(DESTDIR)$(PREFIX)
|
||||
cp $(header) $(DESTDIR)$(PREFIX)/include
|
50
README.md
50
README.md
|
@ -8,32 +8,46 @@ libprof's measurements are accurate down to the microsecond-level thanks to
|
|||
precise hardware timers, so it can also be used to time even small portions of
|
||||
code.
|
||||
|
||||
## Building
|
||||
## Installing and using libprof in a program
|
||||
|
||||
libprof is built and installed only once for both fx-9860G and fx-CG 50. The
|
||||
dependencies are:
|
||||
**Installing with GiteaPC**
|
||||
|
||||
* A GCC cross-compiler for a SuperH architecture
|
||||
* The [gint kernel](/Lephenixnoir/gint)
|
||||
libprof can be built and installed with [GiteaPC](https://gitea.planet-casio.com/Lephenixnoir/GiteaPC), an automation tool for the fxSDK.
|
||||
|
||||
The Makefile will build and install the library without further instructions.
|
||||
|
||||
```sh
|
||||
% make
|
||||
% make install
|
||||
```bash
|
||||
% giteapc install Lephenixnoir/libprof
|
||||
```
|
||||
|
||||
By default `sh-elf` is used to build; you can override this by setting the
|
||||
`target` variable.
|
||||
**Installing manually**
|
||||
|
||||
```sh
|
||||
% make target=sh4eb-elf
|
||||
% make install target=sh4eb-elf
|
||||
libprof should be built with the [fxSDK](/Lephenixnoir/fxsdk), which provides
|
||||
compiler settings and library interfaces to build on the calculator.
|
||||
|
||||
Simply run `fxsdk build-fx` or `fxsdk build-cg`. The fxSDK will invoke CMake
|
||||
with a suitable toolchain file while exposing CMake modules for the calculator.
|
||||
|
||||
```bash
|
||||
% fxsdk build-fx install
|
||||
% fxsdk build-cg install
|
||||
```
|
||||
|
||||
If you have the older setup with two toolchains (`sh3eb-elf` and `sh4eb-elf`),
|
||||
instead of the new one with two targets on the same toolchain (`sh-elf`), you
|
||||
will need to make and install twice.
|
||||
**Using in a CMake-based add-in**
|
||||
|
||||
Find the `LibProf` package, which has a `LibProf` target. Versions are numbered like gint, so aim for your version of gint.
|
||||
|
||||
```cmake
|
||||
find_package(LibProf 2.1 REQUIRED)
|
||||
target_link_libraries(<target_name> LibProf::LibProf)
|
||||
```
|
||||
|
||||
**Using in a Makefile-based add-in**
|
||||
|
||||
Link with `-lprof-fx` on fx-9860G and `-lprof-cg` on fx-CG 50. In `project.cfg`:
|
||||
|
||||
```makefile
|
||||
LIBS_FX := -lprof-fx
|
||||
LIBS_CG := -lprof-cg
|
||||
```
|
||||
|
||||
## Basic use
|
||||
|
||||
|
|
19
cmake/FindLibProf.cmake
Normal file
19
cmake/FindLibProf.cmake
Normal file
|
@ -0,0 +1,19 @@
|
|||
include(FindSimpleLibrary)
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
find_package(Gint 2.2.1 REQUIRED)
|
||||
|
||||
find_simple_library("libprof-${FXSDK_PLATFORM}.a" libprof.h
|
||||
"PROF_VERSION" PATH_VAR PROF_PATH VERSION_VAR PROF_VERSION)
|
||||
|
||||
find_package_handle_standard_args(LibProf
|
||||
REQUIRED_VARS PROF_PATH PROF_VERSION
|
||||
VERSION_VAR PROF_VERSION)
|
||||
|
||||
if(LibProf_FOUND)
|
||||
add_library(LibProf::LibProf UNKNOWN IMPORTED)
|
||||
set_target_properties(LibProf::LibProf PROPERTIES
|
||||
IMPORTED_LOCATION "${PROF_PATH}"
|
||||
INTERFACE_LINK_OPTIONS -lprof-${FXSDK_PLATFORM}
|
||||
IMPORTED_LINK_INTERFACE_LIBRARIES Gint::Gint)
|
||||
endif()
|
25
giteapc.make
Normal file
25
giteapc.make
Normal file
|
@ -0,0 +1,25 @@
|
|||
# giteapc: version=1 depends=Lephenixnoir/gint
|
||||
|
||||
-include giteapc-config.make
|
||||
|
||||
configure:
|
||||
@ fxsdk build-fx -c
|
||||
@ fxsdk build-cg -c
|
||||
|
||||
build:
|
||||
@ fxsdk build-fx
|
||||
@ fxsdk build-cg
|
||||
|
||||
install:
|
||||
@ fxsdk build-fx install
|
||||
@ fxsdk build-cg install
|
||||
|
||||
uninstall:
|
||||
@ if [ -e build-fx/install_manifest.txt ]; then \
|
||||
xargs rm -f < build-fx/install_manifest.txt; \
|
||||
fi
|
||||
@ if [ -e build-cg/install_manifest.txt ]; then \
|
||||
xargs rm -f < build-cg/install_manifest.txt; \
|
||||
fi
|
||||
|
||||
.PHONY: configure build install uninstall
|
|
@ -10,6 +10,11 @@ uint32_t volatile *prof_tcnt = NULL;
|
|||
/* Timer ID */
|
||||
static int prof_timer = -1;
|
||||
|
||||
static int callback(void)
|
||||
{
|
||||
return TIMER_CONTINUE;
|
||||
}
|
||||
|
||||
/* prof_init(): Initialize the profiler's timer */
|
||||
int prof_init(void)
|
||||
{
|
||||
|
@ -17,7 +22,8 @@ int prof_init(void)
|
|||
int timer = -1;
|
||||
for(int t = 2; t >= 0 && timer == -1; t--)
|
||||
{
|
||||
timer = timer_setup(t, 0xffffffff, NULL);
|
||||
timer = timer_configure(t | TIMER_Pphi_4, 0xffffffff,
|
||||
GINT_CALL(callback));
|
||||
}
|
||||
if(timer == -1)
|
||||
{
|
||||
|
|
31
libprof.h
31
libprof.h
|
@ -5,9 +5,16 @@
|
|||
#ifndef LIBPROF_LIBPROF
|
||||
#define LIBPROF_LIBPROF
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <gint/defs/attributes.h>
|
||||
|
||||
/* This is substituted by CMake at compile-time */
|
||||
#define PROF_VERSION "@libprof_VERSION@"
|
||||
|
||||
//---
|
||||
// Initialization
|
||||
//---
|
||||
|
@ -51,7 +58,7 @@ extern uint32_t volatile *prof_tcnt;
|
|||
function was already executing then the deepest instance in the stack is
|
||||
used instead of creating a new counter. */
|
||||
#define prof_enter(prof) { \
|
||||
if(!prof.rec++) prof.elapsed += *prof_tcnt; \
|
||||
if(!(prof).rec++) (prof).elapsed += *prof_tcnt; \
|
||||
}
|
||||
|
||||
/* prof_leave(): Stop counting time for a function
|
||||
|
@ -60,7 +67,15 @@ extern uint32_t volatile *prof_tcnt;
|
|||
are not as exactly as many prof_leave()'s as prof_enter()'s then the
|
||||
resulting time measure will not be relevant at all. */
|
||||
#define prof_leave(prof) { \
|
||||
if(!--prof.rec) prof.elapsed -= *prof_tcnt; \
|
||||
if(!--(prof).rec) (prof).elapsed -= *prof_tcnt; \
|
||||
}
|
||||
|
||||
/* Variant of prof_enter()/prof_leave() for non-recursive contexts */
|
||||
#define prof_enter_norec(prof) { \
|
||||
(prof).elapsed += *prof_tcnt; \
|
||||
}
|
||||
#define prof_leave_norec(prof) { \
|
||||
(prof).elapsed -= *prof_tcnt; \
|
||||
}
|
||||
|
||||
/* prof_exec(): Measure a single block of code
|
||||
|
@ -72,11 +87,11 @@ extern uint32_t volatile *prof_tcnt;
|
|||
exec_code();
|
||||
}); */
|
||||
#define prof_exec(code) ({ \
|
||||
prof_t prof = prof_make(); \
|
||||
prof_enter(prof); \
|
||||
prof_t _prof = prof_make(); \
|
||||
prof_enter(_prof); \
|
||||
code; \
|
||||
prof_leave(prof); \
|
||||
prof_time(prof); \
|
||||
prof_leave(_prof); \
|
||||
prof_time(_prof); \
|
||||
})
|
||||
|
||||
//---
|
||||
|
@ -87,4 +102,8 @@ extern uint32_t volatile *prof_tcnt;
|
|||
Should only be called when the context is not currently executing. */
|
||||
uint32_t prof_time(prof_t prof);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LIBPROF_LIBPROF */
|
||||
|
|
Loading…
Add table
Reference in a new issue