CADIReturn_t CacheStatisticsPlugin::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."); CoreTracer *current_core = 0; for(SystemTraceInterface::TraceComponentIndex i=0; i < num_trace_components; ++i) { const char *component_name = sti->GetComponentTracePath(i); // Get Component Trace Interface of component: ca_interface = sti->GetComponentTrace(i); ComponentTraceInterface *cti = ca_interface->ObtainPointer<ComponentTraceInterface>(); if (!cti) { Error("Unable to get component trace for component '%s'.\n"); continue; } if (cti->GetTraceSource("CORE_INFO") != 0) { current_core = new CoreTracer(component_name, cti, selfcheck); cores.insert(make_pair(component_name, current_core)); printf("Registering core statistics for component '%s'.\n", component_name); } else if (cti->GetTraceSource("CACHE_INFO") != 0) { assert(current_core); CacheTracer *new_tracer = new CacheTracer(component_name, cti, selfcheck, current_core); current_core->RegisterCache(new_tracer); printf("Registering cache statistics for component '%s'.\n", component_name); } } for(CoresT::const_iterator it = cores.begin(); it != cores.end(); ++it) { it->second->Connect(); it->second->PrintInfo(); } return CADI_STATUS_OK; }
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 GenericTrace::RegisterPERIODICCallback() { for(SystemTraceInterface::TraceComponentIndex cidx = 0; cidx < sti->GetNumOfTraceComponents(); ++cidx) { CAInterface *ca_interface = sti->GetComponentTrace(cidx); ComponentTraceInterface *cit = ca_interface->ObtainPointer<ComponentTraceInterface>(); if (!cit) continue; const TraceSource *source = cit->GetTraceSource("PERIODIC"); if (!source) continue; if (verbose) printf("Attaching PERIODIC callback to component '%s'\n", sti->GetComponentTracePath(cidx)); FieldMask mask = 0; const EventFieldType *eft = 0; if ((eft = source->GetField("INST_COUNT")) == 0) { fprintf(stderr, "No field INST_COUNT found in PERIODIC trace source."); return; } mask |= 1 << eft->GetIndex(); EventClass *event_class = source->CreateEventClass(mask); if (!event_class) { fprintf(stderr, "Unable to register event class for PERIODIC trace source."); return; } Status status = event_class->RegisterCallback(&PeriodicCallbackThunk, this); if (status != MTI_OK) { fprintf(stderr, "Registration of PERIODIC trace callback failed."); return; } periodic_inst_count_idx = event_class->GetValueIndex("INST_COUNT"); periodic_pc_idx = event_class->GetValueIndex("PC"); return; } fprintf(stderr, "Did not find PERIODIC trace source in any component but start/end-icount was specified."); }
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."); } }
list<SourceInfo> GenericTrace::ParseSourceList(string sources) { list<SourceInfo> result; for(;;) { string::size_type delim_pos = sources.find_first_of(";,"); string source = sources.substr(0, delim_pos); string::size_type equal_pos = source.find('='); FieldMask field_mask = (FieldMask)-1; // all bits set if (equal_pos != string::npos) { string fields = source.substr(equal_pos + 1); source = source.substr(0, equal_pos); field_mask = strtoul(fields.c_str(), 0, 0); } string::size_type dot_pos = source.rfind('.'); string component_path; if (dot_pos != string::npos) { component_path = source.substr(0, dot_pos); source = source.substr(dot_pos + 1); } // now concretise component/source pairs with existing trace sources: // First loop over all components providing trace: int numMatchingComponents = 0; int numMatchingTraceSources = 0; for(SystemTraceInterface::TraceComponentIndex cidx = 0; cidx < sti->GetNumOfTraceComponents(); ++cidx) { if (component_path.empty() || // empty component_path matches all components (component_path == sti->GetComponentTracePath(cidx)) || MatchesWildcard(component_path, sti->GetComponentTracePath(cidx))) { numMatchingComponents++; CAInterface *ca_interface = sti->GetComponentTrace(cidx); ComponentTraceInterface *cit = ca_interface->ObtainPointer<ComponentTraceInterface>(); if (!cit) continue; // We have found a component which matches the // component_path // first check for the trace source by name to be able to find hidden sources // (hidden trace sources are not advertised in the list of trace sources, but they // are available when queried for by name) TraceSource *trace_source = cit->GetTraceSource(source.c_str()); if (trace_source) { // found an matching source, add it to the result list now: numMatchingTraceSources++; SourceInfo source_info(this); source_info.component_path = sti->GetComponentTracePath(cidx); source_info.source_name = source; FieldMask mask = (1U << trace_source->GetNumFields()) - 1; source_info.field_mask = mask & field_mask; source_info.trace_source = trace_source; // only add if not already in list: result.push_back(source_info); } // now iterate over all trace sources // to find matching ones: // (this will never find hidden sources even if the name matches) for(SourceIndex sidx = 0; sidx < cit->GetNumOfTraceSources(); ++sidx) { trace_source = cit->GetTraceSource(sidx); const char *curr_source_name = trace_source->GetName(); if ((source == curr_source_name) || MatchesWildcard(source, curr_source_name)) { // found an matching source, add it to the result list now: numMatchingTraceSources++; SourceInfo source_info(this); source_info.component_path = sti->GetComponentTracePath(cidx); source_info.source_name = curr_source_name; FieldMask mask = (1U << trace_source->GetNumFields()) - 1; source_info.field_mask = mask & field_mask; source_info.trace_source = trace_source; // only add if not already in list: result.push_back(source_info); } } } } // check whether we found any matching trace source at all // if not this is most likely a user error: notify user if (numMatchingTraceSources == 0) { // first check whether we did not find any matching component at all: then the problem is in the component name/path if (numMatchingComponents == 0) { fprintf(stderr, "GenericTrace: Warning: ignoring %s.%s: no matching component found, possible component paths (or no component path at all for all components):\n", component_path.c_str(), source.c_str()); for(SystemTraceInterface::TraceComponentIndex cidx = 0; cidx < sti->GetNumOfTraceComponents(); ++cidx) fprintf(stderr, "GenericTrace: %s\n", sti->GetComponentTracePath(cidx)); } else { // some components matched: print available trace sources for all matching components fprintf(stderr, "GenericTrace: Warning: ignoring %s.%s: no matching trace source found, but %d matching component paths found, list of available trace sources:\n", component_path.c_str(), source.c_str(), numMatchingComponents); for(SystemTraceInterface::TraceComponentIndex cidx = 0; cidx < sti->GetNumOfTraceComponents(); ++cidx) { if (component_path.empty() || // empty component_path matches all components (component_path == sti->GetComponentTracePath(cidx)) || MatchesWildcard(component_path, sti->GetComponentTracePath(cidx))) { fprintf(stderr, "GenericTrace: list of possible trace sources for component %s:\n", sti->GetComponentTracePath(cidx)); CAInterface *ca_interface = sti->GetComponentTrace(cidx); ComponentTraceInterface *cit = ca_interface->ObtainPointer<ComponentTraceInterface>(); if (!cit) continue; // We have found a component which matches the // component_path, now iterate over all trace sources and print them for(SourceIndex sidx = 0; sidx < cit->GetNumOfTraceSources(); ++sidx) fprintf(stderr, "GenericTrace: %s\n", cit->GetTraceSource(sidx)->GetName()); } } } } if (delim_pos == string::npos) break; sources = sources.substr(delim_pos + 1); } return result; }
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; }