Skip to content

Enable the reading performance profiling #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright (C) 2015 Turn Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package datamine.storage.idl.validate.exceptions;

/**
* @author yqi
*/
public class TableUndefinedException extends AbstractValidationException {

private static final long serialVersionUID = 3812117802751276493L;
private static final String MSG_PATTERN =
"Cannot find the table definition: %s!";

public TableUndefinedException(String tableName) {
super(String.format(MSG_PATTERN, tableName));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ private int getOffset(T col) {
@Override
public Object getValue(T col) {

long ts = 0;
if (IS_DEBUG_ENABLED) {
if (recursionLevel == 0) {
ts = System.currentTimeMillis();
}
recursionLevel++;
}

Field field = col.getField();
FieldType type = field.getType();
FieldValueOperatorInterface valueOpr = FieldValueOperatorFactory.getOperator(type);
Expand All @@ -131,6 +139,13 @@ public Object getValue(T col) {
result = valueOpr.getValue(buf, offset + 4, buf.getInt(offset));
}

if (IS_DEBUG_ENABLED) {
recursionLevel--;
if (recursionLevel == 0) {
readingTimeCostMiliSeconds += System.currentTimeMillis() - ts;
}
}

// never return NULL
if (result == null) {
return col.getField().getDefaultValue();
Expand All @@ -140,97 +155,260 @@ public Object getValue(T col) {
}

public boolean getBool(T col) {

long ts = 0;
if (IS_DEBUG_ENABLED) {
if (recursionLevel == 0) {
ts = System.currentTimeMillis();
}
recursionLevel++;
}

int offset = getOffset(col);
boolean result;
if (offset > 0) {
return buffer.getByteBuffer().get(offset) == 1 ? true : false;
result = buffer.getByteBuffer().get(offset) == 1 ? true : false;
} else {
return (Boolean) col.getField().getDefaultValue();
result = (Boolean) col.getField().getDefaultValue();
}

if (IS_DEBUG_ENABLED) {
recursionLevel--;
if (recursionLevel == 0) {
readingTimeCostMiliSeconds += System.currentTimeMillis() - ts;
}
}

return result;
}


public byte getByte(T col) {
long ts = 0;
if (IS_DEBUG_ENABLED) {
if (recursionLevel == 0) {
ts = System.currentTimeMillis();
}
recursionLevel++;
}

int offset = getOffset(col);
byte result;
if (offset > 0) {
return buffer.getByteBuffer().get(offset);
result = buffer.getByteBuffer().get(offset);
} else {
return (Byte) col.getField().getDefaultValue();
result = (Byte) col.getField().getDefaultValue();
}

if (IS_DEBUG_ENABLED) {
recursionLevel--;
if (recursionLevel == 0) {
readingTimeCostMiliSeconds += System.currentTimeMillis() - ts;
}
}

return result;
}


public short getShort(T col) {
long ts = 0;
if (IS_DEBUG_ENABLED) {
if (recursionLevel == 0) {
ts = System.currentTimeMillis();
}
recursionLevel++;
}

int offset = getOffset(col);
short result;
if (offset > 0) {
return buffer.getByteBuffer().getShort(offset);
result = buffer.getByteBuffer().getShort(offset);
} else {
return (Short) col.getField().getDefaultValue();
result = (Short) col.getField().getDefaultValue();
}

if (IS_DEBUG_ENABLED) {
recursionLevel--;
if (recursionLevel == 0) {
readingTimeCostMiliSeconds += System.currentTimeMillis() - ts;
}
}

return result;
}


public long getLong(T col) {
long ts = 0;
if (IS_DEBUG_ENABLED) {
if (recursionLevel == 0) {
ts = System.currentTimeMillis();
}
recursionLevel++;
}

int offset = getOffset(col);
long result;
if (offset > 0) {
return buffer.getByteBuffer().getLong(offset);
result = buffer.getByteBuffer().getLong(offset);
} else {
return (Long) col.getField().getDefaultValue();
result = (Long) col.getField().getDefaultValue();
}

if (IS_DEBUG_ENABLED) {
recursionLevel--;
if (recursionLevel == 0) {
readingTimeCostMiliSeconds += System.currentTimeMillis() - ts;
}
}

return result;
}


public int getInt(T col) {
long ts = 0;
if (IS_DEBUG_ENABLED) {
if (recursionLevel == 0) {
ts = System.currentTimeMillis();
}
recursionLevel++;
}

int offset = getOffset(col);
int result;
if (offset > 0) {
return buffer.getByteBuffer().getInt(offset);
result = buffer.getByteBuffer().getInt(offset);
} else {
return (Integer) col.getField().getDefaultValue();
result = (Integer) col.getField().getDefaultValue();
}

if (IS_DEBUG_ENABLED) {
recursionLevel--;
if (recursionLevel == 0) {
readingTimeCostMiliSeconds += System.currentTimeMillis() - ts;
}
}

return result;
}


public float getFloat(T col) {
long ts = 0;
if (IS_DEBUG_ENABLED) {
if (recursionLevel == 0) {
ts = System.currentTimeMillis();
}
recursionLevel++;
}

int offset = getOffset(col);
float result;
if (offset > 0) {
return buffer.getByteBuffer().getFloat(offset);
result = buffer.getByteBuffer().getFloat(offset);
} else {
return (Float) col.getField().getDefaultValue();
result = (Float) col.getField().getDefaultValue();
}

if (IS_DEBUG_ENABLED) {
recursionLevel--;
if (recursionLevel == 0) {
readingTimeCostMiliSeconds += System.currentTimeMillis() - ts;
}
}

return result;
}


public double getDouble(T col) {
long ts = 0;
if (IS_DEBUG_ENABLED) {
if (recursionLevel == 0) {
ts = System.currentTimeMillis();
}
recursionLevel++;
}

int offset = getOffset(col);
double result;
if (offset > 0) {
return buffer.getByteBuffer().getDouble(offset);
result = buffer.getByteBuffer().getDouble(offset);
} else {
return (Double) col.getField().getDefaultValue();
result = (Double) col.getField().getDefaultValue();
}

if (IS_DEBUG_ENABLED) {
recursionLevel--;
if (recursionLevel == 0) {
readingTimeCostMiliSeconds += System.currentTimeMillis() - ts;
}
}

return result;
}


public byte[] getBinary(T col) {
long ts = 0;
if (IS_DEBUG_ENABLED) {
if (recursionLevel == 0) {
ts = System.currentTimeMillis();
}
recursionLevel++;
}

int offset = getOffset(col);
byte[] result;
if (offset > 0) {
int length = buffer.getByteBuffer().getInt(offset);
byte[] out = new byte[length];
byte[] src = buffer.getByteBuffer().array();
System.arraycopy(src, offset + 4, out, 0, length);
return out;
result = out;
} else {
return (byte[]) col.getField().getDefaultValue();
result = (byte[]) col.getField().getDefaultValue();
}

if (IS_DEBUG_ENABLED) {
recursionLevel--;
if (recursionLevel == 0) {
readingTimeCostMiliSeconds += System.currentTimeMillis() - ts;
}
}

return result;
}


public String getString(T col) {
long ts = 0;
if (IS_DEBUG_ENABLED) {
if (recursionLevel == 0) {
ts = System.currentTimeMillis();
}
recursionLevel++;
}

int offset = getOffset(col);
String result;
if (offset > 0) {
int length = buffer.getByteBuffer().getShort(offset);
return new String(buffer.getByteBuffer().array(), offset + 2, length);
result = new String(buffer.getByteBuffer().array(), offset + 2, length);
} else {
return (String) col.getField().getDefaultValue();
result = (String) col.getField().getDefaultValue();
}

if (IS_DEBUG_ENABLED) {
recursionLevel--;
if (recursionLevel == 0) {
readingTimeCostMiliSeconds += System.currentTimeMillis() - ts;
}
}

return result;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,25 @@
* @author yqi
*/
public abstract class Record<T extends Enum<T> & RecordMetadataInterface> {


/**
* Static members for the performance profiling
*/
protected static final boolean IS_DEBUG_ENABLED = true;
protected static int recursionLevel = 0;
protected static long readingTimeCostMiliSeconds = 0;

public static void clearTimeCostCounter() {
if (IS_DEBUG_ENABLED) {
recursionLevel = 0;
readingTimeCostMiliSeconds = 0;
}
}

public static long getTimeCostInMilliSecond() {
return readingTimeCostMiliSeconds;
}

/**
* The storage metadata about the recordbuffer is final
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ public void setValue(T col, Object val) {
@Override
public Object getValue(T col) {

long ts = 0;
if (IS_DEBUG_ENABLED) {
if (recursionLevel == 0) {
ts = System.currentTimeMillis();
}
recursionLevel++;
}

if (valueArray == null && readOnlyRecord == null && buffer != null) {
readOnlyRecord = new ReadOnlyRecord<T>(meta.getTableEnumClass(), buffer);
}
Expand All @@ -137,6 +145,14 @@ public Object getValue(T col) {
Field field = col.getField();
int id = field.getId() - 1; // note that id starts at 1.
Object result = valueArray != null && valueArray.length > id ? valueArray[id] : null;

if (IS_DEBUG_ENABLED) {
recursionLevel--;
if (recursionLevel == 0) {
readingTimeCostMiliSeconds += System.currentTimeMillis() - ts;
}
}

if (result == null) { // never return NULL
return col.getField().getDefaultValue();
} else {
Expand Down