summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit')
-rw-r--r--cpukit/sapi/Makefile.am3
-rw-r--r--cpukit/sapi/include/rtems/profiling.h148
-rw-r--r--cpukit/sapi/preinstall.am4
-rw-r--r--cpukit/sapi/src/profilingiterate.c26
-rw-r--r--cpukit/sapi/src/profilingreportxml.c96
5 files changed, 277 insertions, 0 deletions
diff --git a/cpukit/sapi/Makefile.am b/cpukit/sapi/Makefile.am
index 63eb60595f..19f7d87f61 100644
--- a/cpukit/sapi/Makefile.am
+++ b/cpukit/sapi/Makefile.am
@@ -14,6 +14,7 @@ include_rtems_HEADERS += include/rtems/init.h
include_rtems_HEADERS += include/rtems/io.h
include_rtems_HEADERS += include/rtems/mptables.h
include_rtems_HEADERS += include/rtems/cbs.h
+include_rtems_HEADERS += include/rtems/profiling.h
include_rtems_HEADERS += include/rtems/rbheap.h
include_rtems_HEADERS += include/rtems/rbtree.h
include_rtems_HEADERS += include/rtems/sptables.h
@@ -36,6 +37,8 @@ libsapi_a_SOURCES += src/chainsmp.c
libsapi_a_SOURCES += src/cpucounterconverter.c
libsapi_a_SOURCES += src/delayticks.c
libsapi_a_SOURCES += src/delaynano.c
+libsapi_a_SOURCES += src/profilingiterate.c
+libsapi_a_SOURCES += src/profilingreportxml.c
libsapi_a_CPPFLAGS = $(AM_CPPFLAGS)
include $(srcdir)/preinstall.am
diff --git a/cpukit/sapi/include/rtems/profiling.h b/cpukit/sapi/include/rtems/profiling.h
new file mode 100644
index 0000000000..b2bdf10a98
--- /dev/null
+++ b/cpukit/sapi/include/rtems/profiling.h
@@ -0,0 +1,148 @@
+/**
+ * @file
+ *
+ * @ingroup Profiling
+ *
+ * @brief Profiling API
+ */
+
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifndef _RTEMS_PROFILING_H
+#define _RTEMS_PROFILING_H
+
+#include <stdint.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/**
+ * @defgroup Profiling Profiling Support
+ *
+ * @brief The profiling support offers functions to report profiling
+ * information available in the system.
+ *
+ * Profiling support is by default disabled. It must be enabled via the
+ * configure command line with the <tt>--enable-profiling</tt> option. In this
+ * case the RTEMS_PROFILING pre-processor symbol is defined and profiling
+ * statistics will be gathered during system run-time. The profiling support
+ * increases the time of critical sections and has some memory overhead. The
+ * overhead should be acceptable for most applications. The aim of the
+ * profiling implementation is to be available even for production systems so
+ * that verification is simplified.
+ *
+ * Profiling information includes critical timing values such as the maximum
+ * time of disabled thread dispatching which is a measure for the thread
+ * dispatch latency. On SMP configurations statistics of all SMP locks in the
+ * system are available.
+ *
+ * Profiling information can be retrieved via rtems_profiling_iterate() and
+ * reported as an XML dump via rtems_profiling_report_xml(). These functions
+ * are always available, but actual profiling data is only available if enabled
+ * at build configuration time.
+ *
+ * @{
+ */
+
+/**
+ * @brief Type of profiling data.
+ */
+typedef enum {
+} rtems_profiling_type;
+
+/**
+ * @brief The profiling data header.
+ */
+typedef struct {
+ /**
+ * @brief The profiling data type.
+ */
+ rtems_profiling_type type;
+} rtems_profiling_header;
+
+/**
+ * @brief Collection of profiling data.
+ */
+typedef union {
+ /**
+ * @brief Header to specify the actual profiling data.
+ */
+ rtems_profiling_header header;
+} rtems_profiling_data;
+
+/**
+ * @brief Visitor function for the profiling iteration.
+ *
+ * @param[in, out] arg The visitor argument.
+ * @param[in] data The current profiling data.
+ *
+ * @see rtems_profiling_iterate().
+ */
+typedef void (*rtems_profiling_visitor)(
+ void *arg,
+ const rtems_profiling_data *data
+);
+
+/**
+ * @brief Iterates through all profiling data of the system.
+ *
+ * @param[in] visitor The visitor.
+ * @param[in, out] visitor_arg The visitor argument.
+ */
+void rtems_profiling_iterate(
+ rtems_profiling_visitor visitor,
+ void *visitor_arg
+);
+
+/**
+ * @brief Function for formatted output.
+ *
+ * @param[in, out] arg Some argument.
+ * @param[in] format The output format as specified by printf().
+ * @param[in] ... More parameters according to format.
+ *
+ * @returns As specified by printf().
+ *
+ * @see rtems_profiling_report_xml().
+ */
+typedef int (*rtems_profiling_printf)(void *arg, const char *format, ...);
+
+/**
+ * @brief Reports profiling data as XML.
+ *
+ * @param[in] name The name of the profiling report.
+ * @param[in] printf_func The formatted output function.
+ * @param[in, out] printf_arg The formatted output function argument.
+ * @param[in] indentation_level The current indentation level.
+ * @param[in] indentation The string used for indentation.
+ *
+ * @returns As specified by printf().
+ */
+int rtems_profiling_report_xml(
+ const char *name,
+ rtems_profiling_printf printf_func,
+ void *printf_arg,
+ uint32_t indentation_level,
+ const char *indentation
+);
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* _RTEMS_PROFILING_H */
diff --git a/cpukit/sapi/preinstall.am b/cpukit/sapi/preinstall.am
index 79eceef405..d05ab256a1 100644
--- a/cpukit/sapi/preinstall.am
+++ b/cpukit/sapi/preinstall.am
@@ -72,6 +72,10 @@ $(PROJECT_INCLUDE)/rtems/cbs.h: include/rtems/cbs.h $(PROJECT_INCLUDE)/rtems/$(d
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/cbs.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/cbs.h
+$(PROJECT_INCLUDE)/rtems/profiling.h: include/rtems/profiling.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/profiling.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/profiling.h
+
$(PROJECT_INCLUDE)/rtems/rbheap.h: include/rtems/rbheap.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rbheap.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rbheap.h
diff --git a/cpukit/sapi/src/profilingiterate.c b/cpukit/sapi/src/profilingiterate.c
new file mode 100644
index 0000000000..e528932db9
--- /dev/null
+++ b/cpukit/sapi/src/profilingiterate.c
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <rtems/profiling.h>
+
+void rtems_profiling_iterate(
+ rtems_profiling_visitor visitor,
+ void *visitor_arg
+)
+{
+}
diff --git a/cpukit/sapi/src/profilingreportxml.c b/cpukit/sapi/src/profilingreportxml.c
new file mode 100644
index 0000000000..d3fe7f7652
--- /dev/null
+++ b/cpukit/sapi/src/profilingreportxml.c
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2014 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <rtems@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+#include <rtems/profiling.h>
+
+#ifdef RTEMS_PROFILING
+
+typedef struct {
+ rtems_profiling_printf printf_func;
+ void *printf_arg;
+ uint32_t indentation_level;
+ const char *indentation;
+ int retval;
+} context;
+
+static void update_retval(context *ctx, int rv)
+{
+ if (rv > 0 && ctx->retval >= 0) {
+ ctx->retval += rv;
+ }
+}
+
+static void indent(context *ctx, uint32_t indentation_level)
+{
+ uint32_t n = ctx->indentation_level + indentation_level;
+ uint32_t i;
+
+ for (i = 0; i < n; ++i) {
+ int rv = (*ctx->printf_func)(ctx->printf_arg, "%s", ctx->indentation);
+
+ update_retval(ctx, rv);
+ }
+}
+
+static void report(void *arg, const rtems_profiling_data *data)
+{
+ context *ctx = arg;
+}
+
+#endif /* RTEMS_PROFILING */
+
+int rtems_profiling_report_xml(
+ const char *name,
+ rtems_profiling_printf printf_func,
+ void *printf_arg,
+ uint32_t indentation_level,
+ const char *indentation
+)
+{
+#ifdef RTEMS_PROFILING
+ context ctx_instance = {
+ .printf_func = printf_func,
+ .printf_arg = printf_arg,
+ .indentation_level = indentation_level,
+ .indentation = indentation,
+ .retval = 0
+ };
+ context *ctx = &ctx_instance;
+ int rv;
+
+ indent(ctx, 0);
+ rv = (*printf_func)(printf_arg, "<ProfilingReport name=\"%s\">\n", name);
+ update_retval(ctx, rv);
+
+ rtems_profiling_iterate(report, ctx);
+
+ indent(ctx, 0);
+ rv = (*printf_func)(printf_arg, "</ProfilingReport>\n");
+ update_retval(ctx, rv);
+
+ return ctx->retval;
+#else /* RTEMS_PROFILING */
+ (void) name;
+ (void) printf_func;
+ (void) printf_arg;
+ (void) indentation_level;
+ (void) indentation;
+
+ return 0;
+#endif /* RTEMS_PROFILING */
+}