traceview

16:53:44.577 INFO  jd.cli.Main - Decompiling traceview.jar
package com.android.traceview;

public final class Call$TraceAction
{
  public static final int ACTION_ENTER = 0;
  public static final int ACTION_EXIT = 1;
  public final int mAction;
  public final Call mCall;
  
  public Call$TraceAction(int action, Call call)
  {
    mAction = action;
    mCall = call;
  }
}

/* Location:
 * Qualified Name:     com.android.traceview.Call.TraceAction
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.traceview;

import org.eclipse.swt.graphics.Color;

class Call
  implements TimeLineView.Block
{
  private final ThreadData mThreadData;
  private final MethodData mMethodData;
  final Call mCaller;
  private String mName;
  private boolean mIsRecursive;
  long mGlobalStartTime;
  long mGlobalEndTime;
  long mThreadStartTime;
  long mThreadEndTime;
  long mInclusiveRealTime;
  long mExclusiveRealTime;
  long mInclusiveCpuTime;
  long mExclusiveCpuTime;
  
  Call(ThreadData threadData, MethodData methodData, Call caller)
  {
    mThreadData = threadData;
    mMethodData = methodData;
    mName = methodData.getProfileName();
    mCaller = caller;
  }
  
  public void updateName()
  {
    mName = mMethodData.getProfileName();
  }
  
  public double addWeight(int x, int y, double weight)
  {
    return mMethodData.addWeight(x, y, weight);
  }
  
  public void clearWeight()
  {
    mMethodData.clearWeight();
  }
  
  public long getStartTime()
  {
    return mGlobalStartTime;
  }
  
  public long getEndTime()
  {
    return mGlobalEndTime;
  }
  
  public long getExclusiveCpuTime()
  {
    return mExclusiveCpuTime;
  }
  
  public long getInclusiveCpuTime()
  {
    return mInclusiveCpuTime;
  }
  
  public long getExclusiveRealTime()
  {
    return mExclusiveRealTime;
  }
  
  public long getInclusiveRealTime()
  {
    return mInclusiveRealTime;
  }
  
  public Color getColor()
  {
    return mMethodData.getColor();
  }
  
  public String getName()
  {
    return mName;
  }
  
  public void setName(String name)
  {
    mName = name;
  }
  
  public ThreadData getThreadData()
  {
    return mThreadData;
  }
  
  public int getThreadId()
  {
    return mThreadData.getId();
  }
  
  public MethodData getMethodData()
  {
    return mMethodData;
  }
  
  public boolean isContextSwitch()
  {
    return mMethodData.getId() == -1;
  }
  
  public boolean isIgnoredBlock()
  {
    return (mCaller == null) || ((isContextSwitch()) && (mCaller.mCaller == null));
  }
  
  public TimeLineView.Block getParentBlock()
  {
    return mCaller;
  }
  
  public boolean isRecursive()
  {
    return mIsRecursive;
  }
  
  void setRecursive(boolean isRecursive)
  {
    mIsRecursive = isRecursive;
  }
  
  void addCpuTime(long elapsedCpuTime)
  {
    mExclusiveCpuTime += elapsedCpuTime;
    mInclusiveCpuTime += elapsedCpuTime;
  }
  
  void finish()
  {
    if (mCaller != null)
    {
      mCaller.mInclusiveCpuTime += mInclusiveCpuTime;
      mCaller.mInclusiveRealTime += mInclusiveRealTime;
    }
    mMethodData.addElapsedExclusive(mExclusiveCpuTime, mExclusiveRealTime);
    if (!mIsRecursive) {
      mMethodData.addTopExclusive(mExclusiveCpuTime, mExclusiveRealTime);
    }
    mMethodData.addElapsedInclusive(mInclusiveCpuTime, mInclusiveRealTime, mIsRecursive, mCaller);
  }
  
  public static final class TraceAction
  {
    public static final int ACTION_ENTER = 0;
    public static final int ACTION_EXIT = 1;
    public final int mAction;
    public final Call mCall;
    
    public TraceAction(int action, Call call)
    {
      mAction = action;
      mCall = call;
    }
  }
}

/* Location:
 * Qualified Name:     com.android.traceview.Call
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.traceview;

import java.util.HashMap;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;

public class ColorController
{
  private static final int[] systemColors = { 9, 3, 5, 13, 11, 10, 4, 6, 8, 14, 12, 2 };
  private static RGB[] rgbColors = { new RGB(90, 90, 255), new RGB(0, 240, 0), new RGB(255, 0, 0), new RGB(0, 255, 255), new RGB(255, 80, 255), new RGB(200, 200, 0), new RGB(40, 0, 200), new RGB(150, 255, 150), new RGB(150, 0, 0), new RGB(30, 150, 150), new RGB(200, 200, 255), new RGB(0, 120, 0), new RGB(255, 150, 150), new RGB(140, 80, 140), new RGB(150, 100, 50), new RGB(70, 70, 70) };
  private static HashMap<Integer, Color> colorCache = new HashMap();
  private static HashMap<Integer, Image> imageCache = new HashMap();
  
  public static Color requestColor(Display display, RGB rgb)
  {
    return requestColor(display, red, green, blue);
  }
  
  public static Image requestColorSquare(Display display, RGB rgb)
  {
    return requestColorSquare(display, red, green, blue);
  }
  
  public static Color requestColor(Display display, int red, int green, int blue)
  {
    int key = red << 16 | green << 8 | blue;
    Color color = (Color)colorCache.get(Integer.valueOf(key));
    if (color == null)
    {
      color = new Color(display, red, green, blue);
      colorCache.put(Integer.valueOf(key), color);
    }
    return color;
  }
  
  public static Image requestColorSquare(Display display, int red, int green, int blue)
  {
    int key = red << 16 | green << 8 | blue;
    Image image = (Image)imageCache.get(Integer.valueOf(key));
    if (image == null)
    {
      image = new Image(display, 8, 14);
      GC gc = new GC(image);
      Color color = requestColor(display, red, green, blue);
      gc.setBackground(color);
      gc.fillRectangle(image.getBounds());
      gc.dispose();
      imageCache.put(Integer.valueOf(key), image);
    }
    return image;
  }
  
  public static void assignMethodColors(Display display, MethodData[] methods)
  {
    int nextColorIndex = 0;
    for (MethodData md : methods)
    {
      RGB rgb = rgbColors[nextColorIndex];
      nextColorIndex++;
      if (nextColorIndex == rgbColors.length) {
        nextColorIndex = 0;
      }
      Color color = requestColor(display, rgb);
      Image image = requestColorSquare(display, rgb);
      md.setColor(color);
      md.setImage(image);
      
      int fadedRed = 150 + red / 4;
      int fadedGreen = 150 + green / 4;
      int fadedBlue = 150 + blue / 4;
      RGB faded = new RGB(fadedRed, fadedGreen, fadedBlue);
      color = requestColor(display, faded);
      image = requestColorSquare(display, faded);
      md.setFadedColor(color);
      md.setFadedImage(image);
    }
  }
}

/* Location:
 * Qualified Name:     com.android.traceview.ColorController
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.traceview;

import java.util.Comparator;

class DmTraceReader$1
  implements Comparator<ThreadData>
{
  DmTraceReader$1(DmTraceReader paramDmTraceReader, TimeBase paramTimeBase) {}
  
  public int compare(ThreadData td1, ThreadData td2)
  {
    if (val$timeBase.getTime(td2) > val$timeBase.getTime(td1)) {
      return 1;
    }
    if (val$timeBase.getTime(td2) < val$timeBase.getTime(td1)) {
      return -1;
    }
    return td2.getName().compareTo(td1.getName());
  }
}

/* Location:
 * Qualified Name:     com.android.traceview.DmTraceReader.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.traceview;

import java.util.Comparator;

class DmTraceReader$2
  implements Comparator<MethodData>
{
  DmTraceReader$2(DmTraceReader paramDmTraceReader, TimeBase paramTimeBase) {}
  
  public int compare(MethodData md1, MethodData md2)
  {
    if (val$timeBase.getElapsedInclusiveTime(md2) > val$timeBase.getElapsedInclusiveTime(md1)) {
      return 1;
    }
    if (val$timeBase.getElapsedInclusiveTime(md2) < val$timeBase.getElapsedInclusiveTime(md1)) {
      return -1;
    }
    return md1.getName().compareTo(md2.getName());
  }
}

/* Location:
 * Qualified Name:     com.android.traceview.DmTraceReader.2
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.traceview;

class DmTraceReader$3 {}

/* Location:
 * Qualified Name:     com.android.traceview.DmTraceReader.3
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.traceview;

 enum DmTraceReader$ClockSource
{
  THREAD_CPU,  WALL,  DUAL;
  
  private DmTraceReader$ClockSource() {}
}

/* Location:
 * Qualified Name:     com.android.traceview.DmTraceReader.ClockSource
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.traceview;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.nio.BufferUnderflowException;
import java.nio.ByteOrder;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class DmTraceReader
  extends TraceReader
{
  private static final int TRACE_MAGIC = 1464814675;
  private static final int METHOD_TRACE_ENTER = 0;
  private static final int METHOD_TRACE_EXIT = 1;
  private static final int METHOD_TRACE_UNROLL = 2;
  private static final long MIN_CONTEXT_SWITCH_TIME_USEC = 100L;
  private int mVersionNumber;
  private boolean mRegression;
  private ProfileProvider mProfileProvider;
  private String mTraceFileName;
  private MethodData mTopLevel;
  private ArrayList<Call> mCallList;
  private HashMap<String, String> mPropertiesMap;
  private HashMap<Integer, MethodData> mMethodMap;
  private HashMap<Integer, ThreadData> mThreadMap;
  private ThreadData[] mSortedThreads;
  private MethodData[] mSortedMethods;
  private long mTotalCpuTime;
  private long mTotalRealTime;
  private MethodData mContextSwitch;
  private int mRecordSize;
  private ClockSource mClockSource;
  
  private static enum ClockSource
  {
    THREAD_CPU,  WALL,  DUAL;
    
    private ClockSource() {}
  }
  
  private static final Pattern mIdNamePattern = Pattern.compile("(\\d+)\t(.*)");
  static final int PARSE_VERSION = 0;
  static final int PARSE_THREADS = 1;
  static final int PARSE_METHODS = 2;
  static final int PARSE_OPTIONS = 4;
  
  public DmTraceReader(String traceFileName, boolean regression)
    throws IOException
  {
    mTraceFileName = traceFileName;
    mRegression = regression;
    mPropertiesMap = new HashMap();
    mMethodMap = new HashMap();
    mThreadMap = new HashMap();
    mCallList = new ArrayList();
    
    mTopLevel = new MethodData(0, "(toplevel)");
    mContextSwitch = new MethodData(-1, "(context switch)");
    mMethodMap.put(Integer.valueOf(0), mTopLevel);
    mMethodMap.put(Integer.valueOf(-1), mContextSwitch);
    generateTrees();
  }
  
  void generateTrees()
    throws IOException
  {
    long offset = parseKeys();
    parseData(offset);
    analyzeData();
  }
  
  public ProfileProvider getProfileProvider()
  {
    if (mProfileProvider == null) {
      mProfileProvider = new ProfileProvider(this);
    }
    return mProfileProvider;
  }
  
  private MappedByteBuffer mapFile(String filename, long offset)
    throws IOException
  {
    MappedByteBuffer buffer = null;
    FileInputStream dataFile = new FileInputStream(filename);
    try
    {
      File file = new File(filename);
      FileChannel fc = dataFile.getChannel();
      buffer = fc.map(FileChannel.MapMode.READ_ONLY, offset, file.length() - offset);
      buffer.order(ByteOrder.LITTLE_ENDIAN);
      
      return buffer;
    }
    finally
    {
      dataFile.close();
    }
  }
  
  private void readDataFileHeader(MappedByteBuffer buffer)
  {
    int magic = buffer.getInt();
    if (magic != 1464814675)
    {
      System.err.printf("Error: magic number mismatch; got 0x%x, expected 0x%x\n", new Object[] { Integer.valueOf(magic), Integer.valueOf(1464814675) });
      
      throw new RuntimeException();
    }
    int version = buffer.getShort();
    if (version != mVersionNumber)
    {
      System.err.printf("Error: version number mismatch; got %d in data header but %d in options\n", new Object[] { Integer.valueOf(version), Integer.valueOf(mVersionNumber) });
      
      throw new RuntimeException();
    }
    if ((version < 1) || (version > 3))
    {
      System.err.printf("Error: unsupported trace version number %d.  Please use a newer version of TraceView to read this file.", new Object[] { Integer.valueOf(version) });
      
      throw new RuntimeException();
    }
    int offsetToData = buffer.getShort() - 16;
    
    buffer.getLong();
    if (version == 1)
    {
      mRecordSize = 9;
    }
    else if (version == 2)
    {
      mRecordSize = 10;
    }
    else
    {
      mRecordSize = buffer.getShort();
      offsetToData -= 2;
    }
    while (offsetToData-- > 0) {
      buffer.get();
    }
  }
  
  private void parseData(long offset)
    throws IOException
  {
    MappedByteBuffer buffer = mapFile(mTraceFileName, offset);
    readDataFileHeader(buffer);
    
    ArrayList<TraceAction> trace = null;
    if (mClockSource == ClockSource.THREAD_CPU) {
      trace = new ArrayList();
    }
    boolean haveThreadClock = mClockSource != ClockSource.WALL;
    boolean haveGlobalClock = mClockSource != ClockSource.THREAD_CPU;
    
    ThreadData prevThreadData = null;
    for (;;)
    {
      int threadId;
      int methodId;
      long threadTime;
      long globalTime;
      try
      {
        int recordSize = mRecordSize;
        if (mVersionNumber == 1)
        {
          int threadId = buffer.get();
          recordSize--;
        }
        else
        {
          threadId = buffer.getShort();
          recordSize -= 2;
        }
        methodId = buffer.getInt();
        recordSize -= 4;
        switch (mClockSource)
        {
        case WALL: 
          threadTime = 0L;
          globalTime = buffer.getInt();
          recordSize -= 4;
          break;
        case DUAL: 
          threadTime = buffer.getInt();
          globalTime = buffer.getInt();
          recordSize -= 8;
          break;
        case THREAD_CPU: 
        default: 
          threadTime = buffer.getInt();
          globalTime = 0L;
          recordSize -= 4;
        }
        if (recordSize-- > 0)
        {
          buffer.get(); continue;
        }
      }
      catch (BufferUnderflowException ex)
      {
        break;
      }
      int methodAction = methodId & 0x3;
      methodId &= 0xFFFFFFFC;
      MethodData methodData = (MethodData)mMethodMap.get(Integer.valueOf(methodId));
      if (methodData == null)
      {
        String name = String.format("(0x%1$x)", new Object[] { Integer.valueOf(methodId) });
        methodData = new MethodData(methodId, name);
        mMethodMap.put(Integer.valueOf(methodId), methodData);
      }
      ThreadData threadData = (ThreadData)mThreadMap.get(Integer.valueOf(threadId));
      if (threadData == null)
      {
        String name = String.format("[%1$d]", new Object[] { Integer.valueOf(threadId) });
        threadData = new ThreadData(threadId, name, mTopLevel);
        mThreadMap.put(Integer.valueOf(threadId), threadData);
      }
      long elapsedGlobalTime = 0L;
      if (haveGlobalClock)
      {
        if (!mHaveGlobalTime)
        {
          mGlobalStartTime = globalTime;
          mHaveGlobalTime = true;
        }
        else
        {
          elapsedGlobalTime = globalTime - mGlobalEndTime;
        }
        mGlobalEndTime = globalTime;
      }
      if (haveThreadClock)
      {
        long elapsedThreadTime = 0L;
        if (!mHaveThreadTime)
        {
          mThreadStartTime = threadTime;
          mThreadCurrentTime = threadTime;
          mHaveThreadTime = true;
        }
        else
        {
          elapsedThreadTime = threadTime - mThreadEndTime;
        }
        mThreadEndTime = threadTime;
        if (!haveGlobalClock)
        {
          if ((prevThreadData != null) && (prevThreadData != threadData))
          {
            Call switchCall = prevThreadData.enter(mContextSwitch, trace);
            mThreadStartTime = mThreadEndTime;
            mCallList.add(switchCall);
            
            Call top = threadData.top();
            if (top.getMethodData() == mContextSwitch)
            {
              threadData.exit(mContextSwitch, trace);
              long beforeSwitch = elapsedThreadTime / 2L;
              mThreadStartTime += beforeSwitch;
              mThreadEndTime = mThreadStartTime;
            }
          }
          prevThreadData = threadData;
        }
        else
        {
          long sleepTime = elapsedGlobalTime - elapsedThreadTime;
          if (sleepTime > 100L)
          {
            Call switchCall = threadData.enter(mContextSwitch, trace);
            long beforeSwitch = elapsedThreadTime / 2L;
            long afterSwitch = elapsedThreadTime - beforeSwitch;
            mGlobalStartTime = (globalTime - elapsedGlobalTime + beforeSwitch);
            mGlobalEndTime = (globalTime - afterSwitch);
            mThreadStartTime = (threadTime - afterSwitch);
            mThreadEndTime = mThreadStartTime;
            threadData.exit(mContextSwitch, trace);
            mCallList.add(switchCall);
          }
        }
        Call top = threadData.top();
        top.addCpuTime(elapsedThreadTime);
      }
      switch (methodAction)
      {
      case 0: 
        Call call = threadData.enter(methodData, trace);
        if (haveGlobalClock) {
          mGlobalStartTime = globalTime;
        }
        if (haveThreadClock) {
          mThreadStartTime = threadTime;
        }
        mCallList.add(call);
        break;
      case 1: 
      case 2: 
        Call call = threadData.exit(methodData, trace);
        if (call != null)
        {
          if (haveGlobalClock) {
            mGlobalEndTime = globalTime;
          }
          if (haveThreadClock) {
            mThreadEndTime = threadTime;
          }
        }
        break;
      default: 
        throw new RuntimeException("Unrecognized method action: " + methodAction);
      }
    }
    for (ThreadData threadData : mThreadMap.values()) {
      threadData.endTrace(trace);
    }
    long globalTime;
    if (!haveGlobalClock)
    {
      globalTime = 0L;
      prevThreadData = null;
      for (TraceAction traceAction : trace)
      {
        Call call = mCall;
        ThreadData threadData = call.getThreadData();
        if (mAction == 0)
        {
          long threadTime = mThreadStartTime;
          globalTime += mThreadStartTime - mThreadCurrentTime;
          mGlobalStartTime = globalTime;
          if (!mHaveGlobalTime)
          {
            mHaveGlobalTime = true;
            mGlobalStartTime = globalTime;
          }
          mThreadCurrentTime = threadTime;
        }
        else if (mAction == 1)
        {
          long threadTime = mThreadEndTime;
          globalTime += mThreadEndTime - mThreadCurrentTime;
          mGlobalEndTime = globalTime;
          mGlobalEndTime = globalTime;
          mThreadCurrentTime = threadTime;
        }
        prevThreadData = threadData;
      }
    }
    for (int i = mCallList.size() - 1; i >= 0; i--)
    {
      Call call = (Call)mCallList.get(i);
      
      long realTime = mGlobalEndTime - mGlobalStartTime;
      mExclusiveRealTime = Math.max(realTime - mInclusiveRealTime, 0L);
      mInclusiveRealTime = realTime;
      
      call.finish();
    }
    mTotalCpuTime = 0L;
    mTotalRealTime = 0L;
    for (ThreadData threadData : mThreadMap.values())
    {
      Call rootCall = threadData.getRootCall();
      threadData.updateRootCallTimeBounds();
      rootCall.finish();
      mTotalCpuTime += mInclusiveCpuTime;
      mTotalRealTime += mInclusiveRealTime;
    }
    if (mRegression)
    {
      System.out.format("totalCpuTime %dus\n", new Object[] { Long.valueOf(mTotalCpuTime) });
      System.out.format("totalRealTime %dus\n", new Object[] { Long.valueOf(mTotalRealTime) });
      
      dumpThreadTimes();
      dumpCallTimes();
    }
  }
  
  long parseKeys()
    throws IOException
  {
    long offset = 0L;
    BufferedReader in = null;
    try
    {
      in = new BufferedReader(new InputStreamReader(new FileInputStream(mTraceFileName), "US-ASCII"));
      
      int mode = 0;
      String line = null;
      for (;;)
      {
        line = in.readLine();
        if (line == null) {
          throw new IOException("Key section does not have an *end marker");
        }
        offset += line.length() + 1;
        if (line.startsWith("*"))
        {
          if (line.equals("*version")) {
            mode = 0;
          } else if (line.equals("*threads")) {
            mode = 1;
          } else if (line.equals("*methods")) {
            mode = 2;
          } else {
            if (line.equals("*end")) {
              break;
            }
          }
        }
        else {
          switch (mode)
          {
          case 0: 
            mVersionNumber = Integer.decode(line).intValue();
            mode = 4;
            break;
          case 1: 
            parseThread(line);
            break;
          case 2: 
            parseMethod(line);
            break;
          case 4: 
            parseOption(line);
          }
        }
      }
    }
    catch (FileNotFoundException ex)
    {
      System.err.println(ex.getMessage());
    }
    finally
    {
      if (in != null) {
        in.close();
      }
    }
    if (mClockSource == null) {
      mClockSource = ClockSource.THREAD_CPU;
    }
    return offset;
  }
  
  void parseOption(String line)
  {
    String[] tokens = line.split("=");
    if (tokens.length == 2)
    {
      String key = tokens[0];
      String value = tokens[1];
      mPropertiesMap.put(key, value);
      if (key.equals("clock")) {
        if (value.equals("thread-cpu")) {
          mClockSource = ClockSource.THREAD_CPU;
        } else if (value.equals("wall")) {
          mClockSource = ClockSource.WALL;
        } else if (value.equals("dual")) {
          mClockSource = ClockSource.DUAL;
        }
      }
    }
  }
  
  void parseThread(String line)
  {
    String idStr = null;
    String name = null;
    Matcher matcher = mIdNamePattern.matcher(line);
    if (matcher.find())
    {
      idStr = matcher.group(1);
      name = matcher.group(2);
    }
    if (idStr == null) {
      return;
    }
    if (name == null) {
      name = "(unknown)";
    }
    int id = Integer.decode(idStr).intValue();
    mThreadMap.put(Integer.valueOf(id), new ThreadData(id, name, mTopLevel));
  }
  
  void parseMethod(String line)
  {
    String[] tokens = line.split("\t");
    int id = Long.decode(tokens[0]).intValue();
    String className = tokens[1];
    String methodName = null;
    String signature = null;
    String pathname = null;
    int lineNumber = -1;
    if (tokens.length == 6)
    {
      methodName = tokens[2];
      signature = tokens[3];
      pathname = tokens[4];
      lineNumber = Integer.decode(tokens[5]).intValue();
      pathname = constructPathname(className, pathname);
    }
    else if (tokens.length > 2)
    {
      if (tokens[3].startsWith("("))
      {
        methodName = tokens[2];
        signature = tokens[3];
      }
      else
      {
        pathname = tokens[2];
        lineNumber = Integer.decode(tokens[3]).intValue();
      }
    }
    mMethodMap.put(Integer.valueOf(id), new MethodData(id, className, methodName, signature, pathname, lineNumber));
  }
  
  private String constructPathname(String className, String pathname)
  {
    int index = className.lastIndexOf('/');
    if ((index > 0) && (index < className.length() - 1) && (pathname.endsWith(".java"))) {
      pathname = className.substring(0, index + 1) + pathname;
    }
    return pathname;
  }
  
  private void analyzeData()
  {
    final TimeBase timeBase = getPreferredTimeBase();
    
    Collection<ThreadData> tv = mThreadMap.values();
    mSortedThreads = ((ThreadData[])tv.toArray(new ThreadData[tv.size()]));
    Arrays.sort(mSortedThreads, new Comparator()
    {
      public int compare(ThreadData td1, ThreadData td2)
      {
        if (timeBase.getTime(td2) > timeBase.getTime(td1)) {
          return 1;
        }
        if (timeBase.getTime(td2) < timeBase.getTime(td1)) {
          return -1;
        }
        return td2.getName().compareTo(td1.getName());
      }
    });
    Collection<MethodData> mv = mMethodMap.values();
    
    MethodData[] methods = (MethodData[])mv.toArray(new MethodData[mv.size()]);
    Arrays.sort(methods, new Comparator()
    {
      public int compare(MethodData md1, MethodData md2)
      {
        if (timeBase.getElapsedInclusiveTime(md2) > timeBase.getElapsedInclusiveTime(md1)) {
          return 1;
        }
        if (timeBase.getElapsedInclusiveTime(md2) < timeBase.getElapsedInclusiveTime(md1)) {
          return -1;
        }
        return md1.getName().compareTo(md2.getName());
      }
    });
    int nonZero = 0;
    for (MethodData md : methods)
    {
      if (timeBase.getElapsedInclusiveTime(md) == 0L) {
        break;
      }
      nonZero++;
    }
    mSortedMethods = new MethodData[nonZero];
    int ii = 0;
    for (MethodData md : methods)
    {
      if (timeBase.getElapsedInclusiveTime(md) == 0L) {
        break;
      }
      md.setRank(ii);
      mSortedMethods[(ii++)] = md;
    }
    for (MethodData md : mSortedMethods) {
      md.analyzeData(timeBase);
    }
    for (Call call : mCallList) {
      call.updateName();
    }
    if (mRegression) {
      dumpMethodStats();
    }
  }
  
  public ArrayList<TimeLineView.Record> getThreadTimeRecords()
  {
    ArrayList<TimeLineView.Record> timeRecs = new ArrayList();
    for (ThreadData threadData : mSortedThreads) {
      if ((!threadData.isEmpty()) && (threadData.getId() != 0))
      {
        TimeLineView.Record record = new TimeLineView.Record(threadData, threadData.getRootCall());
        timeRecs.add(record);
      }
    }
    for (Call call : mCallList)
    {
      TimeLineView.Record record = new TimeLineView.Record(call.getThreadData(), call);
      timeRecs.add(record);
    }
    if (mRegression)
    {
      dumpTimeRecs(timeRecs);
      System.exit(0);
    }
    return timeRecs;
  }
  
  private void dumpThreadTimes()
  {
    System.out.print("\nThread Times\n");
    System.out.print("id  t-start    t-end  g-start    g-end     name\n");
    for (ThreadData threadData : mThreadMap.values()) {
      System.out.format("%2d %8d %8d %8d %8d  %s\n", new Object[] { Integer.valueOf(threadData.getId()), Long.valueOf(mThreadStartTime), Long.valueOf(mThreadEndTime), Long.valueOf(mGlobalStartTime), Long.valueOf(mGlobalEndTime), threadData.getName() });
    }
  }
  
  private void dumpCallTimes()
  {
    System.out.print("\nCall Times\n");
    System.out.print("id  t-start    t-end  g-start    g-end    excl.    incl.  method\n");
    for (Call call : mCallList) {
      System.out.format("%2d %8d %8d %8d %8d %8d %8d  %s\n", new Object[] { Integer.valueOf(call.getThreadId()), Long.valueOf(mThreadStartTime), Long.valueOf(mThreadEndTime), Long.valueOf(mGlobalStartTime), Long.valueOf(mGlobalEndTime), Long.valueOf(mExclusiveCpuTime), Long.valueOf(mInclusiveCpuTime), call.getMethodData().getName() });
    }
  }
  
  private void dumpMethodStats()
  {
    System.out.print("\nMethod Stats\n");
    System.out.print("Excl Cpu  Incl Cpu  Excl Real Incl Real    Calls  Method\n");
    for (MethodData md : mSortedMethods) {
      System.out.format("%9d %9d %9d %9d %9s  %s\n", new Object[] { Long.valueOf(md.getElapsedExclusiveCpuTime()), Long.valueOf(md.getElapsedInclusiveCpuTime()), Long.valueOf(md.getElapsedExclusiveRealTime()), Long.valueOf(md.getElapsedInclusiveRealTime()), md.getCalls(), md.getProfileName() });
    }
  }
  
  private void dumpTimeRecs(ArrayList<TimeLineView.Record> timeRecs)
  {
    System.out.print("\nTime Records\n");
    System.out.print("id  t-start    t-end  g-start    g-end  method\n");
    for (TimeLineView.Record record : timeRecs)
    {
      Call call = (Call)block;
      System.out.format("%2d %8d %8d %8d %8d  %s\n", new Object[] { Integer.valueOf(call.getThreadId()), Long.valueOf(mThreadStartTime), Long.valueOf(mThreadEndTime), Long.valueOf(mGlobalStartTime), Long.valueOf(mGlobalEndTime), call.getMethodData().getName() });
    }
  }
  
  public HashMap<Integer, String> getThreadLabels()
  {
    HashMap<Integer, String> labels = new HashMap();
    for (ThreadData t : mThreadMap.values()) {
      labels.put(Integer.valueOf(t.getId()), t.getName());
    }
    return labels;
  }
  
  public MethodData[] getMethods()
  {
    return mSortedMethods;
  }
  
  public ThreadData[] getThreads()
  {
    return mSortedThreads;
  }
  
  public long getTotalCpuTime()
  {
    return mTotalCpuTime;
  }
  
  public long getTotalRealTime()
  {
    return mTotalRealTime;
  }
  
  public boolean haveCpuTime()
  {
    return mClockSource != ClockSource.WALL;
  }
  
  public boolean haveRealTime()
  {
    return mClockSource != ClockSource.THREAD_CPU;
  }
  
  public HashMap<String, String> getProperties()
  {
    return mPropertiesMap;
  }
  
  public TimeBase getPreferredTimeBase()
  {
    if (mClockSource == ClockSource.WALL) {
      return TimeBase.REAL_TIME;
    }
    return TimeBase.CPU_TIME;
  }
  
  public String getClockSource()
  {
    switch (mClockSource)
    {
    case THREAD_CPU: 
      return "cpu time";
    case WALL: 
      return "real time";
    case DUAL: 
      return "real time, dual clock";
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     com.android.traceview.DmTraceReader
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.traceview;

import org.eclipse.jface.action.Action;

class MainWindow$1
  extends Action
{
  MainWindow$1(MainWindow paramMainWindow, String x0)
  {
    super(x0);
  }
  
  public void run()
  {
    MainWindow.access$000(this$0);
  }
}

/* Location:
 * Qualified Name:     com.android.traceview.MainWindow.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.traceview;

import com.android.sdkstats.SdkStatsService;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.nio.channels.FileChannel;
import java.util.HashMap;
import java.util.Properties;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class MainWindow
  extends ApplicationWindow
{
  private static final String PING_NAME = "Traceview";
  private TraceReader mReader;
  private String mTraceName;
  public static HashMap<String, String> sStringCache = new HashMap();
  
  public MainWindow(String traceName, TraceReader reader)
  {
    super(null);
    mReader = reader;
    mTraceName = traceName;
    
    addMenuBar();
  }
  
  public void run()
  {
    setBlockOnOpen(true);
    open();
  }
  
  protected void configureShell(Shell shell)
  {
    super.configureShell(shell);
    shell.setText("Traceview: " + mTraceName);
    
    InputStream in = getClass().getClassLoader().getResourceAsStream("icons/traceview-128.png");
    if (in != null) {
      shell.setImage(new Image(shell.getDisplay(), in));
    }
    shell.setBounds(100, 10, 1282, 900);
  }
  
  protected Control createContents(Composite parent)
  {
    ColorController.assignMethodColors(parent.getDisplay(), mReader.getMethods());
    SelectionController selectionController = new SelectionController();
    
    GridLayout gridLayout = new GridLayout(1, false);
    marginWidth = 0;
    marginHeight = 0;
    horizontalSpacing = 0;
    verticalSpacing = 0;
    parent.setLayout(gridLayout);
    
    Display display = parent.getDisplay();
    Color darkGray = display.getSystemColor(16);
    
    SashForm sashForm1 = new SashForm(parent, 512);
    sashForm1.setBackground(darkGray);
    SASH_WIDTH = 3;
    GridData data = new GridData(1808);
    sashForm1.setLayoutData(data);
    
    new TimeLineView(sashForm1, mReader, selectionController);
    
    new ProfileView(sashForm1, mReader, selectionController);
    return sashForm1;
  }
  
  protected MenuManager createMenuManager()
  {
    MenuManager manager = super.createMenuManager();
    
    MenuManager viewMenu = new MenuManager("View");
    manager.add(viewMenu);
    
    Action showPropertiesAction = new Action("Show Properties...")
    {
      public void run()
      {
        MainWindow.this.showProperties();
      }
    };
    viewMenu.add(showPropertiesAction);
    
    return manager;
  }
  
  private void showProperties()
  {
    PropertiesDialog dialog = new PropertiesDialog(getShell());
    dialog.setProperties(mReader.getProperties());
    dialog.open();
  }
  
  private static String makeTempTraceFile(String base)
    throws IOException
  {
    File temp = File.createTempFile(base, ".trace");
    temp.deleteOnExit();
    
    FileOutputStream dstStream = null;
    FileInputStream keyStream = null;
    FileInputStream dataStream = null;
    try
    {
      dstStream = new FileOutputStream(temp);
      FileChannel dstChannel = dstStream.getChannel();
      
      keyStream = new FileInputStream(base + ".key");
      FileChannel srcChannel = keyStream.getChannel();
      long size = dstChannel.transferFrom(srcChannel, 0L, srcChannel.size());
      srcChannel.close();
      
      dataStream = new FileInputStream(base + ".data");
      srcChannel = dataStream.getChannel();
      dstChannel.transferFrom(srcChannel, size, srcChannel.size());
    }
    finally
    {
      if (dstStream != null) {
        dstStream.close();
      }
      if (keyStream != null) {
        keyStream.close();
      }
      if (dataStream != null) {
        dataStream.close();
      }
    }
    return temp.getPath();
  }
  
  private static String getRevision()
  {
    Properties p = new Properties();
    try
    {
      String toolsdir = System.getProperty("com.android.traceview.toolsdir");
      File sourceProp;
      File sourceProp;
      if ((toolsdir == null) || (toolsdir.length() == 0)) {
        sourceProp = new File("source.properties");
      } else {
        sourceProp = new File(toolsdir, "source.properties");
      }
      FileInputStream fis = null;
      try
      {
        fis = new FileInputStream(sourceProp);
        p.load(fis);
        if (fis != null) {
          try
          {
            fis.close();
          }
          catch (IOException ignore) {}
        }
        revision = p.getProperty("Pkg.Revision");
      }
      finally
      {
        if (fis != null) {
          try
          {
            fis.close();
          }
          catch (IOException ignore) {}
        }
      }
      String revision;
      if ((revision != null) && (revision.length() > 0)) {
        return revision;
      }
    }
    catch (FileNotFoundException e) {}catch (IOException e) {}
    return null;
  }
  
  public static void main(String[] args)
  {
    TraceReader reader = null;
    boolean regression = false;
    
    String revision = getRevision();
    if (revision != null) {
      new SdkStatsService().ping("Traceview", revision);
    }
    int argc = 0;
    int len = args.length;
    while (argc < len)
    {
      String arg = args[argc];
      if (arg.charAt(0) != '-') {
        break;
      }
      if (!arg.equals("-r")) {
        break;
      }
      regression = true;
      
      argc++;
    }
    if (argc != len - 1)
    {
      System.out.printf("Usage: java %s [-r] trace%n", new Object[] { MainWindow.class.getName() });
      System.out.printf("  -r   regression only%n", new Object[0]);
      return;
    }
    String traceName = args[(len - 1)];
    File file = new File(traceName);
    if ((file.exists()) && (file.isDirectory()))
    {
      System.out.printf("Qemu trace files not supported yet.\n", new Object[0]);
      System.exit(1);
    }
    else
    {
      if (!file.exists()) {
        if (new File(traceName + ".trace").exists())
        {
          traceName = traceName + ".trace";
        }
        else if ((new File(traceName + ".data").exists()) && (new File(traceName + ".key").exists()))
        {
          try
          {
            traceName = makeTempTraceFile(traceName);
          }
          catch (IOException e)
          {
            System.err.printf("cannot convert old trace file '%s'\n", new Object[] { traceName });
            System.exit(1);
          }
        }
        else
        {
          System.err.printf("trace file '%s' not found\n", new Object[] { traceName });
          System.exit(1);
        }
      }
      try
      {
        reader = new DmTraceReader(traceName, regression);
      }
      catch (IOException e)
      {
        System.err.printf("Failed to read the trace file", new Object[0]);
        e.printStackTrace();
        System.exit(1);
        return;
      }
    }
    reader.getTraceUnits().setTimeScale(TraceUnits.TimeScale.MilliSeconds);
    
    Display.setAppName("Traceview");
    new MainWindow(traceName, reader).run();
  }
}

/* Location:
 * Qualified Name:     com.android.traceview.MainWindow
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.traceview;

import java.util.Comparator;

class MethodData$1
  implements Comparator<ProfileData>
{
  MethodData$1(MethodData paramMethodData, TimeBase paramTimeBase) {}
  
  public int compare(ProfileData pd1, ProfileData pd2)
  {
    if (val$timeBase.getElapsedInclusiveTime(pd2) > val$timeBase.getElapsedInclusiveTime(pd1)) {
      return 1;
    }
    if (val$timeBase.getElapsedInclusiveTime(pd2) < val$timeBase.getElapsedInclusiveTime(pd1)) {
      return -1;
    }
    return 0;
  }
}

/* Location:
 * Qualified Name:     com.android.traceview.MethodData.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.traceview;

public enum MethodData$Sorter$Column
{
  BY_NAME,  BY_EXCLUSIVE_CPU_TIME,  BY_EXCLUSIVE_REAL_TIME,  BY_INCLUSIVE_CPU_TIME,  BY_INCLUSIVE_REAL_TIME,  BY_CALLS,  BY_REAL_TIME_PER_CALL,  BY_CPU_TIME_PER_CALL;
  
  private MethodData$Sorter$Column() {}
}

/* Location:
 * Qualified Name:     com.android.traceview.MethodData.Sorter.Column
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.traceview;

public enum MethodData$Sorter$Direction
{
  INCREASING,  DECREASING;
  
  private MethodData$Sorter$Direction() {}
}

/* Location:
 * Qualified Name:     com.android.traceview.MethodData.Sorter.Direction
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.traceview;

import java.util.Comparator;

public class MethodData$Sorter
  implements Comparator<MethodData>
{
  private Column mColumn;
  private Direction mDirection;
  
  public int compare(MethodData md1, MethodData md2)
  {
    if (mColumn == Column.BY_NAME)
    {
      int result = md1.getName().compareTo(md2.getName());
      return mDirection == Direction.INCREASING ? result : -result;
    }
    if (mColumn == Column.BY_INCLUSIVE_CPU_TIME)
    {
      if (md2.getElapsedInclusiveCpuTime() > md1.getElapsedInclusiveCpuTime()) {
        return mDirection == Direction.INCREASING ? -1 : 1;
      }
      if (md2.getElapsedInclusiveCpuTime() < md1.getElapsedInclusiveCpuTime()) {
        return mDirection == Direct
1 2 3 4 5 6 7

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd