Changeset a103e782d9ad5e36286df42628dd09e0cb874d6f

Show
Ignore:
Timestamp:
09/13/09 14:40:29 (5 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1252852829 +0000
git-parent:

[9f36fc28a66a07bec282ecc4145903b2187c355a]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1252852829 +0000
Message:

refactor for external use

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/noit_check.h

    r88a7178 ra103e78  
    212212  noit_check_state_string(int16_t state); 
    213213API_EXPORT(int) 
     214  noit_stats_snprint_metric_value(char *b, int l, metric_t *m); 
     215API_EXPORT(int) 
    214216  noit_stats_snprint_metric(char *b, int l, metric_t *m); 
    215217 
  • src/noit_check_log.c

    r88a7178 ra103e78  
    215215 
    216216int 
    217 noit_stats_snprint_metric(char *b, int l, metric_t *m) { 
     217noit_stats_snprint_metric_value(char *b, int l, metric_t *m) { 
    218218  int rv; 
    219219  if(!m->metric_value.s) { /* they are all null */ 
    220     rv = snprintf(b, l, "%s[%c] = [[null]]", m->metric_name, m->metric_type); 
     220    rv = snprintf(b, l, "[[null]]"); 
    221221  } 
    222222  else { 
    223223    switch(m->metric_type) { 
    224224      case METRIC_INT32: 
    225         rv = snprintf(b, l, "%s[%c] = %d", 
    226                       m->metric_name, m->metric_type, *(m->metric_value.i)); 
    227         break; 
     225        rv = snprintf(b, l, "%d", *(m->metric_value.i)); break; 
    228226      case METRIC_UINT32: 
    229         rv = snprintf(b, l, "%s[%c] = %u", 
    230                       m->metric_name, m->metric_type, *(m->metric_value.I)); 
    231         break; 
     227        rv = snprintf(b, l, "%u", *(m->metric_value.I)); break; 
    232228      case METRIC_INT64: 
    233         rv = snprintf(b, l, "%s[%c] = %lld", 
    234                       m->metric_name, m->metric_type, *(m->metric_value.l)); 
    235         break; 
     229        rv = snprintf(b, l, "%lld", *(m->metric_value.l)); break; 
    236230      case METRIC_UINT64: 
    237         rv = snprintf(b, l, "%s[%c] = %llu", 
    238                       m->metric_name, m->metric_type, *(m->metric_value.L)); 
    239         break; 
     231        rv = snprintf(b, l, "%llu", *(m->metric_value.L)); break; 
    240232      case METRIC_DOUBLE: 
    241         rv = snprintf(b, l, "%s[%c] = %.12e", 
    242                       m->metric_name, m->metric_type, *(m->metric_value.n)); 
    243         break; 
     233        rv = snprintf(b, l, "%.12e", *(m->metric_value.n)); break; 
    244234      case METRIC_STRING: 
    245         rv = snprintf(b, l, "%s[%c] = %s", 
    246                       m->metric_name, m->metric_type, m->metric_value.s); 
    247         break; 
     235        rv = snprintf(b, l, "%s", m->metric_value.s); break; 
    248236      default: 
    249         rv = snprintf(b, l, "%s has unknown metric type 0%02x", 
    250                       m->metric_name, m->metric_type); 
     237        return -1; 
    251238    } 
    252239  } 
    253240  return rv; 
    254241} 
     242int 
     243noit_stats_snprint_metric(char *b, int l, metric_t *m) { 
     244  int rv, nl; 
     245  nl = snprintf(b, l, "%s[%c] = ", m->metric_name, m->metric_type); 
     246  if(nl >= l || nl <= 0) return nl; 
     247  rv = noit_stats_snprint_metric_value(b+nl, l-nl, m); 
     248  if(rv == -1) 
     249    rv = snprintf(b+nl, l-nl, "[[unknown type]]"); 
     250  return rv + nl; 
     251}