EventClass * Tracer::CreateEventClass(const char *source_name, const char *field_string) { TraceSource *source = cti->GetTraceSource(source_name); if (!source) { char buf[128]; sprintf(buf, "In component %s: No trace source %s found.", component_name.c_str(), source_name); throw(std::runtime_error(buf)); } FieldMask mask = 0; string fields(field_string); for(;!fields.empty();) { string::size_type delim_pos = fields.find(','); string field_name = fields.substr(0, delim_pos); const EventFieldType *event_field = source->GetField(field_name.c_str()); if (!event_field) { char buf[128]; sprintf(buf, "Error: no field %s in trace source %s.", field_name.c_str(), source_name); throw runtime_error(buf); } mask |= 1 << event_field->GetIndex(); if (delim_pos == string::npos) break; fields = fields.substr(delim_pos + 1); } EventClass *event_class = source->CreateEventClass(mask); return event_class; }
void Tracer::RegisterCounter(const char *name, uint64_t *counter, bool unregister) { TraceSource *source = cti->GetTraceSource(name); if (!source) { Error("No trace source \"" + string(name) + "\" found."); return; } if (unregister) { Status status = source->UnregisterCounter(counter); if (status != MTI_OK) Error("TraceSource::UnregisterCounter() returned error."); } else { Status status = source->RegisterCounter(counter); if (status != MTI_OK) Error("TraceSource::RegisterCounter() returned error."); } }
CADIReturn_t SimpleTraceExample::RegisterSimulation(CAInterface *ca_interface) { if (!ca_interface) return CADI_STATUS_IllegalArgument; // Get the System Trace Interface: SystemTraceInterface *sti = ca_interface->ObtainPointer<SystemTraceInterface>(); if (!sti) return CADI_STATUS_IllegalArgument; // Check if there is at least one component with trace: SystemTraceInterface::TraceComponentIndex num_trace_components = sti->GetNumOfTraceComponents(); if (num_trace_components == 0) return Error("No components provide trace."); // For each component get the Trace Component Interface and see if it has an INST source for(SystemTraceInterface::TraceComponentIndex tci=0; tci < num_trace_components; ++tci) { CAInterface *caif = sti->GetComponentTrace(tci); ComponentTraceInterface *cti = caif->ObtainPointer<ComponentTraceInterface>(); if(cti) { printf("Attached %s to component: %s\n", instance_name.c_str(), sti->GetComponentTracePath(tci)); // Get the trace source named "INST": TraceSource *source = cti->GetTraceSource("INST"); if (source) { // Now find the field "PC", and create a field mask: const EventFieldType *field = source->GetField("PC"); if (!field) return Error("No field named \"PC\" found in \"INST\" trace source."); FieldMask mask = 1 << field->GetIndex(); // Register an event class: EventClass *event_class = source->CreateEventClass(mask); if (!event_class) return Error("Problem when creating EventClass."); inst_pc_index = event_class->GetValueIndex("PC"); // Now register the callback: Status status = event_class->RegisterCallback(TracePC_Thunk, this); if (status != MTI_OK) return Error("EventClass::RegisterCallback() returned error."); inst_pc_index = event_class->GetValueIndex("PC"); if (inst_pc_index == -1) return Error("EventClass::GetValueIndex(\"PC\") returned error."); } else { printf("Ignoring component %s as it does not contain an INST source\n", sti->GetComponentTracePath(tci)); } } } return CADI_STATUS_OK; }