@@ -2980,10 +2980,17 @@ istgt_uctl_cmd_iostats(UCTL_Ptr uctl)
29802980 ISTGT_LU_Ptr lu ;
29812981 int rc , length ;
29822982 uint64_t usedlogicalblocks ;
2983+ struct timespec now ;
2984+ uint64_t time_diff ;
29832985 /* instantiate json_object from json-c library. */
29842986 struct json_object * jobj ;
2985- /* these are utility variables that will be freed at the end of the function. */
2986- char * writes , * reads , * totalreadbytes , * totalwritebytes , * size , * usedblocks , * sectorsize ;
2987+ /*
2988+ * these are utility variables that will be freed
2989+ * at the end of the function.
2990+ */
2991+ char * writes , * reads , * totalreadbytes , * totalwritebytes , * size ,
2992+ * usedblocks , * sectorsize , * uptime , * totalreadtime , * totalwritetime ,
2993+ * totalreadblockcount , * totalwriteblockcount ;
29872994 ISTGT_LU_DISK * spec ;
29882995 MTX_LOCK (& specq_mtx );
29892996 TAILQ_FOREACH (spec , & spec_q , spec_next ) {
@@ -3011,33 +3018,89 @@ istgt_uctl_cmd_iostats(UCTL_Ptr uctl)
30113018 length = snprintf (NULL , 0 , "%" PRIu64 , spec -> size );
30123019 size = malloc (length + 1 );
30133020 snprintf (size , length + 1 , "%" PRIu64 , spec -> size );
3014- usedlogicalblocks = ( spec -> stats .used / spec -> blocklen ) ;
3021+
3022+ usedlogicalblocks = (spec -> stats .used / spec -> blocklen );
30153023
30163024 length = snprintf (NULL , 0 , "%" PRIu64 , usedlogicalblocks );
30173025 usedblocks = malloc (length + 1 );
3018- snprintf (usedblocks , length + 1 , "%" PRIu64 , usedlogicalblocks );
3026+ snprintf (usedblocks , length + 1 , "%" PRIu64 ,
3027+ usedlogicalblocks );
30193028
30203029 length = snprintf (NULL , 0 , "%" PRIu64 , spec -> blocklen );
30213030 sectorsize = malloc (length + 1 );
30223031 snprintf (sectorsize , length + 1 , "%" PRIu64 , spec -> blocklen );
30233032
3033+ length = snprintf (NULL , 0 , "%" PRIu64 , spec -> totalreadtime );
3034+ totalreadtime = malloc (length + 1 );
3035+ snprintf (totalreadtime , length + 1 , "%" PRIu64 ,
3036+ spec -> totalreadtime );
3037+
3038+ length = snprintf (NULL , 0 , "%" PRIu64 , spec -> totalwritetime );
3039+ totalwritetime = malloc (length + 1 );
3040+ snprintf (totalwritetime , length + 1 , "%" PRIu64 ,
3041+ spec -> totalwritetime );
3042+
3043+ length = snprintf (NULL , 0 , "%" PRIu64 ,
3044+ spec -> totalwriteblockcount );
3045+ totalwriteblockcount = malloc (length + 1 );
3046+ snprintf (totalwriteblockcount , length + 1 , "%" PRIu64 ,
3047+ spec -> totalwriteblockcount );
3048+
3049+ length = snprintf (NULL , 0 , "%" PRIu64 ,
3050+ spec -> totalreadblockcount );
3051+ totalreadblockcount = malloc (length + 1 );
3052+ snprintf (totalreadblockcount , length + 1 , "%" PRIu64 ,
3053+ spec -> totalreadblockcount );
3054+
3055+ clock_gettime (CLOCK_MONOTONIC_RAW , & now );
3056+ time_diff = (uint64_t )(now .tv_sec - istgt_start_time .tv_sec );
3057+ length = snprintf (NULL , 0 , "%" PRIu64 , time_diff );
3058+ uptime = malloc (length + 1 );
3059+ snprintf (uptime , length + 1 , "%" PRIu64 , time_diff );
3060+
30243061 json_object * jreads = json_object_new_string (reads ); /* instantiate child object */
30253062 json_object * jwrites = json_object_new_string (writes );
3026- json_object * jtotalreadbytes = json_object_new_string (totalreadbytes );
3027- json_object * jtotalwritebytes = json_object_new_string (totalwritebytes );
3063+ json_object * jtotalreadbytes =
3064+ json_object_new_string (totalreadbytes );
3065+ json_object * jtotalwritebytes =
3066+ json_object_new_string (totalwritebytes );
30283067 json_object * jsize = json_object_new_string (size );
3029- json_object * jusedlogicalblocks = json_object_new_string (usedblocks );
3068+ json_object * jusedlogicalblocks =
3069+ json_object_new_string (usedblocks );
30303070 json_object * jsectorsize = json_object_new_string (sectorsize );
3031-
3032- json_object_object_add (jobj , "WriteIOPS" , jwrites ); /* add values to object field */
3071+ json_object * juptime = json_object_new_string (uptime );
3072+ json_object * jtotalreadtime = json_object_new_string (
3073+ totalreadtime );
3074+ json_object * jtotalwritetime = json_object_new_string (
3075+ totalwritetime );
3076+ json_object * jtotalreadblockcount = json_object_new_string (
3077+ totalreadblockcount );
3078+ json_object * jtotalwriteblockcount = json_object_new_string (
3079+ totalwriteblockcount );
3080+
3081+ json_object_object_add (jobj , "WriteIOPS" ,
3082+ jwrites ); /* add values to object field */
30333083 json_object_object_add (jobj , "ReadIOPS" , jreads );
3034- json_object_object_add (jobj , "TotalWriteBytes" , jtotalwritebytes );
3035- json_object_object_add (jobj , "TotalReadBytes" , jtotalreadbytes );
3084+ json_object_object_add (jobj , "TotalWriteBytes" ,
3085+ jtotalwritebytes );
3086+ json_object_object_add (jobj , "TotalReadBytes" ,
3087+ jtotalreadbytes );
30363088 json_object_object_add (jobj , "Size" , jsize );
3037- json_object_object_add (jobj , "UsedLogicalBlocks" , jusedlogicalblocks );
3089+ json_object_object_add (jobj , "UsedLogicalBlocks" ,
3090+ jusedlogicalblocks );
30383091 json_object_object_add (jobj , "SectorSize" , jsectorsize );
3039-
3040- istgt_uctl_snprintf (uctl , "%s %s\n" , uctl -> cmd , json_object_to_json_string (jobj ));
3092+ json_object_object_add (jobj , "Uptime" , juptime );
3093+ json_object_object_add (jobj , "TotalReadTime" ,
3094+ jtotalreadtime );
3095+ json_object_object_add (jobj , "TotalWriteTime" ,
3096+ jtotalwritetime );
3097+ json_object_object_add (jobj , "TotalReadBlockCount" ,
3098+ jtotalreadblockcount );
3099+ json_object_object_add (jobj , "TotalWriteBlockCount" ,
3100+ jtotalwriteblockcount );
3101+
3102+ istgt_uctl_snprintf (uctl , "%s %s\n" ,
3103+ uctl -> cmd , json_object_to_json_string (jobj ));
30413104 rc = istgt_uctl_writeline (uctl );
30423105 if (rc != UCTL_CMD_OK ){
30433106 // free the pointers
@@ -3048,6 +3111,11 @@ istgt_uctl_cmd_iostats(UCTL_Ptr uctl)
30483111 free (size );
30493112 free (usedblocks );
30503113 free (sectorsize );
3114+ free (uptime );
3115+ free (totalreadtime );
3116+ free (totalwritetime );
3117+ free (totalreadblockcount );
3118+ free (totalwriteblockcount );
30513119 /* freeing root json_object will free all the allocated memory
30523120 ** associated with the json_object.
30533121 */
@@ -3062,6 +3130,11 @@ istgt_uctl_cmd_iostats(UCTL_Ptr uctl)
30623130 free (size );
30633131 free (usedblocks );
30643132 free (sectorsize );
3133+ free (uptime );
3134+ free (totalreadtime );
3135+ free (totalwritetime );
3136+ free (totalreadblockcount );
3137+ free (totalwriteblockcount );
30653138 json_object_put (jobj );
30663139 }
30673140 MTX_UNLOCK (& specq_mtx );
0 commit comments