"Fossies" - the Fresh Open Source Software Archive

Member "httperf-0.9.0/src/gen/call_seq.c" (7 Apr 2007, 3874 Bytes) of package /linux/www/old/httperf-0.9.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "call_seq.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2     httperf -- a tool for measuring web server performance
    3     Copyright 2000-2007 Hewlett-Packard Company and Contributors listed in
    4     AUTHORS file. Originally contributed by David Mosberger-Tang
    5 
    6     This file is part of httperf, a web server performance measurment
    7     tool.
    8 
    9     This program is free software; you can redistribute it and/or
   10     modify it under the terms of the GNU General Public License as
   11     published by the Free Software Foundation; either version 2 of the
   12     License, or (at your option) any later version.
   13     
   14     In addition, as a special exception, the copyright holders give
   15     permission to link the code of this work with the OpenSSL project's
   16     "OpenSSL" library (or with modified versions of it that use the same
   17     license as the "OpenSSL" library), and distribute linked combinations
   18     including the two.  You must obey the GNU General Public License in
   19     all respects for all of the code used other than "OpenSSL".  If you
   20     modify this file, you may extend this exception to your version of the
   21     file, but you are not obligated to do so.  If you do not wish to do
   22     so, delete this exception statement from your version.
   23 
   24     This program is distributed in the hope that it will be useful,
   25     but WITHOUT ANY WARRANTY; without even the implied warranty of
   26     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   27     General Public License for more details.
   28 
   29     You should have received a copy of the GNU General Public License
   30     along with this program; if not, write to the Free Software
   31     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
   32     02110-1301, USA
   33 */
   34 
   35 /* Issue a sequence of calls on a connection.  */
   36 
   37 #include <assert.h>
   38 
   39 #include <httperf.h>
   40 #include <call.h>
   41 #include <core.h>
   42 #include <event.h>
   43 #include <conn.h>
   44 
   45 #define CONN_PRIVATE_DATA(c) \
   46   ((Conn_Private_Data *) ((char *)(c) + conn_private_data_offset))
   47 
   48 #define MIN(a,b)    ((a) < (b) ? (a) : (b))
   49 
   50 typedef struct Conn_Private_Data
   51   {
   52     int num_calls;
   53     int num_completed;
   54     int num_destroyed;
   55   }
   56 Conn_Private_Data;
   57 
   58 static size_t conn_private_data_offset;
   59 
   60 static void
   61 issue_calls (Conn *conn)
   62 {
   63   Conn_Private_Data *priv;
   64   Call *call;
   65   int i;
   66 
   67   priv = CONN_PRIVATE_DATA (conn);
   68   priv->num_completed = 0;
   69   priv->num_destroyed = 0;
   70 
   71   for (i = 0; i < param.burst_len; ++i)
   72     if (priv->num_calls++ < param.num_calls)
   73       {
   74     call = call_new ();
   75     if (call)
   76       {
   77         core_send (conn, call);
   78         call_dec_ref (call);
   79       }
   80       }
   81 }
   82 
   83 static void
   84 conn_connected (Event_Type et, Conn *conn)
   85 {
   86   assert (et == EV_CONN_CONNECTED && object_is_conn (conn));
   87 
   88   issue_calls (conn);
   89 }
   90 
   91 static void
   92 call_done (Event_Type et, Call *call)
   93 {
   94   Conn *conn = call->conn;
   95   Conn_Private_Data *priv;
   96 
   97   assert (et == EV_CALL_RECV_STOP && conn && object_is_conn (conn));
   98 
   99   priv = CONN_PRIVATE_DATA (conn);
  100   ++priv->num_completed;
  101 }
  102 
  103 static void
  104 call_destroyed (Event_Type et, Call *call)
  105 {
  106   Conn_Private_Data *priv;
  107   Conn *conn;
  108 
  109   assert (et == EV_CALL_DESTROYED && object_is_call (call));
  110 
  111   conn = call->conn;
  112   priv = CONN_PRIVATE_DATA (conn);
  113 
  114   if (++priv->num_destroyed >= MIN (param.burst_len, param.num_calls))
  115     {
  116       if (priv->num_completed == priv->num_destroyed
  117       && priv->num_calls < param.num_calls)
  118     issue_calls (conn);
  119       else
  120     core_close (conn);
  121     }
  122 }
  123 
  124 static void
  125 init (void)
  126 {
  127   Any_Type arg;
  128 
  129   conn_private_data_offset = object_expand (OBJ_CONN,
  130                         sizeof (Conn_Private_Data));
  131 
  132   arg.l = 0;
  133   event_register_handler (EV_CONN_CONNECTED, (Event_Handler) conn_connected,
  134               arg);
  135   event_register_handler (EV_CALL_RECV_STOP, (Event_Handler) call_done, arg);
  136   event_register_handler (EV_CALL_DESTROYED, (Event_Handler) call_destroyed,
  137               arg);
  138 }
  139 
  140 Load_Generator call_seq =
  141   {
  142     "performs a sequence of calls on a connection",
  143     init,
  144     no_op,
  145     no_op
  146   };