Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief Common routines for system benchmarking
0003  *
0004  * @file benchmark.c
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 
0035 /*---------------------------Includes-----------------------------------*/
0036 #include <ndrstandard.h>
0037 #include <time.h>
0038 #include <sys/time.h>
0039 #include <stdlib.h>
0040 #include <string.h>
0041 #include <stdio.h>
0042 #include <sys/stat.h>
0043 #include <ctype.h>
0044 #include <pthread.h>
0045 #include <unistd.h>
0046 #include <errno.h>
0047 #include "ndebug.h"
0048 #include "nstdutil.h"
0049 
0050 /*---------------------------Externs------------------------------------*/
0051 /*---------------------------Macros-------------------------------------*/
0052 /* Enduro/X Benchmarking: */
0053 #define CONF_NDRX_BENCH_FILE        "NDRX_BENCH_FILE"       /* Benchmark output file */
0054 #define CONF_NDRX_BENCH_CONFIGNAME  "NDRX_BENCH_CONFIGNAME" /* Benchmark configuration description */
0055 /*---------------------------Enums--------------------------------------*/
0056 /*---------------------------Typedefs-----------------------------------*/
0057 /*---------------------------Globals------------------------------------*/
0058 /*---------------------------Statics------------------------------------*/
0059 /*---------------------------Prototypes---------------------------------*/
0060 
0061 /**
0062  * Write the benchmark statistics for later document processing (i.e. charting)
0063  * We will use following env variables:
0064  * - NDRX_BENCH_FILE - where to plot the output
0065  * @param param1
0066  * @param param2
0067  * @return SUCCEED/FAIL
0068  */
0069 expublic int ndrx_bench_write_stats(double msgsize, double callspersec)
0070 {
0071     static char *file;
0072     static char *config_name;
0073     static int first = EXTRUE;
0074     int ret = EXSUCCEED;
0075     FILE *f = NULL;
0076     
0077     if (first)
0078     {
0079         file = getenv(CONF_NDRX_BENCH_FILE);
0080         config_name = getenv(CONF_NDRX_BENCH_CONFIGNAME);
0081         first = EXFALSE;
0082     }
0083     
0084     if (NULL!=file && NULL!=config_name)
0085     {
0086         if( access( file, F_OK ) != EXFAIL )
0087         {
0088             if (NULL==(f=NDRX_FOPEN(file, "a")))
0089             {
0090                 NDRX_LOG(log_error, "Failed to open [%s]: %s", file, strerror(errno));
0091                 EXFAIL_OUT(ret);
0092             }   
0093         }
0094         else
0095         {
0096             /* file doesn't exist - create */
0097             if (NULL==(f=NDRX_FOPEN(file, "w")))
0098             {
0099                 NDRX_LOG(log_error, "Failed to open [%s]: %s", file, strerror(errno));
0100                 EXFAIL_OUT(ret);
0101             }
0102             
0103             fprintf(f, "\"Configuration\" \"MsgSize\" \"CallsPerSec\"\n");
0104         }
0105         fprintf(f, "\"%s\" %.0lf %.0lf\n", config_name, msgsize, callspersec);
0106     }
0107     else
0108     {
0109         NDRX_LOG(log_error, "%s or %s not set!", CONF_NDRX_BENCH_FILE, CONF_NDRX_BENCH_CONFIGNAME);
0110         EXFAIL_OUT(ret);
0111     }
0112     
0113 out:
0114 
0115     if (NULL!=f)
0116     {
0117         NDRX_FCLOSE(f);
0118     }
0119 
0120     return ret;
0121 }
0122 /* vim: set ts=4 sw=4 et smartindent: */