srfsh now:
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 1 Mar 2005 22:29:41 +0000 (22:29 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 1 Mar 2005 22:29:41 +0000 (22:29 +0000)
shows request elapsed time
formats request params as arrays internally

generic_utils:
added a get_timestamp_millis method that returns seconds.millis since epoch

git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@141 9efc2488-bf62-4759-914b-345cdb29e865

include/opensrf/generic_utils.h
src/libtransport/generic_utils.c
src/srfsh/srfsh.c

index 5144328..0c629d1 100644 (file)
@@ -53,6 +53,7 @@ void log_free();
 
 // Utility method
 void get_timestamp( char buf_36chars[]);
+double get_timestamp_millis();
 
 // ---------------------------------------------------------------------------------
 // Error handling interface.
index f83e19a..4de95fb 100644 (file)
@@ -16,7 +16,13 @@ void get_timestamp( char buf_36chars[]) {
        strcat(buf_36chars,mil);
        free(localtime);
 }
-
+double get_timestamp_millis() {
+       struct timeb t;
+       ftime(&t);
+       double time     = ( (int)t.time + ( ((float)t.millitm) / 1000 ) );
+       return time;
+}
+       
 
 inline void* safe_malloc( int size ) {
        void* ptr = (void*) malloc( size );
index 3eee7b3..36175df 100644 (file)
@@ -56,21 +56,31 @@ int main( int argc, char* argv[] ) {
                }
 
                if(!strcmp(request,"last")) {
-                       memset(request,0,256);
-                       strcpy(request, last_request);
-                       printf("%s\n", request);
-               } else {
-                       free(last_request);
-                       last_request = strdup(request);
+                       if(last_request) {
+                               memset(request,0,256);
+                               strcpy(request, last_request);
+                               printf("%s\n", request);
+                       } else {
+                               printf(prompt);
+                               continue;
+                       }
                }
 
+               char* req_copy = strdup(request);
+
                if( !strcmp(request, "help") || !strcmp(request,"?")) 
                        print_help();
-               else 
-                       parse_request( request );
+               else {
+                       if(parse_request( req_copy ) && strcmp(request,"last") ) {
+                               free(last_request);
+                               last_request = strdup(request);
+                       }
+               }
+
 
                printf(prompt);
                memset(request, 0, 300);
+               free(req_copy);
        }
 
        fprintf(stderr, "Exiting...\n[Ignore Segfault]\n");
@@ -183,10 +193,12 @@ int handle_request( char* words[] ) {
                int i;
                growing_buffer* buffer = buffer_init(128);
 
+               buffer_add(buffer, "[");
                for(i = 3; words[i] != NULL; i++ ) {
                        buffer_add( buffer, words[i] );
                        buffer_add(buffer, " ");
                }
+               buffer_add(buffer, "]");
 
                return send_request( server, method, buffer );
        } 
@@ -203,6 +215,13 @@ int send_request( char* server, char* method, growing_buffer* buffer ) {
                params = json_tokener_parse(buffer->buf);
 
        osrf_app_session* session = osrf_app_client_session_init(server);
+       double start = get_timestamp_millis();
+
+       if(!osrf_app_session_connect(session)) {
+               warning_handler( "Unable to connect to remote service %s\n", server );
+               return 1;
+       }
+
        int req_id = osrf_app_session_make_request( session, params, method, 1 );
 
        osrf_message* omsg = osrf_app_session_request_recv( session, req_id, 8 );
@@ -214,6 +233,9 @@ int send_request( char* server, char* method, growing_buffer* buffer ) {
        while(omsg) {
                if(omsg->result_content) 
                        printf( "Received Data: %s\n",json_object_to_json_string(omsg->result_content) );
+               else
+                       printf( "Received Message but no result data\n");
+
                osrf_message_free(omsg);
                omsg = osrf_app_session_request_recv( session, req_id, 5 );
        }
@@ -222,6 +244,10 @@ int send_request( char* server, char* method, growing_buffer* buffer ) {
        if( osrf_app_session_request_complete( session, req_id ))
                printf("[Request Completed Successfully]\n");
 
+       double end = get_timestamp_millis();
+
+       printf("Request Time in seconds: %f\n", end - start );
+
        osrf_app_session_disconnect( session );
 
        return 1;
@@ -301,7 +327,9 @@ void print_help() {
                        "time <timestamp>       - Formats seconds since epoch into readable format\n"   
                        "---------------------------------------------------------------------------------\n"
                        "router query servers <server1 [, server2, ...]>\n"
-                       "reqeust <service> <method> [ <json formatted string of params as an array> ]\n"
+                       "       - Returns stats on connected services\n"
+                       "reqeust <service> <method> [ <json formatted string of params> ]\n"
+                       "       - Anything passed in will be wrapped in a json array\n"
                        "---------------------------------------------------------------------------------\n"
                        );