<p>neels has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-bsc/+/24426">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">meas rep logging: replace a dozen DEBUGPC() with one DEBUGP()<br><br>Instead of calling DEBUGPC() over and over, compose a string using<br>osmo_strbuf and then log it once.<br><br>Rationale:<br><br>a) DEBUGPC() is a bad idea for gsmtap_log, because each DEBUGPC()<br>dispatches a separate gsmtap_log packet, fragmenting the actual log line<br>in wireshark.<br><br>b) DEBUGPC() is a bad idea because it checks the logging categories for<br>every DEBUGPC() invocation.<br><br>c) using a separate function with osmo_strbuf and OTC_SELECT, we can<br>actually skip the entire string composition in case the DMEAS logging<br>category is disabled, with a single logging category check.<br><br>Change-Id: I4cb607ff43a1cb30408427d99d97c103776b6e69<br>---<br>M src/osmo-bsc/abis_rsl.c<br>1 file changed, 46 insertions(+), 25 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/26/24426/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/osmo-bsc/abis_rsl.c b/src/osmo-bsc/abis_rsl.c</span><br><span>index 1fb167a..17e754d 100644</span><br><span>--- a/src/osmo-bsc/abis_rsl.c</span><br><span>+++ b/src/osmo-bsc/abis_rsl.c</span><br><span>@@ -1006,65 +1006,86 @@</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static void print_meas_rep_uni(struct gsm_meas_rep_unidir *mru,</span><br><span style="color: hsl(0, 100%, 40%);">- const char *prefix)</span><br><span style="color: hsl(120, 100%, 40%);">+static void print_meas_rep_uni(struct osmo_strbuf *sb, struct gsm_meas_rep_unidir *mru, const char *prefix)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- DEBUGPC(DMEAS, "RXL-FULL-%s=%3ddBm RXL-SUB-%s=%3ddBm ",</span><br><span style="color: hsl(0, 100%, 40%);">- prefix, rxlev2dbm(mru->full.rx_lev),</span><br><span style="color: hsl(0, 100%, 40%);">- prefix, rxlev2dbm(mru->sub.rx_lev));</span><br><span style="color: hsl(0, 100%, 40%);">- DEBUGPC(DMEAS, "RXQ-FULL-%s=%d RXQ-SUB-%s=%d ",</span><br><span style="color: hsl(0, 100%, 40%);">- prefix, mru->full.rx_qual, prefix, mru->sub.rx_qual);</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_STRBUF_PRINTF(*sb, "RXL-FULL-%s=%3ddBm RXL-SUB-%s=%3ddBm ",</span><br><span style="color: hsl(120, 100%, 40%);">+ prefix, rxlev2dbm(mru->full.rx_lev),</span><br><span style="color: hsl(120, 100%, 40%);">+ prefix, rxlev2dbm(mru->sub.rx_lev));</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_STRBUF_PRINTF(*sb, "RXQ-FULL-%s=%d RXQ-SUB-%s=%d ",</span><br><span style="color: hsl(120, 100%, 40%);">+ prefix, mru->full.rx_qual, prefix, mru->sub.rx_qual);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static void print_meas_rep(struct gsm_lchan *lchan, struct gsm_meas_rep *mr)</span><br><span style="color: hsl(120, 100%, 40%);">+static int print_meas_rep_buf(char *buf, size_t len, struct gsm_lchan *lchan, struct gsm_meas_rep *mr)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- int i;</span><br><span> const char *name = "";</span><br><span> struct bsc_subscr *bsub = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct osmo_strbuf sb = { .buf = buf, .len = len };</span><br><span> </span><br><span> if (lchan && lchan->conn) {</span><br><span> bsub = lchan->conn->bsub;</span><br><span> if (bsub) {</span><br><span style="color: hsl(0, 100%, 40%);">- log_set_context(LOG_CTX_BSC_SUBSCR, bsub);</span><br><span> name = bsc_subscr_name(bsub);</span><br><span> } else</span><br><span> name = lchan->name;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- DEBUGP(DMEAS, "[%s] MEASUREMENT RESULT NR=%d ", name, mr->nr);</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_STRBUF_PRINTF(sb, "[%s] MEASUREMENT RESULT NR=%d ", name, mr->nr);</span><br><span> </span><br><span> if (mr->flags & MEAS_REP_F_DL_DTX)</span><br><span style="color: hsl(0, 100%, 40%);">- DEBUGPC(DMEAS, "DTXd ");</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_STRBUF_PRINTF(sb, "DTXd ");</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- print_meas_rep_uni(&mr->ul, "ul");</span><br><span style="color: hsl(0, 100%, 40%);">- DEBUGPC(DMEAS, "BS_POWER=%ddBm ", mr->bs_power_db);</span><br><span style="color: hsl(120, 100%, 40%);">+ print_meas_rep_uni(&sb, &mr->ul, "ul");</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_STRBUF_PRINTF(sb, "BS_POWER=%ddBm ", mr->bs_power_db);</span><br><span> </span><br><span> if (mr->flags & MEAS_REP_F_MS_TO)</span><br><span style="color: hsl(0, 100%, 40%);">- DEBUGPC(DMEAS, "MS_TO=%d ", mr->ms_timing_offset);</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_STRBUF_PRINTF(sb, "MS_TO=%d ", mr->ms_timing_offset);</span><br><span> </span><br><span> if (mr->flags & MEAS_REP_F_MS_L1) {</span><br><span style="color: hsl(0, 100%, 40%);">- DEBUGPC(DMEAS, "L1_MS_PWR=%3ddBm ", mr->ms_l1.pwr);</span><br><span style="color: hsl(0, 100%, 40%);">- DEBUGPC(DMEAS, "L1_FPC=%u ",</span><br><span style="color: hsl(0, 100%, 40%);">- mr->flags & MEAS_REP_F_FPC ? 1 : 0);</span><br><span style="color: hsl(0, 100%, 40%);">- DEBUGPC(DMEAS, "L1_TA=%u ", mr->ms_l1.ta);</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_STRBUF_PRINTF(sb, "L1_MS_PWR=%3ddBm ", mr->ms_l1.pwr);</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_STRBUF_PRINTF(sb, "L1_FPC=%u ", mr->flags & MEAS_REP_F_FPC ? 1 : 0);</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_STRBUF_PRINTF(sb, "L1_TA=%u ", mr->ms_l1.ta);</span><br><span> }</span><br><span> </span><br><span> if (mr->flags & MEAS_REP_F_UL_DTX)</span><br><span style="color: hsl(0, 100%, 40%);">- DEBUGPC(DMEAS, "DTXu ");</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_STRBUF_PRINTF(sb, "DTXu ");</span><br><span> if (mr->flags & MEAS_REP_F_BA1)</span><br><span style="color: hsl(0, 100%, 40%);">- DEBUGPC(DMEAS, "BA1 ");</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_STRBUF_PRINTF(sb, "BA1 ");</span><br><span> if (!(mr->flags & MEAS_REP_F_DL_VALID))</span><br><span style="color: hsl(0, 100%, 40%);">- DEBUGPC(DMEAS, "NOT VALID ");</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_STRBUF_PRINTF(sb, "NOT VALID ");</span><br><span> else</span><br><span style="color: hsl(0, 100%, 40%);">- print_meas_rep_uni(&mr->dl, "dl");</span><br><span style="color: hsl(120, 100%, 40%);">+ print_meas_rep_uni(&sb, &mr->dl, "dl");</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- DEBUGPC(DMEAS, "NUM_NEIGH=%u\n", mr->num_cell);</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_STRBUF_PRINTF(sb, "NUM_NEIGH=%u", mr->num_cell);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return sb.chars_needed;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static char *print_meas_rep_c(void *ctx, struct gsm_lchan *lchan, struct gsm_meas_rep *mr)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ /* A naive count of required characters gets me to ~200, so 256 should be safe to get a large enough buffer on</span><br><span style="color: hsl(120, 100%, 40%);">+ * the first time. */</span><br><span style="color: hsl(120, 100%, 40%);">+ OSMO_NAME_C_IMPL(ctx, 256, "ERROR", print_meas_rep_buf, lchan, mr)</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void print_meas_rep(struct gsm_lchan *lchan, struct gsm_meas_rep *mr)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int i;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct bsc_subscr *bsub = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (lchan && lchan->conn) {</span><br><span style="color: hsl(120, 100%, 40%);">+ bsub = lchan->conn->bsub;</span><br><span style="color: hsl(120, 100%, 40%);">+ if (bsub)</span><br><span style="color: hsl(120, 100%, 40%);">+ log_set_context(LOG_CTX_BSC_SUBSCR, bsub);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ DEBUGP(DMEAS, "%s\n", print_meas_rep_c(OTC_SELECT, lchan, mr));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (mr->num_cell == 7)</span><br><span> return;</span><br><span> for (i = 0; i < mr->num_cell; i++) {</span><br><span> struct gsm_meas_rep_cell *mrc = &mr->cell[i];</span><br><span> DEBUGP(DMEAS, "IDX=%u ARFCN=%u BSIC=%u => %d dBm\n",</span><br><span style="color: hsl(0, 100%, 40%);">- mrc->neigh_idx, mrc->arfcn, mrc->bsic, rxlev2dbm(mrc->rxlev));</span><br><span style="color: hsl(120, 100%, 40%);">+ mrc->neigh_idx, mrc->arfcn, mrc->bsic, rxlev2dbm(mrc->rxlev));</span><br><span> }</span><br><span> </span><br><span> if (bsub)</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-bsc/+/24426">change 24426</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/osmo-bsc/+/24426"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: osmo-bsc </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I4cb607ff43a1cb30408427d99d97c103776b6e69 </div>
<div style="display:none"> Gerrit-Change-Number: 24426 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: neels <nhofmeyr@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>