Commit 3f02e0d5 authored by Anas Nashif's avatar Anas Nashif
Browse files

samples: remove kernel_event_logger sample



We are replacing kernel_event_logger with a more generic tracing API.

Signed-off-by: default avatarAnas Nashif <anas.nashif@intel.com>
parent ac47070d
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
cmake_minimum_required(VERSION 3.8.2)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(NONE)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})
+0 −41
Original line number Diff line number Diff line
.. _kerneleventlogger_sample:

Kernel Event Logger Sample
################################

Overview
********

A simple application that demonstrates use of kernel event
logger feature. Two threads (A and B) of the same priority
are created and main thread is configured to have low priority,
which reads the events from kernel event logger's buffer and
prints to the console. When thread 'A' gets scheduled it will
sleep for 1 second. Similarly when thread 'B' gets scheduled
it will sleep for 0.5 seconds. When both A and B are sleeping,
the main thread gets scheduled and retrieves the events captured
from kernel event logger's buffer and prints to the console.

Building and Running
********************

This project outputs to the console.  It can be built and executed
on QEMU as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/subsys/logging/kernel_event_logger
   :host-os: unix
   :board: qemu_x86
   :goals: run
   :compact:

Sample Output
=============

.. code-block:: console

       tid of context switched thread = 400080 at time = 96538
       tid of context switched thread = 4000c0 at time = 98047
       thread = 400080, is moved to = REDAY_Q , at time = 51019657
       thread = 400040, is moved to = REDAY_Q , at time = 51024998
+0 −9
Original line number Diff line number Diff line
CONFIG_BOOT_BANNER=y

CONFIG_MAIN_THREAD_PRIORITY=3
CONFIG_RING_BUFFER=y
CONFIG_KERNEL_EVENT_LOGGER=y
CONFIG_KERNEL_EVENT_LOGGER_CONTEXT_SWITCH=y
CONFIG_KERNEL_EVENT_LOGGER_INTERRUPT=n
CONFIG_KERNEL_EVENT_LOGGER_THREAD=y
CONFIG_USERSPACE=n
+0 −16
Original line number Diff line number Diff line
sample:
  description: A simple application that demonstrate
    use of kernel event logging feature.
  name: Kernel event logger Sample
tests:
  test:
    tags: apps logging events
    harness: console
    harness_config:
      type: multi_line
      ordered: false
      regex:
        - "thread = (.*), is moved to = REDAY_Q ,at time = (\\d+)"
        - "tid of context switched thread = (.*) at time = (\\d+)"
        - "thread = (.*), is moved to = EXIT_STATE ,at time = (\\d+)"
        - "thread = (.*), is moved to = PEND_STATE ,at time = (\\d+)"
+0 −99
Original line number Diff line number Diff line
/*
 * Copyright (c) 2017 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr.h>
#include <logging/kernel_event_logger.h>
#include <misc/printk.h>
#include <misc/util.h>

K_THREAD_STACK_DEFINE(threadA_stack, 1024);
K_THREAD_STACK_DEFINE(threadB_stack, 1024);
K_THREAD_STACK_DEFINE(event_logger_stack, 4096);

K_SEM_DEFINE(sem_sync, 0, 1);	/* starts off "not available" */

static struct k_thread threadA_data;
static struct k_thread threadB_data;
static u32_t timestamp;
char event_type[][12] = {"REDAY_Q", "PEND_STATE", "EXIT_STATE"};

static void event_logger(void)
{
	u32_t event_data[4];
	u16_t event_id;
	u8_t dropped;
	u8_t event_data_size = (u8_t)ARRAY_SIZE(event_data);
	int ret;

	for (;;) {

		ret = sys_k_event_logger_get_wait(&event_id,
						  &dropped,
						  event_data,
						  &event_data_size);
		if (ret < 0) {
			continue;
		}

		timestamp = event_data[0];

		switch (event_id) {
		case KERNEL_EVENT_LOGGER_CONTEXT_SWITCH_EVENT_ID:
			printk("tid of context switched thread = %x at "
			       "time = %d\n", event_data[1], timestamp);
			break;
		case KERNEL_EVENT_LOGGER_INTERRUPT_EVENT_ID:
			break;
		case KERNEL_EVENT_LOGGER_SLEEP_EVENT_ID:
			break;
		case KERNEL_EVENT_LOGGER_THREAD_EVENT_ID:
			printk("thread = %x, is moved to = %s ,at time = %d\n"
			, event_data[1], event_type[event_data[2]], timestamp);
			break;
		default:
			break;
		}

	}
}

static void threadB(void)
{
	unsigned int i = 10;

	for (; i ; i--) {
		k_sleep(MSEC_PER_SEC / 2);
	}

	k_sem_take(&sem_sync, K_FOREVER);
}

static void threadA(void)
{
	unsigned int j = 10;

	for (; j ; j--) {

		k_sleep(MSEC_PER_SEC);
	}

	k_sem_give(&sem_sync);
}

void main(void)
{
	k_thread_create(&threadB_data, threadB_stack,
			K_THREAD_STACK_SIZEOF(threadB_stack),
			(k_thread_entry_t)threadB,
			NULL, NULL, NULL, K_PRIO_PREEMPT(2), 0, 0);

	k_thread_create(&threadA_data, threadA_stack,
			K_THREAD_STACK_SIZEOF(threadA_stack),
			(k_thread_entry_t)threadA,
			NULL, NULL, NULL, K_PRIO_PREEMPT(2), 0, 0);

	event_logger();
}