Add a variable for start/current time to ctdb statistics
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 2 Jun 2010 03:13:09 +0000 (13:13 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Wed, 2 Jun 2010 03:13:09 +0000 (13:13 +1000)
and print the time startistics was taken and for how long the statistics have been collected to the "ctdb statistics" output.

client/ctdb_client.c
include/ctdb_private.h
server/ctdb_control.c
tools/ctdb.c

index 4aad40060a6fe91ea0237aad3d09803f4ff56ad2..4a307c42d878ee9b672522e2722b0d64b4f41fdb 100644 (file)
@@ -2757,6 +2757,8 @@ struct ctdb_context *ctdb_init(struct event_context *ev)
                return NULL;
        }
 
+       ctdb->statistics.statistics_start_time = timeval_current();
+
        return ctdb;
 }
 
index 6893d67b29329d37ebc2aa20a12157e2f41162e9..099182a7077dcf64dc155ed0350a698437cb5def 100644 (file)
@@ -345,6 +345,8 @@ struct ctdb_statistics {
        double max_lockwait_latency;
        double max_childwrite_latency;
        uint32_t num_recoveries;
+       struct timeval statistics_start_time;
+       struct timeval statistics_current_time;
 };
 
 
index ed7324cfcc6b3ddae26fe6fbd88acdb19aa61e42..6c101018b360b0d6cfd84e0566adec806d125e9b 100644 (file)
@@ -108,6 +108,8 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                        }
                }
                ctdb->statistics.recovering = (ctdb->recovery_mode == CTDB_RECOVERY_ACTIVE);
+               ctdb->statistics.statistics_current_time = timeval_current();
+
                outdata->dptr = (uint8_t *)&ctdb->statistics;
                outdata->dsize = sizeof(ctdb->statistics);
                return 0;
@@ -128,6 +130,7 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
        case CTDB_CONTROL_STATISTICS_RESET: {
                CHECK_CONTROL_DATA_SIZE(0);
                ZERO_STRUCT(ctdb->statistics);
+               ctdb->statistics.statistics_start_time = timeval_current();
                return 0;
        }
 
index 2939f88c57884dc76b9c156865c4c3eccb7921c2..91e8212520ad6d86363479ca36cb3c70ac1944be 100644 (file)
@@ -158,6 +158,7 @@ static void show_statistics(struct ctdb_statistics *s)
        int i;
        const char *prefix=NULL;
        int preflen=0;
+       int tmp, days, hours, minutes, seconds;
        const struct {
                const char *name;
                uint32_t offset;
@@ -196,7 +197,19 @@ static void show_statistics(struct ctdb_statistics *s)
                STATISTICS_FIELD(memory_used),
                STATISTICS_FIELD(max_hop_count),
        };
+       tmp = s->statistics_current_time.tv_sec - s->statistics_start_time.tv_sec;
+       seconds = tmp%60;
+       tmp    /= 60;
+       minutes = tmp%60;
+       tmp    /= 60;
+       hours   = tmp%24;
+       tmp    /= 24;
+       days    = tmp;
+
        printf("CTDB version %u\n", CTDB_VERSION);
+       printf("Current time of statistics  :                %s", ctime(&s->statistics_start_time.tv_sec));
+       printf("Statistics collected since  : (%03d %02d:%02d:%02d) %s", days, hours, minutes, seconds, ctime(&s->statistics_start_time.tv_sec));
+
        for (i=0;i<ARRAY_SIZE(fields);i++) {
                if (strchr(fields[i].name, '.')) {
                        preflen = strcspn(fields[i].name, ".")+1;
@@ -219,6 +232,8 @@ static void show_statistics(struct ctdb_statistics *s)
        printf(" %-30s     %.6f sec\n", "max_call_latency", s->max_call_latency);
        printf(" %-30s     %.6f sec\n", "max_lockwait_latency", s->max_lockwait_latency);
        printf(" %-30s     %.6f sec\n", "max_childwrite_latency", s->max_childwrite_latency);
+       printf(" %-30s     %.6f sec\n", "max_childwrite_latency", s->max_childwrite_latency);
+
        talloc_free(tmp_ctx);
 }