Change in ...libosmocore[master]: fsm: Reduce amount of copy+pasted LOGPFSMSRC() statements

2019-06-05 Thread Harald Welte
Harald Welte has submitted this change and it was merged. ( 
https://gerrit.osmocom.org/c/libosmocore/+/14363 )

Change subject: fsm: Reduce amount of copy+pasted LOGPFSMSRC() statements
..

fsm: Reduce amount of copy+pasted LOGPFSMSRC() statements

Instead of copy+pasting the same LOGPFSMSRC("State change to " ...)
with slightly different trailer depending on the FSM timer, let's first
snprintf() to a stack variable and then have a single log statement.

Change-Id: I49528c4ca1fa11aef09c2092615dccca450b847c
---
M src/fsm.c
1 file changed, 15 insertions(+), 17 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/fsm.c b/src/fsm.c
index 37da9f9..337786d 100644
--- a/src/fsm.c
+++ b/src/fsm.c
@@ -609,33 +609,31 @@
st->onleave(fi, new_state);

if (fsm_log_timeouts) {
+   char trailer[64];
+   trailer[0] = '\0';
if (keep_timer && fi->timer.active) {
/* This should always give us a timeout, but just in 
case the return value indicates error, omit
 * logging the remaining time. */
if (osmo_timer_remaining(>timer, NULL, ))
-   LOGPFSMSRC(fi, file, line,
-  "State change to %s (keeping " 
OSMO_T_FMT ")\n",
-  osmo_fsm_state_name(fsm, new_state),
-  OSMO_T_FMT_ARGS(fi->T));
+   snprintf(trailer, sizeof(trailer), "(keeping " 
OSMO_T_FMT ")",
+OSMO_T_FMT_ARGS(fi->T));
else
-   LOGPFSMSRC(fi, file, line,
-  "State change to %s (keeping " 
OSMO_T_FMT ", %ld.%03lds remaining)\n",
-  osmo_fsm_state_name(fsm, new_state),
-  OSMO_T_FMT_ARGS(fi->T), 
remaining.tv_sec, remaining.tv_usec / 1000);
+   snprintf(trailer, sizeof(trailer), "(keeping " 
OSMO_T_FMT
+ ", %ld.%03lds remaining)", 
OSMO_T_FMT_ARGS(fi->T),
+ remaining.tv_sec, remaining.tv_usec / 
1000);
} else if (timeout_ms) {
-   if (timeout_ms % 1000 == 0) {
+   if (timeout_ms % 1000 == 0)
/* keep log output legacy compatible to avoid 
autotest failures */
-   LOGPFSMSRC(fi, file, line, "State change to %s 
(" OSMO_T_FMT ", %lus)\n",
-  osmo_fsm_state_name(fsm, new_state),
+   snprintf(trailer, sizeof(trailer), "(" 
OSMO_T_FMT ", %lus)",
   OSMO_T_FMT_ARGS(T), timeout_ms/1000);
-   } else {
-   LOGPFSMSRC(fi, file, line, "State change to %s 
(" OSMO_T_FMT ", %lums)\n",
-  osmo_fsm_state_name(fsm, new_state),
+   else
+   snprintf(trailer, sizeof(trailer), "(" 
OSMO_T_FMT ", %lums)",
   OSMO_T_FMT_ARGS(T), timeout_ms);
-   }
} else
-   LOGPFSMSRC(fi, file, line, "State change to %s (no 
timeout)\n",
-  osmo_fsm_state_name(fsm, new_state));
+   snprintf(trailer, sizeof(trailer), "(no timeout)");
+
+   LOGPFSMSRC(fi, file, line, "State change to %s %s\n",
+  osmo_fsm_state_name(fsm, new_state), trailer);
} else {
LOGPFSMSRC(fi, file, line, "state_chg to %s\n",
   osmo_fsm_state_name(fsm, new_state));

--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/14363
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I49528c4ca1fa11aef09c2092615dccca450b847c
Gerrit-Change-Number: 14363
Gerrit-PatchSet: 3
Gerrit-Owner: Harald Welte 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-MessageType: merged


Change in ...libosmocore[master]: fsm: Reduce amount of copy+pasted LOGPFSMSRC() statements

2019-06-05 Thread Harald Welte
Harald Welte has posted comments on this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/14363 )

Change subject: fsm: Reduce amount of copy+pasted LOGPFSMSRC() statements
..


Patch Set 2: Code-Review+2


--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/14363
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I49528c4ca1fa11aef09c2092615dccca450b847c
Gerrit-Change-Number: 14363
Gerrit-PatchSet: 2
Gerrit-Owner: Harald Welte 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Comment-Date: Wed, 05 Jun 2019 10:01:19 +
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment


Change in ...libosmocore[master]: fsm: Reduce amount of copy+pasted LOGPFSMSRC() statements

2019-06-04 Thread Harald Welte
Harald Welte has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmocore/+/14363


Change subject: fsm: Reduce amount of copy+pasted LOGPFSMSRC() statements
..

fsm: Reduce amount of copy+pasted LOGPFSMSRC() statements

Instead of copy+pasting the same LOGPFSMSRC("State change to " ...)
with slightly different trailer depending on the FSM timer, let's first
snprintf() to a stack variable and then have a single log statement.

Change-Id: I49528c4ca1fa11aef09c2092615dccca450b847c
---
M src/fsm.c
1 file changed, 15 insertions(+), 17 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/63/14363/1

diff --git a/src/fsm.c b/src/fsm.c
index 37da9f9..337786d 100644
--- a/src/fsm.c
+++ b/src/fsm.c
@@ -609,33 +609,31 @@
st->onleave(fi, new_state);

if (fsm_log_timeouts) {
+   char trailer[64];
+   trailer[0] = '\0';
if (keep_timer && fi->timer.active) {
/* This should always give us a timeout, but just in 
case the return value indicates error, omit
 * logging the remaining time. */
if (osmo_timer_remaining(>timer, NULL, ))
-   LOGPFSMSRC(fi, file, line,
-  "State change to %s (keeping " 
OSMO_T_FMT ")\n",
-  osmo_fsm_state_name(fsm, new_state),
-  OSMO_T_FMT_ARGS(fi->T));
+   snprintf(trailer, sizeof(trailer), "(keeping " 
OSMO_T_FMT ")",
+OSMO_T_FMT_ARGS(fi->T));
else
-   LOGPFSMSRC(fi, file, line,
-  "State change to %s (keeping " 
OSMO_T_FMT ", %ld.%03lds remaining)\n",
-  osmo_fsm_state_name(fsm, new_state),
-  OSMO_T_FMT_ARGS(fi->T), 
remaining.tv_sec, remaining.tv_usec / 1000);
+   snprintf(trailer, sizeof(trailer), "(keeping " 
OSMO_T_FMT
+ ", %ld.%03lds remaining)", 
OSMO_T_FMT_ARGS(fi->T),
+ remaining.tv_sec, remaining.tv_usec / 
1000);
} else if (timeout_ms) {
-   if (timeout_ms % 1000 == 0) {
+   if (timeout_ms % 1000 == 0)
/* keep log output legacy compatible to avoid 
autotest failures */
-   LOGPFSMSRC(fi, file, line, "State change to %s 
(" OSMO_T_FMT ", %lus)\n",
-  osmo_fsm_state_name(fsm, new_state),
+   snprintf(trailer, sizeof(trailer), "(" 
OSMO_T_FMT ", %lus)",
   OSMO_T_FMT_ARGS(T), timeout_ms/1000);
-   } else {
-   LOGPFSMSRC(fi, file, line, "State change to %s 
(" OSMO_T_FMT ", %lums)\n",
-  osmo_fsm_state_name(fsm, new_state),
+   else
+   snprintf(trailer, sizeof(trailer), "(" 
OSMO_T_FMT ", %lums)",
   OSMO_T_FMT_ARGS(T), timeout_ms);
-   }
} else
-   LOGPFSMSRC(fi, file, line, "State change to %s (no 
timeout)\n",
-  osmo_fsm_state_name(fsm, new_state));
+   snprintf(trailer, sizeof(trailer), "(no timeout)");
+
+   LOGPFSMSRC(fi, file, line, "State change to %s %s\n",
+  osmo_fsm_state_name(fsm, new_state), trailer);
} else {
LOGPFSMSRC(fi, file, line, "state_chg to %s\n",
   osmo_fsm_state_name(fsm, new_state));

--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/14363
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I49528c4ca1fa11aef09c2092615dccca450b847c
Gerrit-Change-Number: 14363
Gerrit-PatchSet: 1
Gerrit-Owner: Harald Welte 
Gerrit-MessageType: newchange