For STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED, the outer loop should use 
combined_counter_vec, not simple_counter_vec.

The current code likely works  because both members are in the same union in 
stat_segment_data_t, so the top-level vector pointer aliases the same storage.

I found the same pattern in:
  - src/vpp/app/vpp_get_stats.c (stat_poll_loop())
  - src/vpp/app/dump_metrics.c (print_metric_v1())
  - src/plugins/prom/prom.c (dump_counter_vector_combined())
  - src/plugins/sflow/sflow.c (update_counter_vector_combined())

Jerome

De : [email protected] <[email protected]> de la part de Matthew Smith via 
lists.fd.io <[email protected]>
Date : mardi, 24 mars 2026 à 14:38
À : [email protected] <[email protected]>
Objet : Re: [vpp-dev] stats: is this a bug in iterating over 
combined_counter_vec ?

Hi Paul,

I'm not an expert on that code, but it looks to me like you're right - the 
outer loop should use combined_counter_vec.

-Matt


On Fri, Mar 20, 2026 at 1:19 PM G. Paul Ziemba via 
lists.fd.io<http://lists.fd.io> 
<[email protected]<mailto:[email protected]>> wrote:
I'm doing a bit of refactoring in vpp/app/vpp_get_stats.c and I am
scratching my head over the following bit of code. Please note
simple_counter_vec vs. combined_counter_vec.

It seems to me that the outer loop should also use combined_counter_vec.
Is my view correct? I'll make a fix.

vpp/app/vpp_get_stats.c stat_poll_loop()
            case STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED:
              for (k = 0; k < vec_len (res[i].simple_counter_vec); k++)
                for (j = 0; j < vec_len (res[i].combined_counter_vec[k]); j++)
                  fformat (stdout, "[%d]: %llu packets, %llu bytes %s\n",
                           j, res[i].combined_counter_vec[k][j].packets,
                           res[i].combined_counter_vec[k][j].bytes,
                           res[i].name);
              break;

The same kind of iterating is also present here:

vpp/app/dump_metrics.c print_metric_v1()
    case STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED:
      fformat (stream, "# TYPE %s_packets counter\n", prom_string (res->name));
      fformat (stream, "# TYPE %s_bytes counter\n", prom_string (res->name));
      for (k = 0; k < vec_len (res->simple_counter_vec); k++)
        for (j = 0; j < vec_len (res->combined_counter_vec[k]); j++)
          {
            fformat (stream,
                     "%s_packets{thread=\"%d\",interface=\"%d\"} %lld\n",
                     prom_string (res->name), k, j,
                     res->combined_counter_vec[k][j].packets);
            fformat (stream, "%s_bytes{thread=\"%d\",interface=\"%d\"} %lld\n",
                     prom_string (res->name), k, j,
                     res->combined_counter_vec[k][j].bytes);
          }
      break;

This other piece of code seems correct:

vpp/app/vpp_get_stats.c main()
            case STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED:
              if (res[i].combined_counter_vec == 0)
                continue;
              for (k = 0; k < vec_len (res[i].combined_counter_vec); k++)
                for (j = 0; j < vec_len (res[i].combined_counter_vec[k]); j++)
--
G. Paul Ziemba
FreeBSD unix:
11:16AM  up 36 days, 14:10, 26 users, load averages: 0.45, 0.43, 0.34



-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#26904): https://lists.fd.io/g/vpp-dev/message/26904
Mute This Topic: https://lists.fd.io/mt/118422723/21656
Group Owner: [email protected]
Unsubscribe: https://lists.fd.io/g/vpp-dev/leave/14379924/21656/631435203/xyzzy 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to