Skip to content

Commit 035749c

Browse files
committed
log OPTIMIZE append paths to data/schema paths
Instead of having to build the full path.
1 parent d57c922 commit 035749c

File tree

4 files changed

+44
-31
lines changed

4 files changed

+44
-31
lines changed

src/log.c

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -381,27 +381,27 @@ ly_get_log_clb(void)
381381
}
382382

383383
void
384-
ly_log_location(const struct lysc_node *scnode, const struct lyd_node *dnode, const char *spath, const struct ly_in *in)
384+
ly_log_location(const struct lysc_node *scnode, const struct lyd_node *dnode, const char *path, const struct ly_in *in)
385385
{
386386
if (scnode) {
387387
ly_set_add(&log_location.scnodes, (void *)scnode, 1, NULL);
388388
}
389-
if (dnode || (!scnode && !spath && !in)) {
389+
if (dnode || (!scnode && !path && !in)) {
390390
ly_set_add(&log_location.dnodes, (void *)dnode, 1, NULL);
391391
}
392-
if (spath) {
393-
char *s = strdup(spath);
392+
if (path) {
393+
char *s = strdup(path);
394394

395395
LY_CHECK_ERR_RET(!s, LOGMEM(NULL), );
396-
ly_set_add(&log_location.spaths, s, 1, NULL);
396+
ly_set_add(&log_location.paths, s, 1, NULL);
397397
}
398398
if (in) {
399399
ly_set_add(&log_location.inputs, (void *)in, 1, NULL);
400400
}
401401
}
402402

403403
void
404-
ly_log_location_revert(uint32_t scnode_steps, uint32_t dnode_steps, uint32_t spath_steps, uint32_t in_steps)
404+
ly_log_location_revert(uint32_t scnode_steps, uint32_t dnode_steps, uint32_t path_steps, uint32_t in_steps)
405405
{
406406
for (uint32_t i = scnode_steps; i && log_location.scnodes.count; i--) {
407407
log_location.scnodes.count--;
@@ -411,8 +411,8 @@ ly_log_location_revert(uint32_t scnode_steps, uint32_t dnode_steps, uint32_t spa
411411
log_location.dnodes.count--;
412412
}
413413

414-
for (uint32_t i = spath_steps; i && log_location.spaths.count; i--) {
415-
ly_set_rm_index(&log_location.spaths, log_location.spaths.count - 1, free);
414+
for (uint32_t i = path_steps; i && log_location.paths.count; i--) {
415+
ly_set_rm_index(&log_location.paths, log_location.paths.count - 1, free);
416416
}
417417

418418
for (uint32_t i = in_steps; i && log_location.inputs.count; i--) {
@@ -426,8 +426,8 @@ ly_log_location_revert(uint32_t scnode_steps, uint32_t dnode_steps, uint32_t spa
426426
if (dnode_steps && !log_location.dnodes.count) {
427427
ly_set_erase(&log_location.dnodes, NULL);
428428
}
429-
if (spath_steps && !log_location.spaths.count) {
430-
ly_set_erase(&log_location.spaths, free);
429+
if (path_steps && !log_location.paths.count) {
430+
ly_set_erase(&log_location.paths, free);
431431
}
432432
if (in_steps && !log_location.inputs.count) {
433433
ly_set_erase(&log_location.inputs, NULL);
@@ -808,21 +808,38 @@ ly_vlog_build_data_path(const struct ly_ctx *ctx, char **path)
808808
static LY_ERR
809809
ly_vlog_build_path_line(const struct ly_ctx *ctx, char **data_path, char **schema_path, uint64_t *line)
810810
{
811+
int r;
812+
char *path;
813+
811814
*data_path = NULL;
812815
*schema_path = NULL;
813816
*line = 0;
814817

815-
if (log_location.spaths.count && ((const char *)(log_location.spaths.objs[log_location.spaths.count - 1]))[0]) {
816-
/* simply get what is in the provided path string */
817-
*schema_path = strdup(log_location.spaths.objs[log_location.spaths.count - 1]);
818+
/* data/schema node */
819+
if (log_location.dnodes.count) {
820+
LY_CHECK_RET(ly_vlog_build_data_path(ctx, data_path));
821+
} else if (log_location.scnodes.count) {
822+
*schema_path = lysc_path(log_location.scnodes.objs[log_location.scnodes.count - 1], LYSC_PATH_LOG, NULL, 0);
818823
LY_CHECK_ERR_RET(!*schema_path, LOGMEM(ctx), LY_EMEM);
819-
} else {
820-
/* data/schema node */
821-
if (log_location.dnodes.count) {
822-
LY_CHECK_RET(ly_vlog_build_data_path(ctx, data_path));
823-
} else if (log_location.scnodes.count) {
824-
*schema_path = lysc_path(log_location.scnodes.objs[log_location.scnodes.count - 1], LYSC_PATH_LOG, NULL, 0);
825-
LY_CHECK_ERR_RET(!*schema_path, LOGMEM(ctx), LY_EMEM);
824+
}
825+
826+
if (log_location.paths.count && ((const char *)(log_location.paths.objs[log_location.paths.count - 1]))[0]) {
827+
/* append the provided path string to data/schema path, if any */
828+
if (*data_path) {
829+
r = asprintf(&path, "%s%s", *data_path, (char *)log_location.paths.objs[log_location.paths.count - 1]);
830+
} else if (*schema_path) {
831+
r = asprintf(&path, "%s%s", *schema_path, (char *)log_location.paths.objs[log_location.paths.count - 1]);
832+
} else {
833+
r = asprintf(&path, "%s", (char *)log_location.paths.objs[log_location.paths.count - 1]);
834+
}
835+
LY_CHECK_ERR_RET(r == -1, LOGMEM(ctx), LY_EMEM);
836+
837+
if (*data_path) {
838+
free(*data_path);
839+
*data_path = path;
840+
} else {
841+
free(*schema_path);
842+
*schema_path = path;
826843
}
827844
}
828845

src/ly_common.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ struct ly_log_location_s {
7575
struct ly_set inputs; /**< Set of const struct ly_in *in pointers providing the input handler with the line information (LIFO) */
7676
struct ly_set scnodes; /**< Set of const struct lysc_node *scnode pointers providing the compiled schema node to generate path (LIFO) */
7777
struct ly_set dnodes; /**< Set of const struct lyd_node *dnode pointers providing the data node to generate path (LIFO) */
78-
struct ly_set spaths; /**< Set of schema path strings (LIFO) */
78+
struct ly_set paths; /**< Set of path strings (LIFO) */
7979
};
8080

8181
/**
@@ -122,21 +122,21 @@ void ly_err_move(struct ly_ctx *src_ctx, struct ly_ctx *trg_ctx);
122122
*
123123
* @param[in] scnode Compiled schema node.
124124
* @param[in] dnode Data node.
125-
* @param[in] spath Direct schema path string to print.
125+
* @param[in] path Direct path string to append and print.
126126
* @param[in] in Input handler (providing line number).
127127
*/
128128
void ly_log_location(const struct lysc_node *scnode, const struct lyd_node *dnode,
129-
const char *spath, const struct ly_in *in);
129+
const char *path, const struct ly_in *in);
130130

131131
/**
132132
* @brief Revert the specific logger location data by number of changes made by ::ly_log_location().
133133
*
134134
* @param[in] scnode_steps Number of items in ::ly_log_location_s.scnodes to forget.
135135
* @param[in] dnode_steps Number of items in ::ly_log_location_s.dnodes to forget.
136-
* @param[in] spath_steps Number of path strings in ::ly_log_location_s.spaths to forget.
136+
* @param[in] path_steps Number of path strings in ::ly_log_location_s.paths to forget.
137137
* @param[in] in_steps Number of input handlers ::ly_log_location_s.inputs to forget.
138138
*/
139-
void ly_log_location_revert(uint32_t scnode_steps, uint32_t dnode_steps, uint32_t spath_steps, uint32_t in_steps);
139+
void ly_log_location_revert(uint32_t scnode_steps, uint32_t dnode_steps, uint32_t path_steps, uint32_t in_steps);
140140

141141
/**
142142
* @brief Get the stored data node for logging at the index.

src/parser_common.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ lyd_parser_create_meta(struct lyd_ctx *lydctx, struct lyd_node *parent, struct l
321321
void *prefix_data, uint32_t hints, const struct lysc_node *ctx_node)
322322
{
323323
LY_ERR rc = LY_SUCCESS;
324-
char *dpath = NULL, *path = NULL;
324+
char *path = NULL;
325325
ly_bool incomplete;
326326
struct lyd_meta *first = NULL;
327327
ly_bool store_only = (lydctx->parse_opts & LYD_PARSE_STORE_ONLY) == LYD_PARSE_STORE_ONLY ? 1 : 0;
@@ -332,8 +332,7 @@ lyd_parser_create_meta(struct lyd_ctx *lydctx, struct lyd_node *parent, struct l
332332
}
333333

334334
/* generate path to the metadata */
335-
LY_CHECK_RET(ly_vlog_build_data_path(lydctx->data_ctx->ctx, &dpath));
336-
if (asprintf(&path, "%s/@%s:%.*s", dpath, mod->name, (int)name_len, name) == -1) {
335+
if (asprintf(&path, "/@%s:%.*s", mod->name, (int)name_len, name) == -1) {
337336
LOGMEM(lydctx->data_ctx->ctx);
338337
rc = LY_EMEM;
339338
goto cleanup;
@@ -354,7 +353,6 @@ lyd_parser_create_meta(struct lyd_ctx *lydctx, struct lyd_node *parent, struct l
354353

355354
cleanup:
356355
ly_log_location_revert(0, 0, 1, 0);
357-
free(dpath);
358356
free(path);
359357
return rc;
360358
}

src/schema_compile.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,11 +1056,9 @@ lys_compile_unres_llist_dflts(struct lysc_ctx *ctx, struct lysc_node_leaflist *l
10561056
for (u = orig_count; u < LY_ARRAY_COUNT(llist->dflts); ++u) {
10571057
for (v = 0; v < u; ++v) {
10581058
if (!llist->dflts[u]->realtype->plugin->compare(ctx->ctx, llist->dflts[u], llist->dflts[v])) {
1059-
lysc_update_path(ctx, llist->parent ? llist->parent->module : NULL, llist->name);
10601059
LOGVAL(ctx->ctx, LYVE_SEMANTICS, "Configuration leaf-list has multiple defaults of the same value \"%s\".",
10611060
(char *)llist->dflts[u]->realtype->plugin->print(ctx->ctx, llist->dflts[u], LY_VALUE_CANON,
10621061
NULL, NULL, NULL));
1063-
lysc_update_path(ctx, NULL, NULL);
10641062
return LY_EVALID;
10651063
}
10661064
}

0 commit comments

Comments
 (0)