mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
[252130] Memory Import should buffer writes to improve performance
This commit is contained in:
parent
6ee11bc77b
commit
4b0daf25c0
4 changed files with 100 additions and 4 deletions
|
@ -0,0 +1,83 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008 Wind River Systems, Inc. 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:
|
||||
* Ted R Williams (Wind River Systems, Inc.) - initial implementation
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.dd.debug.ui.memory.transport;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
import org.eclipse.debug.core.DebugException;
|
||||
import org.eclipse.debug.core.model.IMemoryBlockExtension;
|
||||
|
||||
public class BufferedMemoryWriter
|
||||
{
|
||||
private IMemoryBlockExtension fBlock;
|
||||
private byte[] fBuffer;
|
||||
private int fBufferPosition = 0;
|
||||
private BigInteger fBufferStart = null;
|
||||
|
||||
public BufferedMemoryWriter(IMemoryBlockExtension block, int bufferLength)
|
||||
{
|
||||
fBlock = block;
|
||||
fBuffer = new byte[bufferLength];
|
||||
}
|
||||
|
||||
public void write(BigInteger address, byte[] data) throws DebugException
|
||||
{
|
||||
while(data.length > 0)
|
||||
{
|
||||
if(fBufferStart == null)
|
||||
{
|
||||
fBufferStart = address;
|
||||
int length = data.length <= fBuffer.length ? data.length : fBuffer.length;
|
||||
System.arraycopy(data, 0, fBuffer, 0, length);
|
||||
fBufferPosition = length;
|
||||
byte[] dataRemainder = new byte[data.length - length];
|
||||
System.arraycopy(data, length, dataRemainder, 0, data.length - length);
|
||||
data = dataRemainder;
|
||||
address = fBufferStart.add(BigInteger.valueOf(length));
|
||||
}
|
||||
else if(fBufferStart.add(BigInteger.valueOf(fBufferPosition)).compareTo(address) != 0)
|
||||
{
|
||||
flush();
|
||||
}
|
||||
else
|
||||
{
|
||||
int availableBufferLength = fBuffer.length - fBufferPosition;
|
||||
int length = data.length <= fBuffer.length - availableBufferLength
|
||||
? data.length : fBuffer.length - availableBufferLength;
|
||||
System.arraycopy(data, 0, fBuffer, fBufferPosition, length);
|
||||
fBufferPosition += length;
|
||||
|
||||
byte[] dataRemainder = new byte[data.length - length];
|
||||
System.arraycopy(data, length, dataRemainder, 0, data.length - length);
|
||||
data = dataRemainder;
|
||||
address = fBufferStart.add(BigInteger.valueOf(length));
|
||||
}
|
||||
|
||||
if(fBufferPosition == fBuffer.length)
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
public void flush() throws DebugException
|
||||
{
|
||||
if(fBufferStart != null)
|
||||
{
|
||||
byte data[] = new byte[fBufferPosition];
|
||||
System.arraycopy(fBuffer, 0, data, 0, fBufferPosition);
|
||||
fBlock.setValue(fBufferStart, data);
|
||||
fBufferStart = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -65,6 +65,8 @@ public class PlainTextImporter implements IMemoryImporter {
|
|||
|
||||
private Properties fProperties;
|
||||
|
||||
private static final int BUFFER_LENGTH = 64 * 1024;
|
||||
|
||||
public Control createControl(final Composite parent, IMemoryBlock memBlock, Properties properties, ImportMemoryDialog parentDialog)
|
||||
{
|
||||
fMemoryBlock = memBlock;
|
||||
|
@ -291,6 +293,8 @@ public class PlainTextImporter implements IMemoryImporter {
|
|||
{
|
||||
try
|
||||
{
|
||||
BufferedMemoryWriter memoryWriter = new BufferedMemoryWriter((IMemoryBlockExtension) fMemoryBlock, BUFFER_LENGTH);
|
||||
|
||||
BigInteger offset = null;
|
||||
if(!fUseCustomAddress)
|
||||
offset = BigInteger.ZERO;
|
||||
|
@ -329,7 +333,7 @@ public class PlainTextImporter implements IMemoryImporter {
|
|||
if(scrollToAddress == null)
|
||||
scrollToAddress = recordAddress;
|
||||
|
||||
((IMemoryBlockExtension) fMemoryBlock).setValue(recordAddress.subtract(((IMemoryBlockExtension)
|
||||
memoryWriter.write(recordAddress.subtract(((IMemoryBlockExtension)
|
||||
fMemoryBlock).getBigBaseAddress()).add(BigInteger.valueOf(bytesRead)), data);
|
||||
|
||||
bytesRead += data.length;
|
||||
|
@ -347,6 +351,7 @@ public class PlainTextImporter implements IMemoryImporter {
|
|||
line = reader.readLine();
|
||||
}
|
||||
|
||||
memoryWriter.flush();
|
||||
reader.close();
|
||||
monitor.done();
|
||||
|
||||
|
|
|
@ -47,7 +47,6 @@ public class SRecordImporter implements IMemoryImporter {
|
|||
|
||||
File fInputFile;
|
||||
BigInteger fStartAddress;
|
||||
boolean fUseCustomAddress;
|
||||
Boolean fScrollToStart;
|
||||
|
||||
private Text fStartText;
|
||||
|
@ -64,6 +63,8 @@ public class SRecordImporter implements IMemoryImporter {
|
|||
|
||||
private Properties fProperties;
|
||||
|
||||
private static final int BUFFER_LENGTH = 64 * 1024;
|
||||
|
||||
public Control createControl(final Composite parent, IMemoryBlock memBlock, Properties properties, ImportMemoryDialog parentDialog)
|
||||
{
|
||||
fMemoryBlock = memBlock;
|
||||
|
@ -77,6 +78,7 @@ public class SRecordImporter implements IMemoryImporter {
|
|||
fProperties.setProperty(TRANSFER_FILE, fFileText.getText());
|
||||
fProperties.setProperty(TRANSFER_START, fStartText.getText());
|
||||
fProperties.setProperty(TRANSFER_SCROLL_TO_START, fScrollToStart.toString());
|
||||
fProperties.setProperty(TRANSFER_CUSTOM_START_ADDRESS, "" + fComboRestoreToThisAddress.getSelection());
|
||||
|
||||
fStartAddress = getStartAddress();
|
||||
fInputFile = getFile();
|
||||
|
@ -94,12 +96,14 @@ public class SRecordImporter implements IMemoryImporter {
|
|||
fComboRestoreToFileAddress = new Button(composite, SWT.RADIO);
|
||||
fComboRestoreToFileAddress.setSelection(true);
|
||||
fComboRestoreToFileAddress.setText("Restore to address specified in the file");
|
||||
fComboRestoreToFileAddress.setSelection(!new Boolean(properties.getProperty(TRANSFER_CUSTOM_START_ADDRESS, "true")).booleanValue());
|
||||
//comboRestoreToFileAddress.setLayoutData(data);
|
||||
|
||||
// restore to this address
|
||||
|
||||
fComboRestoreToThisAddress = new Button(composite, SWT.RADIO);
|
||||
fComboRestoreToThisAddress.setText("Restore to this address: ");
|
||||
fComboRestoreToThisAddress.setSelection(new Boolean(properties.getProperty(TRANSFER_CUSTOM_START_ADDRESS, "true")).booleanValue());
|
||||
FormData data = new FormData();
|
||||
data.top = new FormAttachment(fComboRestoreToFileAddress);
|
||||
fComboRestoreToThisAddress.setLayoutData(data);
|
||||
|
@ -286,6 +290,8 @@ public class SRecordImporter implements IMemoryImporter {
|
|||
{
|
||||
try
|
||||
{
|
||||
BufferedMemoryWriter memoryWriter = new BufferedMemoryWriter((IMemoryBlockExtension) fMemoryBlock, BUFFER_LENGTH);
|
||||
|
||||
// FIXME 4 byte default
|
||||
|
||||
final int CHECKSUM_LENGTH = 1;
|
||||
|
@ -293,7 +299,7 @@ public class SRecordImporter implements IMemoryImporter {
|
|||
BigInteger scrollToAddress = null;
|
||||
|
||||
BigInteger offset = null;
|
||||
if(!fUseCustomAddress)
|
||||
if(!fProperties.getProperty(TRANSFER_CUSTOM_START_ADDRESS, "false").equals("true"))
|
||||
offset = BigInteger.ZERO;
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(fInputFile)));
|
||||
|
@ -372,7 +378,7 @@ public class SRecordImporter implements IMemoryImporter {
|
|||
|
||||
// FIXME error on incorrect checksum
|
||||
|
||||
((IMemoryBlockExtension) fMemoryBlock).setValue(recordAddress.subtract(((IMemoryBlockExtension) fMemoryBlock).getBigBaseAddress()), data);
|
||||
memoryWriter.write(recordAddress.subtract(((IMemoryBlockExtension) fMemoryBlock).getBigBaseAddress()), data);
|
||||
|
||||
jobCount = jobCount.add(BigInteger.valueOf(bytesRead));
|
||||
while(jobCount.compareTo(factor) >= 0)
|
||||
|
@ -384,6 +390,7 @@ public class SRecordImporter implements IMemoryImporter {
|
|||
line = reader.readLine();
|
||||
}
|
||||
|
||||
memoryWriter.flush();
|
||||
reader.close();
|
||||
monitor.done();
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ public interface IMemoryImporter
|
|||
public static final String TRANSFER_FILE = "File";
|
||||
public static final String TRANSFER_START = "Start";
|
||||
public static final String TRANSFER_END = "End";
|
||||
public static final String TRANSFER_CUSTOM_START_ADDRESS = "CustomStartAddress";
|
||||
public static final String TRANSFER_SCROLL_TO_START = "ScrollToStart";
|
||||
|
||||
public Control createControl(Composite parent, IMemoryBlock memBlock, Properties properties, ImportMemoryDialog parentDialog);
|
||||
|
|
Loading…
Add table
Reference in a new issue