Updates to examples queries. Improve real-timeness of lfta aggregation
[com/gs-lite.git] / src / ftacmp / translate_fta.cc
index 19ff634..603a3cf 100644 (file)
@@ -134,6 +134,60 @@ void generate_makefile(vector<string> &input_file_names, int nfiles,
 
 //                     Dump schema summary
 void dump_summary(stream_query *str){
+       for(int q=0;q<str->query_plan.size();++q){
+               qp_node *qp = str->query_plan[q];
+               if(qp==NULL)
+                       continue;       // there can be blanks
+
+               fprintf(schema_summary_output,"-----\n");
+               fprintf(schema_summary_output,"%s\n",qp->node_name.c_str());
+
+               table_def *sch = qp->get_fields();
+
+               vector<field_entry *> flds = sch->get_fields();
+               int f;
+               for(f=0;f<flds.size();++f){
+                       if(f>0) fprintf(schema_summary_output,"|");
+                       fprintf(schema_summary_output,"%s",flds[f]->get_name().c_str());
+               }
+               fprintf(schema_summary_output,"\n");
+               for(f=0;f<flds.size();++f){
+                       if(f>0) fprintf(schema_summary_output,"|");
+                       fprintf(schema_summary_output,"%s",flds[f]->get_type().c_str());
+               }
+               fprintf(schema_summary_output,"\n");
+
+               map<std::string, std::string> defines = qp->get_definitions();
+               string comment = "";
+               if(defines.count("comment")>0){
+                       comment = defines["comment"];
+               }
+               fprintf(schema_summary_output,"%s\n",comment.c_str());
+
+               vector<tablevar_t *> input_tables = qp->get_input_tbls();
+               for(int t=0; t<input_tables.size(); ++t){
+                       if(t>0) fprintf(schema_summary_output,"|");
+                       string machine = input_tables[t]->get_machine(); 
+                       string iface = input_tables[t]->get_interface(); 
+                       string schema = input_tables[t]->get_schema_name(); 
+                       if(machine!=""){
+                               fprintf(schema_summary_output,"%s.",machine.c_str());
+                       }
+                       if(iface!=""){
+                               fprintf(schema_summary_output,"%s.",iface.c_str());
+                       }else{
+                               if(machine!="") fprintf(schema_summary_output,".");
+                       }
+                       fprintf(schema_summary_output,"%s",schema.c_str());
+               }
+
+               fprintf(schema_summary_output,"\n");
+       }
+
+
+
+/*
+       fprintf(schema_summary_output,"-----\n");
        fprintf(schema_summary_output,"%s\n",str->query_name.c_str());
 
        table_def *sch = str->get_output_tabledef();
@@ -150,6 +204,32 @@ void dump_summary(stream_query *str){
                fprintf(schema_summary_output,"%s",flds[f]->get_type().c_str());
        }
        fprintf(schema_summary_output,"\n");
+
+       string comment = "";
+       if(str->defines.count("comment")>0){
+               comment = str->defines["comment"];
+       }
+       fprintf(schema_summary_output,"%s\n",comment.c_str());
+       
+       vector<tablevar_t *> input_tables = str->get_input_tables();
+       for(int t=0; t<input_tables.size(); ++t){
+               if(t>0) fprintf(schema_summary_output,"|");
+               string machine = input_tables[t]->get_machine(); 
+               string iface = input_tables[t]->get_interface(); 
+               string schema = input_tables[t]->get_schema_name(); 
+               if(machine!=""){
+                       fprintf(schema_summary_output,"%s.",machine.c_str());
+               }
+               if(iface!=""){
+                       fprintf(schema_summary_output,"%s.",iface.c_str());
+               }else{
+                       if(machine!="") fprintf(schema_summary_output,".");
+               }
+               fprintf(schema_summary_output,"%s",schema.c_str());
+       }
+       fprintf(schema_summary_output,"\n");
+*/
+
 }
 
 //             Globals
@@ -1234,8 +1314,8 @@ fprintf(stderr,"Parsing file %s\n",qpathname.c_str());
   map<string, int> hfta_name_map;
 //  vector< vector<int> > process_sets;
 //  vector< set<int> > stream_node_sets;
-  reverse(process_order.begin(), process_order.end());  // get listing in reverse order.
-                                                                                                               // i.e. process leaves 1st.
+  reverse(process_order.begin(), process_order.end());  // get listing in reverse .
+                                                                                                               // order: process leaves 1st.
   for(i=0;i<process_order.size();++i){
        if(qnodes[process_order[i]]->is_externally_visible == true){
 //printf("Visible.\n");
@@ -2159,13 +2239,13 @@ else{
                }
 */
 
-/*
-//                             output schema summary
-               if(output_schema_summary){
-                       dump_summary(split_queries[0]);
-               }
-*/
       }
+//                             output schema summary
+         if(output_schema_summary){
+               for(int o=0;o<split_queries.size(); ++o){
+                       dump_summary(split_queries[o]);
+               }
+         }
 
 
          if(hfta_returned){            // query also has an HFTA component
@@ -2713,7 +2793,7 @@ for(ssi_el=extra_external_libs.begin();ssi_el!=extra_external_libs.end();++ssi_e
          lfta_val[lmach] += "// lookup interface properties by name\n";
          lfta_val[lmach] += "// mulitple values of given property returned in the same string separated by commas\n";
          lfta_val[lmach] += "// returns NULL if given property does not exist\n";
-         lfta_val[lmach] += "gs_sp_t get_iface_properties (const gs_sp_t iface_name, const gs_sp_t property_name) {\n";
+         lfta_val[lmach] += "gs_csp_t get_iface_properties (const gs_sp_t iface_name, const gs_sp_t property_name) {\n";
 
 //       collect a lit of interface names used by queries running on this host
          set<std::string> iface_names;
@@ -2776,7 +2856,8 @@ for(ssi_el=extra_external_libs.begin();ssi_el!=extra_external_libs.end();++ssi_e
 
 //                     Generate a full list of FTAs for clearinghouse reference
          lfta_val[lmach] += "// list of FTAs clearinghouse expects to register themselves\n";
-         lfta_val[lmach] += "const gs_sp_t fta_names[] = {";
+
+         lfta_val[lmach] += "gs_csp_t fta_names[] = {";
 
          bool first = true;
          for(auto mvsi=lfta_iface_lists.begin(); mvsi!=lfta_iface_lists.end(); ++mvsi){
@@ -2985,11 +3066,11 @@ for(ssi_el=extra_external_libs.begin();ssi_el!=extra_external_libs.end();++ssi_e
       if(!(debug_only || hfta_only) ){
                string lfta_flnm;
                if(lmach != "")
-                 lfta_flnm = lmach + "_lfta.c";
+                 lfta_flnm = lmach + "_lfta.cc";
                else
-                 lfta_flnm = hostname + "_lfta.c";
+                 lfta_flnm = hostname + "_lfta.cc";
                if((lfta_out = fopen(lfta_flnm.c_str(),"w")) == NULL){
-                       fprintf(stderr,"Can't open output file %s\n%s\n","lfta.c",strerror(errno));
+                       fprintf(stderr,"Can't open output file %s\n%s\n","lfta.cc",strerror(errno));
                        exit(1);
                }
              fprintf(lfta_out,"%s",lfta_header.c_str());
@@ -3062,7 +3143,7 @@ void generate_makefile(vector<string> &input_file_names, int nfiles,
 
        fputs(
 ("CPP= g++ -O3 -g -I "+root_path+"/include  -I "+root_path+"/include/hfta\n"
-"CC= gcc -O3 -g -I . -I "+root_path+"/include -I "+root_path+"/include/lfta"
+"CC= g++ -O3 -g -I . -I "+root_path+"/include -I "+root_path+"/include/lfta"
 ).c_str(), outfl
 );
        if(generate_stats)
@@ -3191,16 +3272,16 @@ void generate_makefile(vector<string> &input_file_names, int nfiles,
        fprintf(outfl,
 "\n"
 "\n"
-"lfta.o: %s_lfta.c\n"
-"\t$(CC) -o lfta.o -c %s_lfta.c\n"
+"lfta.o: %s_lfta.cc\n"
+"\t$(CC) -o lfta.o -c %s_lfta.cc\n"
 "\n"
-"%s_lfta.c: external_fcns.def %s ",hostname.c_str(), hostname.c_str(), hostname.c_str(),schema_file_name.c_str());
+"%s_lfta.cc: %s ",hostname.c_str(), hostname.c_str(), hostname.c_str(),schema_file_name.c_str());
        for(i=0;i<nfiles;++i)
                fprintf(outfl," %s",input_file_names[i].c_str());
        if(hostname == ""){
-               fprintf(outfl,"\n\t%s/bin/translate_fta %s %s ",root_path.c_str(), config_dir_path.c_str(),schema_file_name.c_str());
+               fprintf(outfl,"\n\t%s/bin/translate_fta -f -N -c -M -R %s %s -l %s/qlib packet_schema.txt ",root_path.c_str(), root_path.c_str(), config_dir_path.c_str(), root_path.c_str());
        }else{
-               fprintf(outfl,"\n\t%s/bin/translate_fta -h %s %s %s ", root_path.c_str(), hostname.c_str(), config_dir_path.c_str(),schema_file_name.c_str());
+               fprintf(outfl,"\n\t%s/bin/translate_fta -f -N -h %s -c -M -R %s %s -l %s/qlib packet_schema.txt ", root_path.c_str(), hostname.c_str(), root_path.c_str(), config_dir_path.c_str(), root_path.c_str());
        }
        for(i=0;i<nfiles;++i)
                fprintf(outfl," %s",input_file_names[i].c_str());
@@ -3222,15 +3303,9 @@ void generate_makefile(vector<string> &input_file_names, int nfiles,
                );
 
        fprintf(outfl,
-("\n"
-"packet_schema.txt:\n"
-"\tln -s "+root_path+"/cfg/packet_schema.txt .\n"
-"\n"
-"external_fcns.def:\n"
-"\tln -s "+root_path+"/cfg/external_fcns.def .\n"
 "\n"
 "clean:\n"
-"\trm -rf core rts *.o  %s_lfta.c  external_fcns.def packet_schema.txt").c_str(),hostname.c_str());
+"\trm -rf core rts *.o  %s_lfta.cc",hostname.c_str());
        for(i=0;i<hfta_names.size();++i)
                fprintf(outfl," %s %s.cc",hfta_names[i].c_str(),hfta_names[i].c_str());
        fprintf(outfl,"\n");