-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A sample application to demonstrate use of kernel event logger feature. #4552
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
BOARD ?= qemu_x86 | ||
CONF_FILE = prj.conf | ||
|
||
include ${ZEPHYR_BASE}/Makefile.inc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
.. _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: | ||
|
||
.. code-block:: console | ||
|
||
$ cd samples/subsys/kernel_event_logger | ||
$ make run | ||
|
||
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
sample: | ||
description: A simple application that demonstrate use of | ||
kernel event logging feature. | ||
name: Kernel event logger Sample | ||
tests: | ||
- test: | ||
build_only: true | ||
tags: apps | ||
platform_whitelist: qemu_x86 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
obj-y += main.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright (c) 2017 Intel Corporation | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <kernel_structs.h> | ||
#include <logging/kernel_event_logger.h> | ||
#include <kernel_structs.h> | ||
#include <misc/printk.h> | ||
#include <misc/util.h> | ||
#include <zephyr.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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a default to the switch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.. _logging-samples: | ||
|
||
Logging Sample | ||
################ | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
:glob: | ||
|
||
**/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the first document in the logging area, so you'll need to also add a file samples/subsys/logging/logging.rst that looks like samples/subsys/console/console.rst (copy that one and edit the title). This will remove the "not included in a toc-tree" warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok