@@ -2648,12 +2648,24 @@ read_line_from_file(FILE *fd)
26482648return NULL ;
26492649}
26502650
2651+ /*
2652+ * Initialize a ParsedScript
2653+ */
2654+ static void
2655+ initParsedScript (ParsedScript * ps ,const char * desc ,int alloc_num ,int weight )
2656+ {
2657+ ps -> commands = (Command * * )pg_malloc (sizeof (Command * )* alloc_num );
2658+ ps -> desc = desc ;
2659+ ps -> weight = weight ;
2660+ initStats (& ps -> stats ,0.0 );
2661+ }
2662+
26512663/*
26522664 * Given a file name, read it and return its ParsedScript representation. "-"
26532665 * means to read stdin.
26542666 */
26552667static ParsedScript
2656- process_file (char * filename )
2668+ process_file (char * filename , int weight )
26572669{
26582670#define COMMANDS_ALLOC_NUM 128
26592671ParsedScript ps ;
@@ -2673,8 +2685,7 @@ process_file(char *filename)
26732685}
26742686
26752687alloc_num = COMMANDS_ALLOC_NUM ;
2676- ps .commands = (Command * * )pg_malloc (sizeof (Command * )* alloc_num );
2677- ps .desc = filename ;
2688+ initParsedScript (& ps ,filename ,alloc_num ,weight );
26782689
26792690lineno = 0 ;
26802691index = 0 ;
@@ -2710,7 +2721,7 @@ process_file(char *filename)
27102721
27112722/* Parse the given builtin script and return the parsed representation */
27122723static ParsedScript
2713- process_builtin (BuiltinScript * bi )
2724+ process_builtin (BuiltinScript * bi , int weight )
27142725{
27152726int lineno ,
27162727index ;
@@ -2720,8 +2731,7 @@ process_builtin(BuiltinScript *bi)
27202731ParsedScript ps ;
27212732
27222733alloc_num = COMMANDS_ALLOC_NUM ;
2723- ps .desc = bi -> desc ;
2724- ps .commands = (Command * * )pg_malloc (sizeof (Command * )* alloc_num );
2734+ initParsedScript (& ps ,bi -> desc ,alloc_num ,weight );
27252735
27262736lineno = 0 ;
27272737index = 0 ;
@@ -2860,7 +2870,7 @@ parseScriptWeight(const char *option, char **script)
28602870
28612871/* append a script to the list of scripts to process */
28622872static void
2863- addScript (ParsedScript script , int weight )
2873+ addScript (ParsedScript script )
28642874{
28652875if (script .commands == NULL || script .commands [0 ]== NULL )
28662876{
@@ -2875,8 +2885,6 @@ addScript(ParsedScript script, int weight)
28752885}
28762886
28772887sql_script [num_scripts ]= script ;
2878- sql_script [num_scripts ].weight = weight ;
2879- initStats (& sql_script [num_scripts ].stats ,0.0 );
28802888num_scripts ++ ;
28812889}
28822890
@@ -3251,24 +3259,24 @@ main(int argc, char **argv)
32513259}
32523260
32533261weight = parseScriptWeight (optarg ,& script );
3254- addScript (process_builtin (findBuiltin (script )) ,weight );
3262+ addScript (process_builtin (findBuiltin (script ),weight ) );
32553263benchmarking_option_set = true;
32563264internal_script_used = true;
32573265break ;
32583266
32593267case 'S' :
3260- addScript (process_builtin (findBuiltin ("select-only" )) ,1 );
3268+ addScript (process_builtin (findBuiltin ("select-only" ),1 ) );
32613269benchmarking_option_set = true;
32623270internal_script_used = true;
32633271break ;
32643272case 'N' :
3265- addScript (process_builtin (findBuiltin ("simple-update" )) ,1 );
3273+ addScript (process_builtin (findBuiltin ("simple-update" ),1 ) );
32663274benchmarking_option_set = true;
32673275internal_script_used = true;
32683276break ;
32693277case 'f' :
32703278weight = parseScriptWeight (optarg ,& script );
3271- addScript (process_file (script ) ,weight );
3279+ addScript (process_file (script ,weight ) );
32723280benchmarking_option_set = true;
32733281break ;
32743282case 'D' :
@@ -3406,7 +3414,7 @@ main(int argc, char **argv)
34063414/* set default script if none */
34073415if (num_scripts == 0 && !is_init_mode )
34083416{
3409- addScript (process_builtin (findBuiltin ("tpcb-like" )) ,1 );
3417+ addScript (process_builtin (findBuiltin ("tpcb-like" ),1 ) );
34103418benchmarking_option_set = true;
34113419internal_script_used = true;
34123420}