void printUDT(std::wstringstream& str,const UDT& udt,int depth) { printDepth(str,depth); //str << udt.getID() << L" " << udt.getTypeID() << L" "; str << udt.getKind() << L" " << udt.getName(); UDT::Bases bases = udt.getBases(); printBaseList(str,bases); str << std::endl; printDepth(str,depth); str << L"{\n"; CV_access_e protection = udt.getDefaultProtection(); UDT::Nested nested = udt.getNested(); for(UDT::Nested::const_iterator it = nested.begin(); it != nested.end(); ++it) { printUDT(str,*it,depth+1); } /* std::wstring friends = udt.getFriends(); if(!friends.empty()) { printDepth(str,depth); str << L"//friends " << friends << std::endl; } */ std::wstring enums = udt.getEnums(); if(!enums.empty()) { str << enums; } std::wstring typedefs = udt.getTypedefs(); if(!typedefs.empty()) { str << typedefs; } UDT::DataMembers dataMembers = udt.getDataMembers(); printMembers(str,dataMembers,depth,protection); UDT::Functions functions = udt.getFunctions(); printFunctions(str,functions,depth,protection); printDepth(str,depth); str << L"};\n"; }
int printModelInfo(DATA *data, const char *filename, const char *plotfile, const char *plotFormat, const char *method, const char *outputFormat, const char *outputFilename) { static char buf[256]; FILE *fout = fopen(filename, "w"); FILE *plotCommands; time_t t; int i; #if defined(__MINGW32__) || defined(_MSC_VER) || defined(NO_PIPE) plotCommands = fopen(plotfile, "w"); #else plotCommands = popen("gnuplot", "w"); #endif if(!plotCommands) WARNING1(LOG_UTIL, "Plots of profiling data were disabled: %s\n", strerror(errno)); ASSERT2(fout, "Failed to open %s: %s\n", filename, strerror(errno)); if(plotCommands) { fputs("set terminal svg\n", plotCommands); fputs("set nokey\n", plotCommands); fputs("set format y \"%g\"\n", plotCommands); /* The column containing the time spent to calculate each step */ printPlotCommand(plotCommands, plotFormat, "Execution time of global steps", data->modelData.modelFilePrefix, data->modelData.modelDataXml.nFunctions+data->modelData.modelDataXml.nProfileBlocks, -1, 999, ""); } /* The doctype is needed for id() lookup to work properly */ fprintf(fout, "<!DOCTYPE doc [\ <!ELEMENT simulation (modelinfo, variables, functions, equations)>\ <!ATTLIST variable id ID #REQUIRED>\ <!ELEMENT equation (refs)>\ <!ATTLIST equation id ID #REQUIRED>\ <!ELEMENT profileblocks (profileblock*)>\ <!ELEMENT profileblock (refs, ncall, time, maxTime)>\ <!ELEMENT refs (ref*)>\ <!ATTLIST ref refid IDREF #REQUIRED>\ ]>\n"); if(time(&t) < 0) { WARNING1(LOG_UTIL, "time() failed: %s", strerror(errno)); fclose(fout); return 1; } if(!strftime(buf, 250, "%Y-%m-%d %H:%M:%S", localtime(&t))) { WARNING(LOG_UTIL, "strftime() failed"); fclose(fout); return 1; } fprintf(fout, "<simulation>\n"); fprintf(fout, "<modelinfo>\n"); indent(fout, 2); fprintf(fout, "<name>");printStrXML(fout,data->modelData.modelName);fprintf(fout,"</name>\n"); indent(fout, 2); fprintf(fout, "<prefix>");printStrXML(fout,data->modelData.modelFilePrefix);fprintf(fout,"</prefix>\n"); indent(fout, 2); fprintf(fout, "<date>");printStrXML(fout,buf);fprintf(fout,"</date>\n"); indent(fout, 2); fprintf(fout, "<method>");printStrXML(fout,data->simulationInfo.solverMethod);fprintf(fout,"</method>\n"); indent(fout, 2); fprintf(fout, "<outputFormat>");printStrXML(fout,data->simulationInfo.outputFormat);fprintf(fout,"</outputFormat>\n"); indent(fout, 2); fprintf(fout, "<outputFilename>");printStrXML(fout,outputFilename);fprintf(fout,"</outputFilename>\n"); indent(fout, 2); fprintf(fout, "<outputFilesize>%ld</outputFilesize>\n", (long) fileSize(outputFilename)); indent(fout, 2); fprintf(fout, "<overheadTime>%f</overheadTime>\n", rt_accumulated(SIM_TIMER_OVERHEAD)); indent(fout, 2); fprintf(fout, "<preinitTime>%f</preinitTime>\n", rt_accumulated(SIM_TIMER_PREINIT)); indent(fout, 2); fprintf(fout, "<initTime>%f</initTime>\n", rt_accumulated(SIM_TIMER_INIT)); indent(fout, 2); fprintf(fout, "<eventTime>%f</eventTime>\n", rt_accumulated(SIM_TIMER_EVENT)); indent(fout, 2); fprintf(fout, "<outputTime>%f</outputTime>\n", rt_accumulated(SIM_TIMER_OUTPUT)); indent(fout, 2); fprintf(fout, "<linearizeTime>%f</linearizeTime>\n", rt_accumulated(SIM_TIMER_LINEARIZE)); indent(fout, 2); fprintf(fout, "<totalTime>%f</totalTime>\n", rt_accumulated(SIM_TIMER_TOTAL)); indent(fout, 2); fprintf(fout, "<totalStepsTime>%f</totalStepsTime>\n", rt_total(SIM_TIMER_STEP)); indent(fout, 2); fprintf(fout, "<numStep>%d</numStep>\n", (int) rt_ncall_total(SIM_TIMER_STEP)); indent(fout, 2); fprintf(fout, "<maxTime>%.9f</maxTime>\n", rt_max_accumulated(SIM_TIMER_STEP)); fprintf(fout, "</modelinfo>\n"); fprintf(fout, "<modelinfo_ext>\n"); indent(fout, 2); fprintf(fout, "<odeTime>%f</odeTime>\n", rt_accumulated(SIM_TIMER_FUNCTION_ODE)); indent(fout, 2); fprintf(fout, "<odeTimeTicks>%lu</odeTimeTicks>\n", rt_ncall(SIM_TIMER_FUNCTION_ODE)); fprintf(fout, "</modelinfo_ext>\n"); fprintf(fout, "<profilingdataheader>\n"); printProfilingDataHeader(fout, data); fprintf(fout, "</profilingdataheader>\n"); fprintf(fout, "<variables>\n"); for(i=0;i<data->modelData.nVariablesReal;++i){ printVar(fout, 2, &(data->modelData.realVarsData[i].info)); } for(i=0;i<data->modelData.nParametersReal;++i){ printVar(fout, 2, &data->modelData.realParameterData[i].info); } for(i=0;i<data->modelData.nVariablesInteger;++i){ printVar(fout, 2, &data->modelData.integerVarsData[i].info); } for(i=0;i<data->modelData.nParametersInteger;++i){ printVar(fout, 2, &data->modelData.integerParameterData[i].info); } for(i=0;i<data->modelData.nVariablesBoolean;++i){ printVar(fout, 2, &data->modelData.booleanVarsData[i].info); } for(i=0;i<data->modelData.nParametersBoolean;++i){ printVar(fout, 2, &data->modelData.booleanParameterData[i].info); } for(i=0;i<data->modelData.nVariablesString;++i){ printVar(fout, 2, &data->modelData.stringVarsData[i].info); } for(i=0;i<data->modelData.nParametersString;++i){ printVar(fout, 2, &data->modelData.stringParameterData[i].info); } fprintf(fout, "</variables>\n"); fprintf(fout, "<functions>\n"); printFunctions(fout, plotCommands, plotFormat, data->modelData.modelFilePrefix, data); fprintf(fout, "</functions>\n"); fprintf(fout, "<equations>\n"); printEquations(fout, data->modelData.modelDataXml.nEquations, &data->modelData.modelDataXml); fprintf(fout, "</equations>\n"); fprintf(fout, "<profileblocks>\n"); printProfileBlocks(fout, plotCommands, plotFormat, data); fprintf(fout, "</profileblocks>\n"); fprintf(fout, "</simulation>\n"); fclose(fout); if(plotCommands) { const char *omhome = data->simulationInfo.OPENMODELICAHOME; char *buf = NULL; int genHtmlRes; buf = (char*)malloc(230 + 2*strlen(plotfile) + 2*(omhome ? strlen(omhome) : 0)); assert(buf); #if defined(__MINGW32__) || defined(_MSC_VER) || defined(NO_PIPE) if(omhome) { #if defined(__MINGW32__) || defined(_MSC_VER) sprintf(buf, "%s/lib/omc/libexec/gnuplot/binary/gnuplot.exe %s", omhome, plotfile); #else sprintf(buf, "gnuplot %s", plotfile); #endif fclose(plotCommands); if(0 != system(buf)) { WARNING1(LOG_UTIL, "Plot command failed: %s\n", buf); } } #else if(0 != pclose(plotCommands)) { WARNING(LOG_UTIL, "Warning: Plot command failed\n"); } #endif if(omhome) { #if defined(__MINGW32__) || defined(_MSC_VER) char *xsltproc; sprintf(buf, "%s/lib/omc/libexec/xsltproc/xsltproc.exe", omhome); xsltproc = strdup(buf); #else const char *xsltproc = "xsltproc"; #endif sprintf(buf, "%s -o %s_prof.html %s/share/omc/scripts/default_profiling.xsl %s_prof.xml", xsltproc, data->modelData.modelFilePrefix, omhome, data->modelData.modelFilePrefix); #if defined(__MINGW32__) || defined(_MSC_VER) free(xsltproc); #endif genHtmlRes = system(buf); } else { strcpy(buf, "OPENMODELICAHOME missing"); genHtmlRes = 1; } if(genHtmlRes) { WARNING1(LOG_STDOUT, "Failed to generate html version of profiling results: %s\n", buf); } INFO2(LOG_STDOUT, "Time measurements are stored in %s_prof.html (human-readable) and %s_prof.xml (for XSL transforms or more details)", data->modelData.modelFilePrefix, data->modelData.modelFilePrefix); free(buf); } return 0; }
static void help() { fprintf(stderr, "Usage: -d <device name (hex)> -f <function name> -b <bus number> [-D(ebug)]"); fprintf(stderr, "[-p <parameter hex byte>]* [-v <variable result size>]\n"); printFunctions(); exit(1); }
int main(int argc, char **argv) { byte param_buf[1024] = {0}; int params = 0; int device_addr = -1; char *funcName = NULL; char *library_param = NULL; int c; BOOL var_res_given = FALSE; int var_res_size = 0; while ( (c = getopt(argc, argv, "d:f:b:p:v:D")) != -1) { switch (c) { case 'D': print_buffer_contents = TRUE; debug_mode = TRUE; break; case 'd': if (device_addr != -1) help(); device_addr = parse_int(optarg, 16, "hex device address"); break; case 'f': if (funcName != NULL) help(); funcName = optarg; break; case 'b': if (library_param != NULL) help(); library_param = optarg; break; case 'p': if (params >= sizeof(param_buf)) { fprintf(stderr, "Too many parameter bytes!\n"); exit(1); } int p = parse_int(optarg, 16, "parameter hex byte"); param_buf[params] = p; params++; break; case 'v': if (var_res_given) help(); var_res_size = parse_int(optarg, 10, "variable result size"); if (var_res_size <= 0) { fprintf(stderr, "-v parameter must be positive"); exit(1); } var_res_given = TRUE; break; default: help(); } } if (!funcName || device_addr == -1) help(); if (library_param == NULL) help(); TWIDevice device = { device_addr }; // == Lookup registered function entry ClientFunctionRegistryEntry entry = lookupClientFunction(funcName); if (entry == NULL) { fprintf(stderr, "Function not registered: %s\n", funcName); printFunctions(); exit(1); } if (debug_mode) { fprintf(stderr, "Calling "); printFunction(entry); fprintf(stderr, " on device 0x%02x, i2c bus parameter %s\n", device_addr, library_param); } // == Handle required result size if (!entry->variable_arguments && entry->argument_bytes != params) { fprintf(stderr, "%s needs %i argument bytes, but %i were given.\n", entry->name, entry->argument_bytes, params); exit(1); } int result_size; if (entry->variable_results) { if (!var_res_given) { fprintf(stderr, "Function has variable results, use -v.\n"); exit(1); } result_size = var_res_size; } else { if (var_res_given) fprintf(stderr, "Warning: function does not have variable results. Ignoring -v parameter.\n"); result_size = entry->result_bytes; } // == Initialize and execute the call init_libraries(library_param); return call(device, entry, param_buf, params, result_size); }