56 #ifdef NO_STD_CHEADERS 65 #include <xercesc/util/XMLString.hpp> 66 using XERCES_CPP_NAMESPACE::XMLString;
68 #include <xercesc/parsers/XercesDOMParser.hpp> 69 using XERCES_CPP_NAMESPACE::XercesDOMParser;
71 #include <xercesc/dom/DOMNamedNodeMap.hpp> 72 using XERCES_CPP_NAMESPACE::DOMNamedNodeMap;
106 DIAG_DevMsgIf(
DBG,
"CONFIG: " << inputFile);
109 m_parser->setValidationScheme(XercesDOMParser::Val_Auto);
110 m_parser->setErrorHandler(&errHndlr);
112 if (
m_parser->getErrorCount() > 0) {
113 ConfigParser_Throw(
"terminating because of previously reported CONFIGURATION file parse errors.");
117 DIAG_DevMsgIf(
DBG,
"CONFIG: "<<
"document: " <<
m_doc);
142 const string& metricNm,
bool metricDoDisp,
143 bool metricDoPercent,
bool metricDoSortBy,
144 const string& metricDispNm);
159 const XMLCh *nodeName = node->getNodeName();
160 const XMLCh *nodeValue = node->getNodeValue();
161 cerr <<
"name=" << XMLString::transcode(nodeName)
162 <<
" value=" << XMLString::transcode(nodeValue) << endl;
169 DOMNode *child = node->getFirstChild();
177 DIAG_DevMsgIf(
DBG,
"CONFIG: " << node);
179 if ((node ==
NULL) ||
180 (node->getNodeType() != DOMNode::DOCUMENT_TYPE_NODE)) {
184 node = node->getNextSibling();
185 DIAG_DevMsgIf(
DBG,
"CONFIG: " << node);
188 || (node->getNodeType() != DOMNode::ELEMENT_NODE)) {
193 DOMNode *child = node->getFirstChild();
194 for (; child !=
NULL; child = child->getNextSibling()) {
203 static XMLCh* METRIC = XMLString::transcode(
"METRIC");
204 static XMLCh* PATH = XMLString::transcode(
"PATH");
205 static XMLCh* REPLACE = XMLString::transcode(
"REPLACE");
206 static XMLCh* TITLE = XMLString::transcode(
"TITLE");
207 static XMLCh* STRUCTURE = XMLString::transcode(
"STRUCTURE");
208 static XMLCh* GROUP = XMLString::transcode(
"GROUP");
209 static XMLCh* NAMEATTR = XMLString::transcode(
"name");
210 static XMLCh* VIEWNAMEATTR = XMLString::transcode(
"viewname");
211 static XMLCh* INATTR = XMLString::transcode(
"in");
212 static XMLCh* OUTATTR = XMLString::transcode(
"out");
214 const XMLCh *nodeName = node->getNodeName();
217 if (node->getNodeType() == DOMNode::TEXT_NODE) {
220 else if (node->getNodeType() == DOMNode::COMMENT_NODE) {
223 else if (node->getNodeType() != DOMNode::ELEMENT_NODE) {
224 ConfigParser_Throw(
"Unexpected XML object found: '" << XMLString::transcode(nodeName) <<
"'");
228 if (XMLString::equals(nodeName, TITLE)) {
229 string title =
getAttr(node, NAMEATTR);
230 DIAG_DevMsgIf(
DBG,
"CONFIG: " <<
"TITLE: " << title);
233 else if (XMLString::equals(nodeName, PATH)) {
234 string path =
getAttr(node, NAMEATTR);
235 string viewname =
getAttr(node, VIEWNAMEATTR);
236 DIAG_DevMsgIf(
DBG,
"CONFIG: " <<
"PATH: " << path <<
", v=" << viewname);
242 ConfigParser_Throw(
"PATH '" << path <<
"': viewname attribute cannot be empty when source files are to be copied.");
247 else if (XMLString::equals(nodeName, STRUCTURE)) {
248 string fnm =
getAttr(node, NAMEATTR);
249 DIAG_DevMsgIf(
DBG,
"CONFIG: " <<
"STRUCTURE file: " << fnm);
258 else if (XMLString::equals(nodeName, GROUP)) {
259 string fnm =
getAttr(node, NAMEATTR);
260 DIAG_DevMsgIf(
DBG,
"CONFIG: " <<
"GROUP file: " << fnm);
269 else if (XMLString::equals(nodeName, REPLACE)) {
270 string inPath =
getAttr(node, INATTR);
271 string outPath =
getAttr(node, OUTATTR);
272 DIAG_DevMsgIf(
DBG,
"CONFIG: " <<
"REPLACE: " << inPath <<
" -to- " << outPath);
275 if (inPath == outPath) {
276 cerr <<
"WARNING: REPLACE: Identical 'in' and 'out' paths: '" 277 << inPath <<
"'! No action will be performed." << endl;
280 else if (inPath.empty() && !outPath.empty()) {
281 cerr <<
"WARNING: REPLACE: 'in' path is empty; 'out' path '" << outPath
282 <<
"' will be prepended to every file path!" << endl;
291 else if (XMLString::equals(nodeName, METRIC)) {
295 ConfigParser_Throw(
"Unexpected ELEMENT type encountered: '" << XMLString::transcode(nodeName) <<
"'");
303 static XMLCh* FILE = XMLString::transcode(
"FILE");
304 static XMLCh* COMPUTE = XMLString::transcode(
"COMPUTE");
305 static XMLCh* NAMEATTR = XMLString::transcode(
"name");
306 static XMLCh* DISPLAYATTR = XMLString::transcode(
"display");
307 static XMLCh* PERCENTATTR = XMLString::transcode(
"percent");
309 static XMLCh* DISPLAYNAMEATTR = XMLString::transcode(
"displayName");
310 static XMLCh* SORTBYATTR = XMLString::transcode(
"sortBy");
313 string metricNm =
getAttr(node, NAMEATTR);
314 string metricDispNm =
getAttr(node, DISPLAYNAMEATTR);
315 bool metricDoDisp = (
getAttr(node, DISPLAYATTR) ==
"true");
316 bool metricDoPercent = (
getAttr(node,PERCENTATTR) ==
"true");
317 bool metricDoSortBy = (
getAttr(node,SORTBYATTR) ==
"true");
319 if (metricNm.empty()) {
323 ConfigParser_Throw(
"METRIC: Metric name '" << metricNm <<
"' was previously defined.");
326 if (metricDispNm.empty()) {
330 DIAG_DevMsgIf(
DBG,
"CONFIG: " <<
"METRIC: name=" << metricNm
331 <<
" display=" << ((metricDoDisp) ?
"true" :
"false")
332 <<
" doPercent=" << ((metricDoPercent) ?
"true" :
"false")
333 <<
" sortBy=" << ((metricDoSortBy) ?
"true" :
"false")
334 <<
" metricDispNm=" << metricDispNm);
337 DOMNode* metricImpl = node->getFirstChild();
339 for ( ; metricImpl !=
NULL; metricImpl = metricImpl->getNextSibling()) {
341 if (metricImpl->getNodeType() == DOMNode::TEXT_NODE) {
345 else if (metricImpl->getNodeType() == DOMNode::COMMENT_NODE) {
349 const XMLCh* metricType = metricImpl->getNodeName();
351 if (XMLString::equals(metricType, FILE)) {
354 metricDoDisp, metricDoPercent, metricDoSortBy,
357 else if (XMLString::equals(metricType,COMPUTE)) {
362 DOMNode* child = metricImpl->getFirstChild();
363 for (; child !=
NULL; child = child->getNextSibling()) {
364 if (child->getNodeType() == DOMNode::TEXT_NODE) {
368 else if (child->getNodeType() == DOMNode::COMMENT_NODE) {
372 using namespace Prof;
375 metricDoDisp, metricDoSortBy,
381 ConfigParser_Throw(
"Unexpected METRIC type '" << XMLString::transcode(metricType) <<
"'.");
397 DIAG_Throw(
"Could not construct METRIC '" << nm <<
"'. XML exception encountered when processing MathML expression: " << e.
what() <<
".");
400 DIAG_Throw(
"Could not construct METRIC '" << nm <<
"'.");
404 DIAG_Msg(1,
"Computed METRIC " << nm <<
": " << nm <<
" = " 415 const string& metricNm,
bool metricDoDisp,
416 bool metricDoPercent,
bool metricDoSortBy,
419 static XMLCh* TYPEATTR = XMLString::transcode(
"type");
420 static XMLCh* NAMEATTR = XMLString::transcode(
"name");
421 static XMLCh* SELECTATTR = XMLString::transcode(
"select");
423 string metricFile =
getAttr(fileNode, NAMEATTR);
424 string metricFileType =
getAttr(fileNode, TYPEATTR);
425 string nativeNm =
getAttr(fileNode, SELECTATTR);
427 if (nativeNm.empty()) {
434 if (!metricFile.empty()) {
435 using namespace Prof;
438 metricFile, nativeNm, metricFileType,
439 metricDoDisp, metricDoSortBy,
454 DOMNamedNodeMap* attributes = node->getAttributes();
455 DOMNode* attrNode = attributes->getNamedItem(attrName);
456 DIAG_DevMsgIf(
DBG,
"CONFIG: " <<
"getAttr(): attrNode" << attrNode);
458 const XMLCh* attrNodeValue =
NULL;
460 attrNodeValue = attrNode->getNodeValue();
476 if (!inPath.empty() && inPath[inPath.length()-1] !=
'/') {
std::vector< std::string > groupFiles
static void ProcessELEMENT(DOMNode *node, Analysis::Args &args, Prof::Metric::Mgr &mMgr)
PathTupleVec searchPathTpls
static void GCC_ATTR_UNUSED printName(DOMNode *node)
bool insert(Metric::ADesc *m)
static Prof::Metric::AExpr * parse(DOMNode *mathMLExpr, const Prof::Metric::Mgr &mMgr)
virtual const std::string & what() const
std::vector< std::string > structureFiles
virtual std::string toString() const
static std::string make_string(const XMLCh *const xmlStr)
XercesDOMParser * m_parser
static void ProcessFILE(DOMNode *fileNode, Analysis::Args &args, Prof::Metric::Mgr &mMgr, const string &metricNm, bool metricDoDisp, bool metricDoPercent, bool metricDoSortBy, const string &metricDispNm)
static void ProcessDOCUMENT(DOMNode *node, Analysis::Args &args, Prof::Metric::Mgr &mMgr)
void parse(Analysis::Args &args, Prof::Metric::Mgr &metricMgr)
std::vector< std::string > replaceInPath
#define ConfigParser_Throw(streamArgs)
ConfigParser(const std::string &inputFile, XercesErrorHandler &errHndlr)
static string getAttr(DOMNode *node, const XMLCh *attrName)
#define DIAG_Msg(level,...)
static Prof::Metric::AExpr * makeMathMLExpr(const char *nm, DOMNode *mathMLExpr, Prof::Metric::Mgr &mMgr)
static void ProcessHPCPROF(DOMNode *node, Analysis::Args &args, Prof::Metric::Mgr &mMgr)
static void ProcessMETRIC(DOMNode *node, Analysis::Args &args, Prof::Metric::Mgr &mMgr)
static void canonicalizePaths(string &inPath, string &outPath)
std::vector< std::string > replaceOutPath
Metric::ADesc * metric(uint i)
std::pair< std::string, std::string > PathTuple