Sierra Toolkit  Version of the Day
WriterParser.cpp
1 
2 #include <sstream>
3 #include <iomanip>
4 #include <map>
5 
6 #include <stk_util/diag/WriterParser.hpp>
7 #include <stk_util/diag/Trace.hpp>
8 #include <stk_util/diag/Writer_fwd.hpp>
9 #include <iostream>
10 
11 namespace stk_classic {
12 namespace diag {
13 
16 {
17  mask("coverage", 0, "Collect and display traceable function usage coverage");
18  mask("members", LOG_MEMBERS, "Display data structure members messages");
19  mask("trace", LOG_TRACE, "Display execution trace");
20  mask("trace-stats", LOG_TRACE_STATS, "Display execution time and memory usage during trace");
21  mask("trace-down", LOG_TRACE_SUB_CALLS, "Display subsequent calls after tracing is enabled");
22 }
23 
24 
27  const char * mask_string) const
28 {
29  m_optionMask = LOG_MEMBERS;
30  return OptionMaskParser::parse(mask_string);
31 }
32 
33 
34 void
36  const std::string & name,
37  const std::string & arg) const
38 {
39  if (name == "trace") {
40  m_optionMask |= LOG_TRACE;
41  if (!arg.empty()) {
42  std::string::const_iterator it0 = arg.begin();
43  std::string::const_iterator it1;
44  std::string::const_iterator it2;
45  do {
46  // Trim preceeding spaces
47  while (it0 != arg.end() && *it0 == ' ')
48  it0++;
49 
50  if (it0 == arg.end())
51  break;
52 
53  int paren_count = 0;
54  for (it1 = it0; it1 != arg.end(); ++it1) {
55  if (*it1 == '(')
56  ++paren_count;
57  else if (*it1 == ')')
58  --paren_count;
59  else if (*it1 == ',' && paren_count == 0)
60  break;
61  }
62 
63 
64  // Trim trailing spaces
65  it2 = it1;
66  while (it2 != it0 && *(it2 - 1) == ' ')
67  --it2;
68 
69  std::string function(it0, it2);
70 
71  Trace::addTraceFunction(function);
72 
73  it0 = it1 + 1;
74  } while (it1 != arg.end());
75  }
76  else
77  m_optionMask |= LOG_TRACE_SUB_CALLS;
78  }
79 
80  else if (name == "coverage") {
82  }
83 
84  else {
85  OptionMaskNameMap::const_iterator mask_entry = m_optionMaskNameMap.find(name.c_str());
86 
87  if (mask_entry != m_optionMaskNameMap.end())
88  m_optionMask |= (*mask_entry).second.m_mask;
89  else {
90  Mask mask_hex = 0;
91  std::istringstream mask_hex_stream(name.c_str());
92  if (mask_hex_stream >> std::resetiosflags(std::ios::basefield) >> mask_hex)
93  m_optionMask |= mask_hex;
94  else
95  m_status = false;
96  }
97  }
98 }
99 
100 } // namespace diag
101 } // namespace stk_classic
_resetiosflags resetiosflags(std::ios_base::fmtflags flags)
Function resetiosflags clears the ios flags as a manipulator.
static void addTraceFunction(const std::string &function_prefix)
Member function addTraceFunction adds a function prefix to the list of function prefixes search to en...
OptionMaskNameMap m_optionMaskNameMap
Mask name vector.
Definition: Option.hpp:345
virtual void parseArg(const std::string &name, const std::string &arg) const
Member function parseArg parses the argument and its argument values.
void mask(const std::string &name, const Mask l_mask, const std::string &description)
Definition: Option.hpp:332
OptionMask m_optionMask
Most recently parsed mask.
Definition: Option.hpp:346
WriterParser()
Creates a new WriterParser instance containing the lowerest level PrintMask names.
virtual Mask parse(const char *mask) const
Definition: Option.cpp:15
bool m_status
Result of most recent parse.
Definition: Option.hpp:347
Sierra Toolkit.
static void enableCoverage(bool coverage_enabled=true)
Member function enableCoverage enables the collection of function call coverage data. This is a very expensive operation, but allows function execution coverage data to be collected for testing.
OptionMask Mask
Mask for this option.
Definition: Option.hpp:261
Mask parse(const char *mask_string) const
Member function parse returns the mask which results from parsing the mask_string.