92 using namespace std::chrono;
96 Atom::TraceContext::TraceContext() {
104 void Atom::trace(TraceContext& context, std::ostream& out)
const {
106 context.write_indents(out);
107 if (context.timestamp_data_) {
110 --context.timestamp_data_;
113 if (context.timestamp_data_ == 1)
115 context.int64_high_ = atom_;
118 auto timestamp = core::Timestamp(microseconds(context.int64_high_ << 32 | atom_));
119 out <<
" " << Utils::RelativeTime(timestamp);
123 if (context.duration_data_) {
125 --context.duration_data_;
128 if (context.duration_data_ == 1)
130 context.int64_high_ = atom_;
133 auto duration = microseconds(context.int64_high_ << 32 | atom_);
134 out <<
" " << Utils::ToString_us(duration);
139 switch (getDescriptor()) {
140 case NIL: out <<
"nil";
return;
141 case BOOLEAN_: out <<
"bl: " << std::boolalpha << asBoolean();
return;
142 case WILDCARD: out <<
":";
return;
143 case T_WILDCARD: out <<
"::";
return;
144 case I_PTR: out <<
"iptr: " << std::dec << asIndex();
return;
145 case VL_PTR: out <<
"vlptr: " << std::dec << asIndex();
return;
146 case R_PTR: out <<
"rptr: " << std::dec << asIndex();
return;
147 case IPGM_PTR: out <<
"ipgm_ptr: " << std::dec << asIndex();
return;
148 case IN_OBJ_PTR: out <<
"in_obj_ptr: " << std::dec << (uint32)asInputIndex() <<
" " << asIndex();
return;
149 case D_IN_OBJ_PTR: out <<
"d_in_obj_ptr: " << std::dec << (uint32)asRelativeIndex() <<
" " << asIndex();
return;
150 case OUT_OBJ_PTR: out <<
"out_obj_ptr: " << std::dec << asIndex();
return;
151 case VALUE_PTR: out <<
"value_ptr: " << std::dec << asIndex();
return;
152 case PROD_PTR: out <<
"prod_ptr: " << std::dec << asIndex();
return;
153 case ASSIGN_PTR: out <<
"assign_ptr: " << std::dec << (uint16)asAssignmentIndex() <<
" " << asIndex();
return;
154 case CODE_VL_PTR: out <<
"code_vlptr: " << std::dec << asIndex();
return;
155 case THIS: out <<
"this";
return;
156 case VIEW: out <<
"view";
return;
157 case MKS: out <<
"mks";
return;
158 case VWS: out <<
"vws";
return;
159 case NODE: out <<
"nid: " << std::dec << (uint32)getNodeID();
return;
160 case DEVICE: out <<
"did: " << std::dec << (uint32)getNodeID() <<
" " << (uint32)getClassID() <<
" " << (uint32)getDeviceID();
return;
161 case DEVICE_FUNCTION: out <<
"fid: " << std::dec << asOpcode() <<
" (" << GetOpcodeName(asOpcode()).c_str() <<
")";
return;
162 case C_PTR: out <<
"cptr: " << std::dec << (uint16)getAtomCount(); context.members_to_go_ = getAtomCount();
return;
163 case SET: out <<
"set: " << std::dec << (uint16)getAtomCount(); context.members_to_go_ = getAtomCount();
return;
164 case OBJECT: out <<
"obj: " << std::dec << asOpcode() <<
" (" << GetOpcodeName(asOpcode()).c_str() <<
") " << (uint16)getAtomCount(); context.members_to_go_ = getAtomCount();
return;
165 case S_SET: out <<
"s_set: " << std::dec << asOpcode() <<
" (" << GetOpcodeName(asOpcode()).c_str() <<
") " << (uint16)getAtomCount(); context.members_to_go_ = getAtomCount();
return;
166 case MARKER: out <<
"mk: " << std::dec << asOpcode() <<
" (" << GetOpcodeName(asOpcode()).c_str() <<
") " << (uint16)getAtomCount(); context.members_to_go_ = getAtomCount();
return;
167 case OPERATOR: out <<
"op: " << std::dec << asOpcode() <<
" (" << GetOpcodeName(asOpcode()).c_str() <<
") " << (uint16)getAtomCount(); context.members_to_go_ = getAtomCount();
return;
168 case STRING: out <<
"st: " << std::dec << (uint16)getAtomCount() <<
" " << (atom_ & 0x000000FF); context.members_to_go_ = context.string_data_ = getAtomCount(); context.char_count_ = (atom_ & 0x000000FF);
return;
169 case TIMESTAMP: out <<
"ts"; context.members_to_go_ = context.timestamp_data_ = 2;
return;
170 case DURATION: out <<
"us"; context.members_to_go_ = context.duration_data_ = 2;
return;
171 case GROUP: out <<
"grp: " << std::dec << asOpcode() <<
" (" << GetOpcodeName(asOpcode()).c_str() <<
") " << (uint16)getAtomCount(); context.members_to_go_ = getAtomCount();
return;
172 case INSTANTIATED_PROGRAM:
173 case INSTANTIATED_ANTI_PROGRAM:
174 case INSTANTIATED_INPUT_LESS_PROGRAM:
175 out <<
"ipgm: " << std::dec << asOpcode() <<
" (" << GetOpcodeName(asOpcode()).c_str() <<
") " << (uint16)getAtomCount(); context.members_to_go_ = getAtomCount();
return;
176 case COMPOSITE_STATE: out <<
"cst: " << std::dec << asOpcode() <<
" (" << GetOpcodeName(asOpcode()).c_str() <<
") " << (uint16)getAtomCount(); context.members_to_go_ = getAtomCount();
return;
177 case MODEL: out <<
"mdl: " << std::dec << asOpcode() <<
" (" << GetOpcodeName(asOpcode()).c_str() <<
") " << (uint16)getAtomCount(); context.members_to_go_ = getAtomCount();
return;
178 case NULL_PROGRAM: out <<
"null pgm " << takesPastInputs() ?
"all inputs" :
"new inputs";
return;
180 if (context.string_data_) {
182 --context.string_data_;
184 char *content = (
char *)&atom_;
185 for (uint8 i = 0; i < 4; ++i) {
187 if (context.char_count_-- > 0)
193 }
else if (isFloat()) {
195 out <<
"nb: " << std::scientific << asFloat() << std::defaultfloat;
202 void Atom::TraceContext::write_indents(std::ostream& out) {
204 if (members_to_go_) {
212 unordered_map<uint16, set<string>> OpcodeNames;
214 string GetOpcodeName(uint16 opcode) {
215 unordered_map<uint16, set<string>>::iterator names =
216 OpcodeNames.find(opcode);
217 if (names == OpcodeNames.end())
221 for (set<string>::iterator it = names->second.begin();
222 it != names->second.end(); ++it) {
223 if (result.size() != 0)
231 bool SetOpcodeNames(
const std::unordered_map<uint16, std::set<std::string>>& opcode_names) {
232 if (OpcodeNames.size() > 0)
236 OpcodeNames = opcode_names;