⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wsesslog.c

📁 一个WEB服务器的性能测试工具
💻 C
📖 第 1 页 / 共 2 页
字号:
  if (priv->num_calls_destroyed >= priv->total_num_reqs)    /* we're done with this session */    sess_dec_ref (sess);  else if (priv->num_calls_in_this_burst < priv->current_burst->num_reqs)    issue_calls (sess, priv);  else if (priv->num_calls_destroyed >= priv->num_calls_target)    prepare_for_next_burst (sess, priv);}/* Allocates memory for a REQ and assigns values to data members.   This is used during configuration file parsing only.  */static REQ*new_request (char *uristr){  REQ *retptr;  retptr = (REQ *) malloc (sizeof (*retptr));  if (retptr == NULL || uristr == NULL)    panic ("%s: ran out of memory while parsing %s\n",	   prog_name, param.wsesslog.file);    memset (retptr, 0, sizeof (*retptr));  retptr->uri = uristr;  retptr->uri_len = strlen (uristr);  retptr->method = HM_GET;  return retptr;}/* Like new_request except this is for burst descriptors.  */static BURST*new_burst (REQ *r){  BURST *retptr;      retptr = (BURST *) malloc (sizeof (*retptr));  if (retptr == NULL)    panic ("%s: ran out of memory while parsing %s\n",	   prog_name, param.wsesslog.file);    memset (retptr, 0, sizeof (*retptr));  retptr->user_think_time = param.wsesslog.think_time;  retptr->req_list = r;  return retptr;}/* Read in session-defining configuration file and create in-memory   data structures from which to assign uri_s to calls. */static voidparse_config (void){  FILE *fp;  int lineno, i, reqnum;  Sess_Private_Data *sptr;  char line[10000];	/* some uri's get pretty long */  char uri[10000];	/* some uri's get pretty long */  char method_str[1000];  char this_arg[10000];  char contents[10000];  double think_time;  int bytes_read;  REQ *reqptr;  BURST *bptr, *current_burst = 0;  char *from, *to, *parsed_so_far;  int ch;  int single_quoted, double_quoted, escaped, done;  fp = fopen (param.wsesslog.file, "r");  if (fp == NULL)    panic ("%s: can't open %s\n", prog_name, param.wsesslog.file);    num_templates = 0;  sptr = &session_templates[0];  for (lineno = 1; fgets (line, sizeof (line), fp); lineno++)    {      if (line[0] == '#')	continue;		/* skip over comment lines */      if (sscanf (line,"%s%n", uri, &bytes_read) != 1)	{	  /* must be a session-delimiting blank line */	  if (sptr->current_req != NULL)	    sptr++;		/* advance to next session */	  continue;	}      /* looks like a request-specifying line */      reqptr = new_request (strdup (uri));      if (sptr->current_req == NULL)	{	  num_templates++;	  if (num_templates > MAX_SESSION_TEMPLATES)	    panic ("%s: too many sessions (%d) specified in %s\n",		   prog_name, num_templates, param.wsesslog.file);  	  current_burst = sptr->current_burst = new_burst (reqptr);	}      else	{	  if (!isspace (line[0]))	    /* this uri starts a new burst */	    current_burst = (current_burst->next = new_burst (reqptr));	  else	    sptr->current_req->next = reqptr;	}      /* do some common steps for all new requests */      current_burst->num_reqs++;      sptr->total_num_reqs++;      sptr->current_req = reqptr;      /* parse rest of line to specify additional parameters of this	 request and burst */      parsed_so_far = line + bytes_read;      while (sscanf (parsed_so_far, " %s%n", this_arg, &bytes_read) == 1)	{	  if (sscanf (this_arg, "method=%s", method_str) == 1)	    {	      for (i = 0; i < HM_LEN; i++)		{		  if (!strncmp (method_str,call_method_name[i],				strlen (call_method_name[i])))		    {		      sptr->current_req->method = i;		      break;		    }		}	      if (i == HM_LEN)		panic ("%s: did not recognize method '%s' in %s\n",		       prog_name, method_str, param.wsesslog.file);  	    }	  else if (sscanf (this_arg, "think=%lf", &think_time) == 1)	    current_burst->user_think_time = think_time;	  else if (sscanf (this_arg, "contents=%s", contents) == 1)	    {	      /* this is tricky since contents might be a quoted		 string with embedded spaces or escaped quotes.  We		 should parse this carefully from parsed_so_far */	      from = strchr (parsed_so_far, '=') + 1;	      to = contents;	      single_quoted = FALSE;	      double_quoted = FALSE;	      escaped = FALSE;	      done = FALSE;	      while ((ch = *from++) != '\0' && !done)		{		  if (escaped == TRUE)		    {		      switch (ch)			{			case 'n':			  *to++ = '\n';			  break;			case 'r':			  *to++ = '\r';			  break;			case 't':			  *to++ = '\t';			  break;			case '\n':			  *to++ = '\n';			  /* this allows an escaped newline to			     continue the parsing to the next line. */			  if (fgets(line,sizeof(line),fp) == NULL)			    {			      lineno++;			      panic ("%s: premature EOF seen in '%s'\n",				     prog_name, param.wsesslog.file);  			    }			  parsed_so_far = from = line;			  break;			default:			  *to++ = ch;			  break;			}		      escaped = FALSE;		    }		  else if (ch == '"' && double_quoted)		    {		      double_quoted = FALSE;		    }		  else if (ch == '\'' && single_quoted)		    {		      single_quoted = FALSE;		    }		  else		    {		      switch (ch)			{			case '\t':			case '\n':			case ' ':			  if (single_quoted == FALSE &&			      double_quoted == FALSE)			    done = TRUE;	/* we are done */			  else			    *to++ = ch;			  break;			case '\\':		/* backslash */			  escaped = TRUE;			  break;			case '"':		/* double quote */			  if (single_quoted)			    *to++ = ch;			  else			    double_quoted = TRUE;			  break;			case '\'':		/* single quote */			  if (double_quoted)			    *to++ = ch;			  else			    single_quoted = TRUE;			  break;			default:			  *to++ = ch;			  break;			}		    }		}	      *to = '\0';	      from--;		/* back up 'from' to '\0' or white-space */	      bytes_read = from - parsed_so_far;	      if ((sptr->current_req->contents_len = strlen (contents)) != 0)		{		  sptr->current_req->contents = strdup (contents);		  sprintf (sptr->current_req->extra_hdrs,			    "Content-length: %d\r\n",			   sptr->current_req->contents_len);		  sptr->current_req->extra_hdrs_len =		    strlen (sptr->current_req->extra_hdrs);		}	    }	  else	    {	      /* do not recognize this arg */	      panic ("%s: did not recognize arg '%s' in %s\n",		     prog_name, this_arg, param.wsesslog.file);  	    }	  parsed_so_far += bytes_read;	}    }  fclose (fp);  if (DBG > 3)    {      fprintf (stderr,"%s: session list follows:\n\n", prog_name);      for (i = 0; i < num_templates; i++)	{	  sptr = &session_templates[i];	  fprintf (stderr, "#session %d (total_reqs=%d):\n",		   i, sptr->total_num_reqs);	    	  for (bptr = sptr->current_burst; bptr; bptr = bptr->next)	    {	      for (reqptr = bptr->req_list, reqnum = 0;		   reqptr;		   reqptr = reqptr->next, reqnum++)		{		  if (reqnum >= bptr->num_reqs)		    panic ("%s: internal error detected in parsing %s\n",			   prog_name, param.wsesslog.file);  		  if (reqnum > 0)		    fprintf (stderr, "\t");		  fprintf (stderr, "%s", reqptr->uri);		  if (reqnum == 0		      && bptr->user_think_time != param.wsesslog.think_time)		    fprintf (stderr, " think=%0.2f",			     (double) bptr->user_think_time);		  if (reqptr->method != HM_GET)		    fprintf (stderr," method=%s",			     call_method_name[reqptr->method]);		  if (reqptr->contents != NULL)		    fprintf (stderr, " contents='%s'", reqptr->contents);		  fprintf (stderr, "\n");		}	    }	  fprintf (stderr, "\n");	}    }}static voidinit (void){  Any_Type arg;  parse_config ();  sess_private_data_offset = object_expand (OBJ_SESS,					    sizeof (Sess_Private_Data));  rg_sess.rate = &param.rate;  rg_sess.tick = sess_create;  rg_sess.arg.l = 0;  arg.l = 0;  event_register_handler (EV_SESS_DESTROYED, sess_destroyed, arg);  event_register_handler (EV_CALL_DESTROYED, call_destroyed, arg);  /* This must come last so the session event handlers are executed     before this module's handlers.  */  session_init ();}static voidstart (void){  rate_generator_start (&rg_sess, EV_SESS_DESTROYED);}Load_Generator wsesslog =  {    "creates log-based session workload",    init,    start,    no_op  };

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -