| /* --COPYRIGHT--,EPL |
| * Copyright (c) 2008 Texas Instruments and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Texas Instruments - initial implementation |
| * |
| * --/COPYRIGHT--*/ |
| /* |
| * ======== HostEvent.java ======== |
| */ |
| package xdc.rta; |
| |
| import java.util.Comparator; |
| import java.util.regex.*; |
| |
| /* |
| * ======== HostEvent ======== |
| */ |
| public class HostEvent |
| { |
| public static final int NUMARGS = 8; |
| |
| public int args[]; /* message arguments */ |
| public int eventId; /* log event id */ |
| public int moduleId; /* call site module */ |
| public long sequenceNum; /* 32-bit sequence number */ |
| public long timestamp; /* 64-bit timestamp */ |
| |
| public long formatAddr; |
| |
| private IEventMetaData meta; |
| private IOFReader ofReader = null; |
| |
| /* |
| * ======== HostEvent ======== |
| */ |
| public HostEvent(IEventMetaData meta) |
| { |
| this.meta = meta; |
| this.ofReader = meta.getOFReader(); |
| |
| this.eventId = 0; |
| this.moduleId = 0; |
| this.sequenceNum = 0; |
| this.timestamp = 0; |
| |
| this.args = new int[NUMARGS]; |
| } |
| |
| /* |
| * ======== getFormatStr ======== |
| */ |
| public String getFormatStr() |
| { |
| /* If this is a Log_print... */ |
| if (this.eventId == 0) { |
| if (ofReader != null) { |
| return(ofReader.findString(this.formatAddr)); |
| } |
| return (null); |
| } |
| |
| /* Otherwise */ |
| return (meta.lookupEventMessage(this.eventId)); |
| } |
| |
| /* |
| * ======== getEventMsg ======== |
| */ |
| public String getEventMsg() |
| { |
| String fmt = getFormatStr(); |
| |
| /* For non-Log_prints */ |
| if (this.eventId != 0) { |
| if (fmt == null) { |
| String result = "Log_write(eventId: " + this.eventId; |
| for (int i = 0; i < this.args.length; i++) { |
| result += ", 0x" + Integer.toHexString(this.args[i]); |
| } |
| return (result + ")"); |
| } |
| return (Formatter.doPrint(fmt, this.args, meta.getTargetArgSize())); |
| } |
| |
| /* For Log_prints... */ |
| /* If we have an of reader and can find the format ... */ |
| if (fmt != null) { |
| /* |
| * Arg0 is the format string address, so create a new args |
| * array that shifts all of the args to the left by one. |
| */ |
| int[] formatArgs = new int[this.args.length - 1]; |
| for (int i = 1; i < this.args.length; i++) { |
| formatArgs[i - 1] = this.args[i]; |
| } |
| |
| return (Formatter.doPrint(fmt, formatArgs)); |
| } |
| |
| /* otherwise, display the raw data as a last resort */ |
| String result = "Log_print(0x" |
| + Long.toHexString(this.formatAddr); |
| for (int i = 1; i < this.args.length; i++) { |
| result += ", 0x" + Integer.toHexString(this.args[i]); |
| } |
| return (result + ")"); |
| } |
| |
| /* |
| * ======== getEventName ======== |
| */ |
| public String getEventName() |
| { |
| String name; |
| |
| if (this.eventId == 0) { |
| name = "xdc.runtime.Log_print"; |
| } |
| else { |
| name = meta.lookupEventName(this.eventId); |
| } |
| |
| return (name); |
| } |
| |
| /* |
| * ======== getModuleName ======== |
| */ |
| public String getModuleName() |
| { |
| return (meta.lookupModuleName(this.moduleId)); |
| } |
| |
| /* |
| * ======== toString ======== |
| */ |
| public String toString() |
| { |
| String result = ""; |
| String tmp; |
| |
| if ((tmp = getModuleName()) != null) { |
| result += tmp + ": "; |
| } |
| else { |
| result += "<invalid module id>: "; |
| } |
| |
| if ((tmp = getEventName()) != null) { |
| result += tmp + ": "; |
| } |
| else { |
| result += "<invalid event id>: "; |
| } |
| |
| result += getEventMsg(); |
| |
| return (result); |
| } |
| |
| /* |
| * ======== getRecordSize ======== |
| */ |
| public int getRecordSize() |
| { |
| return (meta.getTargetEventRecSize()); |
| } |
| |
| /* |
| * ======== Comparator ======== |
| * Comparator for sorting records based on sequence number. |
| */ |
| public class CompareRecs implements Comparator<HostEvent> |
| { |
| public int compare(HostEvent o1, HostEvent o2) |
| { |
| long seq1 = o1.sequenceNum; |
| long seq2 = o2.sequenceNum; |
| |
| return ((int) (seq1 - seq2)); |
| } |
| } |
| } |