> -----Original Message----- > From: Petr Machata [mailto:pe...@mellanox.com] > Sent: Monday, September 02, 2019 2:40 AM > To: linuxptp-devel@lists.sourceforge.net > Subject: [Linuxptp-devel] [PATCH 1/2] port: Introduce per-port stats for > received and > transmitted messages > > Add struct PortStats to keep per-port number of messages sent and received, > split by message type. Bump TX counters after messages are sent > successfully, and RX counters after a message is received. To keep things > simple, reserve one counter for each theoretically possible message type, > including the reserved ones. > > Signed-off-by: Petr Machata <pe...@mellanox.com> > --- > ddt.h | 5 +++++ > port.c | 25 +++++++++++++++++++++++-- > port_private.h | 1 + > 3 files changed, 29 insertions(+), 2 deletions(-) > > diff --git a/ddt.h b/ddt.h > index 4acaa4f..5486203 100644 > --- a/ddt.h > +++ b/ddt.h > @@ -100,4 +100,9 @@ struct FaultRecord { > struct PTPText faultDescription; > }; > > +struct PortStats { > + uint64_t rxMsgType[16]; > + uint64_t txMsgType[16];
Is there some define we could use that represents this 16, instead of just using the number? that would make it more clear why this is 16, and possibly update if that ever changes in the future. Thanks, Jake > +}; > + > #endif > diff --git a/port.c b/port.c > index 5a4a116..471e6f4 100644 > --- a/port.c > +++ b/port.c > @@ -580,6 +580,16 @@ static int path_trace_ignore(struct port *p, struct > ptp_message *m) > return 0; > } > > +static void port_stats_inc_rx(struct port *p, const struct ptp_message *msg) > +{ > + p->stats.rxMsgType[msg_type(msg)]++; > +} > + > +static void port_stats_inc_tx(struct port *p, const struct ptp_message *msg) > +{ > + p->stats.txMsgType[msg_type(msg)]++; > +} > + > static int peer_prepare_and_send(struct port *p, struct ptp_message *msg, > enum transport_event event) > { > @@ -595,6 +605,7 @@ static int peer_prepare_and_send(struct port *p, struct > ptp_message *msg, > if (cnt <= 0) { > return -1; > } > + port_stats_inc_tx(p, msg); > if (msg_sots_valid(msg)) { > ts_add(&msg->hwts.ts, p->tx_timestamp_offset); > } > @@ -2627,6 +2638,7 @@ static enum fsm_event bc_event(struct port *p, int > fd_index) > msg_put(msg); > return EV_NONE; > } > + port_stats_inc_rx(p, msg); > if (port_ignore(p, msg)) { > msg_put(msg); > return EV_NONE; > @@ -2691,14 +2703,22 @@ int port_forward(struct port *p, struct ptp_message > *msg) > { > int cnt; > cnt = transport_send(p->trp, &p->fda, TRANS_GENERAL, msg); > - return cnt <= 0 ? -1 : 0; > + if (cnt <= 0) { > + return -1; > + } > + port_stats_inc_tx(p, msg); > + return 0; > } > > int port_forward_to(struct port *p, struct ptp_message *msg) > { > int cnt; > cnt = transport_sendto(p->trp, &p->fda, TRANS_GENERAL, msg); > - return cnt <= 0 ? -1 : 0; > + if (cnt <= 0) { > + return -1; > + } > + port_stats_inc_tx(p, msg); > + return 0; > } > > int port_prepare_and_send(struct port *p, struct ptp_message *msg, > @@ -2717,6 +2737,7 @@ int port_prepare_and_send(struct port *p, struct > ptp_message *msg, > if (cnt <= 0) { > return -1; > } > + port_stats_inc_tx(p, msg); > if (msg_sots_valid(msg)) { > ts_add(&msg->hwts.ts, p->tx_timestamp_offset); > } > diff --git a/port_private.h b/port_private.h > index 9a5022d..5789fbb 100644 > --- a/port_private.h > +++ b/port_private.h > @@ -139,6 +139,7 @@ struct port { > struct fault_interval flt_interval_pertype[FT_CNT]; > enum fault_type last_fault_type; > unsigned int versionNumber; /*UInteger4*/ > + struct PortStats stats; > /* foreignMasterDS */ > LIST_HEAD(fm, foreign_clock) foreign_masters; > /* TC book keeping */ > -- > 2.20.1 > > > > _______________________________________________ > Linuxptp-devel mailing list > Linuxptp-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/linuxptp-devel _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel