Skip to content

Commit

Permalink
Merge pull request #662 from darkv/erprofiling_enhancements
Browse files Browse the repository at this point in the history
Enhancements for ERProfiling
  • Loading branch information
darkv committed Jul 22, 2015
2 parents 3bde6de + 9f4a75b commit 0f57e65
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,19 @@ protected void appendHeatStyles(PFStatsNode stats, WOResponse response, WOContex
}
if ("appendToResponse".equals(stats.name())) {
double fValue = stats.percentage();
int r = 0;
int g = 0;
int r = 255;
int g = (int) (255 * (1.0 - fValue * fValue));
int b = 0;
int a = 1;
if (fValue <= 0.01) {
// r = 255;
// g = 255;
// b = 255;
// response.appendContentString(".wo_p_" +
// duration.getKey() + " { background-color: rgba(" + r
// + "," + g + "," + b + "," + a + ") !important; }\n");
} else {
int value = (int) (255 * (1.0 - fValue * fValue));
r = 255;
g = value;
b = 0;
response.appendContentString("." + stats.cssID() + " { !important; border: 3px solid rgba(" + r + "," + g + "," + b + "," + a + ") !important; }\n");
int w = 1;
if (fValue > 0.75) {
w = 4;
} else if (fValue > 0.4) {
w = 3;
} else if (fValue > 0.1) {
w = 2;
}
response.appendContentString("." + stats.cssID() + " { outline: " + w + "px solid rgb(" + r
+ "," + g + "," + b + ") !important; outline-offset: -" + w + "px !important }\n");
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.List;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

import com.webobjects.appserver.WOContext;
import com.webobjects.appserver.WOElement;
import com.webobjects.appserver.WOMessage;
Expand Down Expand Up @@ -137,41 +139,35 @@ public void didAppendToResponse(WOElement element, WOResponse response, WOContex
for (int i = startIndex; i < endIndex; i++) {
char ch = contentStr.charAt(i);
if (ch == '<') {
if (i < endIndex - 1 && contentStr.charAt(i + 1) != '/') {
if (i < endIndex - 1 && contentStr.charAt(i + 1) != '/' && contentStr.charAt(i + 1) != '!') {
tagIndex = i;
break;
}
}
}

if (tagIndex != -1) {
int attributeOffset = -1;
boolean spacesFound = false;
for (int i = tagIndex; i < endIndex; i++) {
char ch = contentStr.charAt(i);
if (ch == ' ') {
spacesFound = true;
} else if (ch == '>' || ch == '/') {
if (attributeOffset > tagIndex + 1) {
attributeOffset = i;
}
break;
} else if (spacesFound) {
attributeOffset = i;
break;
}
}
if (attributeOffset != -1) {
String profilerID = markerStats._stats.cssID();
String profilerIDAttributeName = "class";
if (regionMatches(contentStr, attributeOffset, profilerIDAttributeName, 0, profilerIDAttributeName.length())) {
int openQuoteIndex = indexOf(contentStr, "\"", attributeOffset);
if (openQuoteIndex != -1) {
insert(contentStr, openQuoteIndex + 1, profilerID + " ");
}
String profilerIDAttributeName = "class";
String profilerIDAttributeStart = " " + profilerIDAttributeName + "=\"";
boolean foundClassAttribute = false;
int closeOffset = StringUtils.indexOf(contentStr, '>', tagIndex);
int attributeOffset = StringUtils.indexOf(contentStr, profilerIDAttributeName, tagIndex);
if (attributeOffset == -1 || attributeOffset > closeOffset) {
char ch = contentStr.charAt(closeOffset - 1);
if (ch == '/') {
attributeOffset = closeOffset - 1;
} else {
insert(contentStr, attributeOffset, " " + profilerIDAttributeName + "=\"" + profilerID + "\" ");
attributeOffset = closeOffset;
}
} else {
attributeOffset += profilerIDAttributeStart.length() -1;
foundClassAttribute = true;
}
String profilerID = markerStats._stats.cssID();
if (foundClassAttribute) {
insert(contentStr, attributeOffset, profilerID + " ");
} else {
insert(contentStr, attributeOffset, profilerIDAttributeStart + profilerID + "\"");
}
}
}
Expand Down

0 comments on commit 0f57e65

Please sign in to comment.