Skip to content
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

dlt-system: Avoid expensive getpid() syscalls #717

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/dlt/dlt_user.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ typedef struct
#ifdef DLT_TRACE_LOAD_CTRL_ENABLE
pthread_rwlock_t trace_load_limit_lock;
#endif
pid_t local_pid; /**< Local DltUser process identifier cache */
} DltUser;

typedef int (*dlt_injection_callback_id)(uint32_t, void *, uint32_t, void *);
Expand Down
9 changes: 8 additions & 1 deletion src/lib/dlt_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,9 @@ DltReturnValue dlt_init_common(void)
/* set to unknown state of connected client */
dlt_user.log_state = -1;

/* set pid cache to none until we need it */
dlt_user.local_pid = -1;

dlt_user.dlt_log_handle = -1;
dlt_user.dlt_user_handle = DLT_FD_INIT;

Expand Down Expand Up @@ -4011,7 +4014,10 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, const int mtype, int *
/* send session id */
if (dlt_user.with_session_id) {
msg.standardheader->htyp |= DLT_HTYP_WSID;
msg.headerextra.seid = (uint32_t) getpid();
if (__builtin_expect(!!(dlt_user.local_pid == -1), false)) {
dlt_user.local_pid = getpid();
}
msg.headerextra.seid = (uint32_t) dlt_user.local_pid;
}

if (is_verbose_mode(dlt_user.verbose_mode, log))
Expand Down Expand Up @@ -5377,6 +5383,7 @@ static void dlt_fork_child_fork_handler()
g_dlt_is_child = 1;
dlt_user_init_state = INIT_UNITIALIZED;
dlt_user.dlt_log_handle = -1;
dlt_user.local_pid = -1;
#ifdef DLT_TRACE_LOAD_CTRL_ENABLE
pthread_rwlock_unlock(&trace_load_rw_lock);
#endif
Expand Down