pmlogrewrite.c (pcp-6.0.2) | : | pmlogrewrite.c (pcp-6.0.3) | ||
---|---|---|---|---|
skipping to change at line 44 | skipping to change at line 44 | |||
#include "./logger.h" | #include "./logger.h" | |||
#include <assert.h> | #include <assert.h> | |||
global_t global; | global_t global; | |||
indomspec_t *indom_root; | indomspec_t *indom_root; | |||
metricspec_t *metric_root; | metricspec_t *metric_root; | |||
textspec_t *text_root; | textspec_t *text_root; | |||
labelspec_t *label_root; | labelspec_t *label_root; | |||
int lineno; | int lineno; | |||
__pmHashCtl indom_hash = { 0 }; | ||||
static pmLongOptions longopts[] = { | static pmLongOptions longopts[] = { | |||
PMAPI_OPTIONS_HEADER("Options"), | PMAPI_OPTIONS_HEADER("Options"), | |||
PMOPT_DEBUG, | PMOPT_DEBUG, | |||
{ "config", 1, 'c', "PATH", "file or directory to load rules from" }, | { "config", 1, 'c', "PATH", "file or directory to load rules from" }, | |||
{ "check", 0, 'C', 0, "parse config file(s) and quit (verbose warnings also) " }, | { "check", 0, 'C', 0, "parse config file(s) and quit (verbose warnings also) " }, | |||
{ "desperate", 0, 'd', 0, "desperate, save output archive even after error" }, | { "desperate", 0, 'd', 0, "desperate, save output archive even after error" }, | |||
{ "", 0, 'i', 0, "rewrite in place, input-archive will be over-written" }, | { "", 0, 'i', 0, "rewrite in place, input-archive will be over-written" }, | |||
{ "quick", 0, 'q', 0, "quick mode, no output if no change" }, | { "quick", 0, 'q', 0, "quick mode, no output if no change" }, | |||
{ "scale", 0, 's', 0, "do scale conversion" }, | { "scale", 0, 's', 0, "do scale conversion" }, | |||
{ "verbose", 0, 'v', 0, "increased diagnostic verbosity" }, | { "verbose", 0, 'v', 0, "increased diagnostic verbosity" }, | |||
skipping to change at line 1178 | skipping to change at line 1180 | |||
for (node = __pmHashWalk(hcp, PM_HASH_WALK_START); | for (node = __pmHashWalk(hcp, PM_HASH_WALK_START); | |||
node != NULL; | node != NULL; | |||
node = __pmHashWalk(hcp, PM_HASH_WALK_NEXT)) { | node = __pmHashWalk(hcp, PM_HASH_WALK_NEXT)) { | |||
/* | /* | |||
* if this indom has an indomspec_t, check that, else | * if this indom has an indomspec_t, check that, else | |||
* this indom will go to the archive without change | * this indom will go to the archive without change | |||
*/ | */ | |||
for (ip = indom_root; ip != NULL; ip = ip->i_next) { | for (ip = indom_root; ip != NULL; ip = ip->i_next) { | |||
if (ip->old_indom == mp->old_desc.indom) | if (ip->old_indom == mp->old_desc.indom) | |||
break; | break; | |||
if (ip->new_indom == mp->new_desc.indom) | ||||
break; | ||||
} | } | |||
if (ip == NULL) { | if (ip == NULL) { | |||
if ((pmInDom)(node->key) == mp->new_desc.indom) | if ((pmInDom)(node->key) == mp->new_desc.indom) | |||
/* we're OK */ | /* we're OK */ | |||
break; | break; | |||
} | } | |||
else { | else { | |||
if (ip->new_indom != ip->old_indom && | if (ip->new_indom != ip->old_indom && | |||
ip->new_indom == mp->new_desc.indom) | ip->new_indom == mp->new_desc.indom) | |||
/* we're OK */ | /* we're OK */ | |||
skipping to change at line 1384 | skipping to change at line 1388 | |||
} | } | |||
if (mp->new_desc.indom != PM_INDOM_NULL) { | if (mp->new_desc.indom != PM_INDOM_NULL) { | |||
/* | /* | |||
* new metric is not singular, so one_inst should be | * new metric is not singular, so one_inst should be | |||
* found in the new instance domain ... ignore one_name | * found in the new instance domain ... ignore one_name | |||
* other than to map one_name -> one_inst if one_inst | * other than to map one_name -> one_inst if one_inst | |||
* is not already known | * is not already known | |||
*/ | */ | |||
int i; | int i; | |||
ip = start_indom(mp->new_desc.indom); | ip = start_indom(mp->new_desc.indom); | |||
if (ip == NULL) { | ||||
pmsprintf(mess, sizeof(mess), "Botch: InDom %s not found" | ||||
, pmInDomStr(mp->new_desc.indom)); | ||||
yyerror(mess); | ||||
} | ||||
for (i = 0; i < ip->numinst; i++) { | for (i = 0; i < ip->numinst; i++) { | |||
if (mp->one_name != NULL) { | if (mp->one_name != NULL) { | |||
if (inst_name_eq(ip->old_iname[i], mp->one_name) > 0) { | if (inst_name_eq(ip->old_iname[i], mp->one_name) > 0) { | |||
mp->one_name = NULL; | mp->one_name = NULL; | |||
mp->one_inst = ip->old_inst[i]; | mp->one_inst = ip->old_inst[i]; | |||
break; | break; | |||
} | } | |||
} | } | |||
else if (ip->old_inst[i] == mp->one_inst) | else if (ip->old_inst[i] == mp->one_inst) | |||
break; | break; | |||
skipping to change at line 1515 | skipping to change at line 1523 | |||
int stslog; /* sts from nextlog() */ | int stslog; /* sts from nextlog() */ | |||
int stsmeta = 0; /* sts from nextmeta() */ | int stsmeta = 0; /* sts from nextmeta() */ | |||
int i; | int i; | |||
int ti_idx; /* next slot for input temporal i ndex */ | int ti_idx; /* next slot for input temporal i ndex */ | |||
int dir_fd = -1; /* poinless initialization to hum our gcc */ | int dir_fd = -1; /* poinless initialization to hum our gcc */ | |||
int doneti = 0; | int doneti = 0; | |||
__pmTimestamp tstamp = { 0, 0 }; /* for last log record */ | __pmTimestamp tstamp = { 0, 0 }; /* for last log record */ | |||
off_t old_log_offset = 0; /* log offset before last log record */ | off_t old_log_offset = 0; /* log offset before last log record */ | |||
off_t old_meta_offset; | off_t old_meta_offset; | |||
int seen_event = 0; | int seen_event = 0; | |||
metricspec_t *mp; | ||||
/* process cmd line args */ | /* process cmd line args */ | |||
if (parseargs(argc, argv) < 0) { | if (parseargs(argc, argv) < 0) { | |||
pmUsageMessage(&opts); | pmUsageMessage(&opts); | |||
exit(1); | exit(1); | |||
} | } | |||
/* input archive */ | /* input archive */ | |||
if (iflag == 0) | if (iflag == 0) | |||
inarch.name = argv[argc-2]; | inarch.name = argv[argc-2]; | |||
skipping to change at line 1735 | skipping to change at line 1744 | |||
*/ | */ | |||
exit(1); | exit(1); | |||
/*NOTREACHED*/ | /*NOTREACHED*/ | |||
} | } | |||
/* initialize and write label records */ | /* initialize and write label records */ | |||
newlabel(); | newlabel(); | |||
outarch.logctl.state = PM_LOG_STATE_INIT; | outarch.logctl.state = PM_LOG_STATE_INIT; | |||
writelabel(0); | writelabel(0); | |||
/* | ||||
* build per-indom reference counts | ||||
* ... first all metrics in the archive (note metrics with | ||||
* duplicate names are only counted once because deleting | ||||
* a metric by any name deletes the metric _and_ all of the | ||||
* names) | ||||
*/ | ||||
for (i = 0; i < inarch.ctxp->c_archctl->ac_log->hashpmid.hsize; i++) { | ||||
__pmHashNode *hp; | ||||
for (hp = inarch.ctxp->c_archctl->ac_log->hashpmid.hash[i]; hp != NULL; h | ||||
p = hp->next) { | ||||
pmDesc *dp; | ||||
__pmHashNode *ip; | ||||
int *refp; | ||||
dp = (pmDesc *)hp->data; | ||||
if (dp->indom == PM_INDOM_NULL) | ||||
continue; | ||||
if ((ip = __pmHashSearch((unsigned int)dp->indom, &indom_hash)) == NU | ||||
LL) { | ||||
/* first time we've seen this indom */ | ||||
if ((refp = (int *)malloc(sizeof(int))) == NULL) { | ||||
/* | ||||
* pretty sure we'll die with malloc() failure | ||||
* later, but for the moment just ignore this | ||||
* indom ... worst result is we don't cull an | ||||
* unreferenced indom | ||||
*/ | ||||
continue; | ||||
} | ||||
*refp = 1; | ||||
sts = __pmHashAdd((unsigned int)dp->indom, (void *)refp, &indom_h | ||||
ash); | ||||
if (sts < 0) { | ||||
fprintf(stderr, "__pmHashAdd: failed for indom %s: %s\n", pmI | ||||
nDomStr(dp->indom), pmErrStr(sts)); | ||||
free(refp); | ||||
/* | ||||
* see comment above about "worst result ..." | ||||
*/ | ||||
continue; | ||||
} | ||||
} | ||||
else { | ||||
/* not the first time, bump the refcount */ | ||||
refp = (int *)ip->data; | ||||
(*refp)++; | ||||
} | ||||
if (pmDebugOptions.appl1) { | ||||
fprintf(stderr, "ref++ InDom: %s refcnt: %d (for PMID: %s)\n", | ||||
pmInDomStr(dp->indom), *refp, pmIDStr(dp->pmid)); | ||||
} | ||||
} | ||||
} | ||||
/* | ||||
* ... next walk the metrics from the config, decrementing the | ||||
* reference count for any metrics to be deleted and maybe | ||||
* for metrics that are moving from one indom to another | ||||
*/ | ||||
for (mp = metric_root; mp != NULL; mp = mp->m_next) { | ||||
if (mp->flags & METRIC_DELETE) { | ||||
__pmHashNode *hp; | ||||
int *refp; | ||||
if (mp->old_desc.indom == PM_INDOM_NULL) | ||||
continue; | ||||
if ((hp = __pmHashSearch((unsigned int)mp->old_desc.indom, &indom_has | ||||
h)) == NULL) { | ||||
fprintf(stderr, "Botch: InDom: %s (PMID: %s): not in indom_hash t | ||||
able\n", | ||||
pmInDomStr(mp->old_desc.indom), pmIDStr(mp->old_desc.pmid)); | ||||
continue; | ||||
} | ||||
refp = (int *)hp->data; | ||||
(*refp)--; | ||||
if (pmDebugOptions.appl1) { | ||||
fprintf(stderr, "delete metric ref-- InDom: %s refcnt: %d (for PM | ||||
ID: %s)\n", | ||||
pmInDomStr(mp->old_desc.indom), *refp, pmIDStr(mp->old_desc.p | ||||
mid)); | ||||
} | ||||
} | ||||
else if (mp->flags & METRIC_CHANGE_INDOM) { | ||||
__pmHashNode *hp; | ||||
int *refp; | ||||
if (mp->old_desc.indom != PM_INDOM_NULL) { | ||||
/* decrement refcount for old indom */ | ||||
if ((hp = __pmHashSearch((unsigned int)mp->old_desc.indom, &indom | ||||
_hash)) == NULL) { | ||||
fprintf(stderr, "Botch: old InDom: %s (PMID: %s): not in indo | ||||
m_hash table\n", | ||||
pmInDomStr(mp->old_desc.indom), pmIDStr(mp->old_desc.pmid | ||||
)); | ||||
continue; | ||||
} | ||||
refp = (int *)hp->data; | ||||
(*refp)--; | ||||
if (pmDebugOptions.appl1) { | ||||
fprintf(stderr, "renumber indom ref-- InDom: %s refcnt: %d (f | ||||
or PMID: %s)\n", | ||||
pmInDomStr(mp->old_desc.indom), *refp, pmIDStr(mp->old_de | ||||
sc.pmid)); | ||||
} | ||||
} | ||||
if (mp->new_desc.indom != PM_INDOM_NULL) { | ||||
pmInDom indom; | ||||
/* | ||||
* increment refcount for new indom ... wrinkle here is | ||||
* that new indom id may have been rewritten and then | ||||
* we need to increment the refcount for the corresponding | ||||
* input archive indom | ||||
*/ | ||||
if ((hp = __pmHashSearch((unsigned int)mp->new_desc.indom, &indom | ||||
_hash)) == NULL) { | ||||
indomspec_t *ip; | ||||
/* indom is not used in input archive ... */ | ||||
/* | ||||
* if the indom is not being changed, ip will be NULL | ||||
* after this loop | ||||
*/ | ||||
for (ip = indom_root; ip != NULL; ip = ip->i_next) { | ||||
if (ip->new_indom == mp->new_desc.indom) | ||||
break; | ||||
} | ||||
if (ip == NULL) { | ||||
fprintf(stderr, "Botch: new InDom: %s (PMID: %s): not in | ||||
indom_root table\n", | ||||
pmInDomStr(mp->new_desc.indom), pmIDStr(mp->old_desc. | ||||
pmid)); | ||||
continue; | ||||
} | ||||
if ((hp = __pmHashSearch((unsigned int)ip->old_indom, &indom_ | ||||
hash)) == NULL) { | ||||
fprintf(stderr, "Botch: input InDom: %s (PMID: %s): not i | ||||
n indom_hash table\n", | ||||
pmInDomStr(ip->old_indom), pmIDStr(mp->old_desc.pmid) | ||||
); | ||||
continue; | ||||
} | ||||
indom = ip->old_indom; | ||||
} | ||||
else | ||||
indom = mp->new_desc.indom; | ||||
refp = (int *)hp->data; | ||||
(*refp)++; | ||||
if (pmDebugOptions.appl1) { | ||||
fprintf(stderr, "renumber indom ref++ InDom: %s refcnt: %d (f | ||||
or PMID: %s)\n", | ||||
pmInDomStr(indom), *refp, pmIDStr(mp->old_desc.pmid)); | ||||
} | ||||
} | ||||
} | ||||
} | ||||
first_datarec = 1; | first_datarec = 1; | |||
ti_idx = 0; | ti_idx = 0; | |||
/* | /* | |||
* loop | * loop | |||
* - get next log record | * - get next log record | |||
* - write out new/changed metadata required by this log record | * - write out new/changed metadata required by this log record | |||
* - write out log | * - write out log | |||
* - do ti update if necessary | * - do ti update if necessary | |||
*/ | */ | |||
End of changes. 5 change blocks. | ||||
0 lines changed or deleted | 162 lines changed or added |