Skip to content

Commit

Permalink
SAK-42512 Kernel session attribute tracing (sakaiproject#7356)
Browse files Browse the repository at this point in the history
  • Loading branch information
ern authored and adrianfish committed Sep 24, 2019
1 parent 2c37ca5 commit d25657e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
5 changes: 5 additions & 0 deletions kernel/kernel-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@
<version>3.1.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.carrotsearch</groupId>
<artifactId>java-sizeof</artifactId>
<version>0.0.5</version>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@
import org.sakaiproject.tool.api.SessionStore;
import org.sakaiproject.tool.api.ToolSession;

import com.carrotsearch.sizeof.ObjectTree;
import com.carrotsearch.sizeof.RamUsageEstimator;
import lombok.extern.slf4j.Slf4j;

/**********************************************************************************************************************************************************************************************************************************************************
* Entity: ToolSession, ContextSession (and even HttpSession)
*********************************************************************************************************************************************************************************************************************************************************/

@Slf4j
public class MyLittleSession implements ToolSession, ContextSession, HttpSession, Serializable
{
public static final String TYPE_TOOL = "tool";
Expand Down Expand Up @@ -308,6 +312,32 @@ public void setAttribute(String name, Object value)

else
{
if (log.isDebugEnabled()) {
// DO NOT USE this in a production system as calculating object sizes is very
// CPU intensive and is for debugging only. YOU HAVE BEEN WARNED.
try {
long size = RamUsageEstimator.sizeOf(value);
StringBuilder msg = new StringBuilder("sizeOf [tool context = ");
msg.append(this.m_littleId).append("]");
msg.append(":[").append(name).append(" => ").append(value.getClass().getName()).append("]");
msg.append(" size is ").append(RamUsageEstimator.humanReadableUnits(size));

if (log.isTraceEnabled()) {
// to get a dump of the object tree turn on trace level logging
// don't dump anything over 1MB
if (size <= 1048576 ) {
msg.append(", dumping object tree:\n");
msg.append(ObjectTree.dump(value));
} else {
msg.append(", object is over 1MB skipping dump\n");
}
}
log.debug("{}", msg);
} catch(Exception e) {
log.error("sizeOf could not calculate the size of [toolSession => attribute]:[{} => {}]",this.m_id, name, e);
}
}

Object old = null;

// If this is not a terracotta clustered environment then immediately
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@
import org.sakaiproject.util.RequestFilter;
import org.sakaiproject.util.ResourceLoader;

import com.carrotsearch.sizeof.ObjectTree;
import com.carrotsearch.sizeof.RamUsageEstimator;
import lombok.extern.slf4j.Slf4j;


/*************************************************************************************************************************************************
* Entity: Session Also is an HttpSession
************************************************************************************************************************************************/

@Slf4j
public class MySession implements Session, HttpSession, Serializable
{
/**
Expand Down Expand Up @@ -532,6 +536,32 @@ public void setAttribute(String name, Object value)

else
{
if (log.isDebugEnabled()) {
// DO NOT USE this in a production system as calculating object sizes is very
// CPU intensive and is for debugging only. YOU HAVE BEEN WARNED.
try {
long size = RamUsageEstimator.sizeOf(value);
StringBuilder msg = new StringBuilder("sizeOf [session id = ");
msg.append(this.m_id).append("]");
msg.append(":[").append(name).append(" => ").append(value.getClass().getName()).append("]");
msg.append(" size is ").append(RamUsageEstimator.humanReadableUnits(size));

if (log.isTraceEnabled()) {
// to get a dump of the object tree turn on trace level logging
// don't dump anything over 1MB
if (size <= 1048576 ) {
msg.append(", dumping object tree:\n");
msg.append(ObjectTree.dump(value));
} else {
msg.append(", object is over 1MB skipping dump\n");
}
}
log.debug("{}", msg);
} catch(Exception e) {
log.error("sizeOf could not calculate the size of [session => attribute]:[{} => {}]", this.m_id, name, e);
}
}

Object old = null;

// If this is not a terracotta clustered environment then immediately
Expand Down

0 comments on commit d25657e

Please sign in to comment.