Skip to content

Commit

Permalink
still profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
Anatoli-Grishenko committed Feb 1, 2023
1 parent d4bee0e commit a0c322e
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 69 deletions.
2 changes: 2 additions & 0 deletions src/agents/DroidShip.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ public void setup() {
handleAlias();
}
logger.offSaveDisk();
getMyCPUProfiler().setActive(false);
getMyNetworkProfiler().setActive(false);
// getMyCPUProfiler().setActive(true);
// getMyCPUProfiler().setTsvFileName("./Droidships.tsv");
}
Expand Down
75 changes: 61 additions & 14 deletions src/agents/LARVABaseAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,16 @@ public class LARVABaseAgent extends Agent {
*/
protected String mypassport,
// Remember the name of the Session Manager
mySessionmanager = "", mySessionID="";
mySessionmanager = "", mySessionID = "";

/**
* Counter of cycles of the method Execute()
*/
protected long ncycles;
protected NetworkCookie lastCookie;

protected Profiler MyCPUProfiler, MyNetworkProfiler;
protected boolean isProfiling = false;

/**
* Main constructor
Expand All @@ -133,6 +137,10 @@ public void setup() {
LARVAexit = true;
logger.setOwner(this.getLocalName());
this.BehaviourDefaultSetup();
MyCPUProfiler = new Profiler();
MyCPUProfiler.setOwner(getLocalName());
MyNetworkProfiler = new Profiler();
MyNetworkProfiler.setOwner(getLocalName());
}

@Override
Expand All @@ -152,19 +160,27 @@ public void Execute() {
}

public void preExecute() {
lastCookie = new NetworkCookie();
lastCookie.setOwner(getLocalName());
lastCookie.setSerie((int) getNCycles());

}

public void postExecute() {
lastCookie = null;

}

//
// Messaging
//
protected ACLMessage LARVAprocessAnyMessage(ACLMessage msg) {
if (msg.getUserDefinedParameter(ACLMID) == null) {
msg.addUserDefinedParameter(ACLMID, Keygen.getHexaKey(20));
if (msg != null) {
if (msg.getUserDefinedParameter(ACLMID) == null) {
msg.addUserDefinedParameter(ACLMID, Keygen.getHexaKey(20));
}
msg = ACLMessageTools.secureACLM(msg);
}
msg = ACLMessageTools.secureACLM(msg);
return msg;
}

Expand All @@ -180,12 +196,14 @@ protected ACLMessage LARVAprocessSendMessage(ACLMessage msg) {
}

protected ACLMessage LARVAprocessReceiveMessage(ACLMessage msg) {
if (msg.getUserDefinedParameter(ACLMRCVDATE) == null) {
msg.addUserDefinedParameter(ACLMRCVDATE, "" + new TimeHandler().elapsedTimeSecs());
}
if (msg.getUserDefinedParameter(ACLMROLE) != null && msg.getUserDefinedParameter(ACLMROLE).equals("SESSION MANAGER")) {
this.mySessionmanager=msg.getSender().getLocalName();
this.mySessionID=msg.getConversationId();
if (msg != null) {
if (msg.getUserDefinedParameter(ACLMRCVDATE) == null) {
msg.addUserDefinedParameter(ACLMRCVDATE, "" + new TimeHandler().elapsedTimeSecs());
}
if (msg.getUserDefinedParameter(ACLMROLE) != null && msg.getUserDefinedParameter(ACLMROLE).equals("SESSION MANAGER")) {
this.mySessionmanager = msg.getSender().getLocalName();
this.mySessionID = msg.getConversationId();
}
}
return this.LARVAprocessAnyMessage(msg);
}
Expand Down Expand Up @@ -246,7 +264,6 @@ public ArrayList<String> DFGetAllProvidersOf(String service) {
return res;
}


/**
* It gives the set of services provided by a certain agent, if any.
*
Expand Down Expand Up @@ -325,18 +342,48 @@ public boolean DFRemoveMyServices(String[] services) {
return DFSetMyServices(Transform.toArrayString(prevServices));
}

public Profiler getMyCPUProfiler() {
return MyCPUProfiler;
}

public Profiler getMyNetworkProfiler() {
return MyNetworkProfiler;
}

public void activateMyCPUProfiler(String filename) {
getMyCPUProfiler().setActive(true);
isProfiling = true;
getMyCPUProfiler().setOwner(getLocalName());
getMyCPUProfiler().setTsvFileName(filename + ".tsv");
}

public void activateMyNetworkProfiler(String filename) {
isProfiling = true;
getMyNetworkProfiler().setActive(true);
getMyNetworkProfiler().setOwner(getLocalName());
getMyNetworkProfiler().setTsvFileName(filename + ".tsv");
}

public void deactivateMyCPUProfiler() {
getMyCPUProfiler().setActive(false);
}

public void deactivateMyNetworkProfiler() {
getMyNetworkProfiler().setActive(true);
}

protected ACLMessage LARVAcreateReply(ACLMessage incoming) {
ACLMessage outgoing = incoming.createReply();
outgoing.setSender(getAID());
if (Profiler.isProfiler(incoming)) {
if (Profiler.isProfiler(incoming)
&& (MyCPUProfiler != null && MyCPUProfiler.isActive()
|| MyNetworkProfiler != null && MyNetworkProfiler.isActive())) {
NetworkCookie nc = Profiler.extractProfiler(incoming);
nc.setSerie(nc.getSerie()+1);
Profiler.injectProfiler(outgoing, nc);
}
return outgoing;
}


/**
* It allows the de-registration of all services.
*/
Expand Down
50 changes: 7 additions & 43 deletions src/agents/LARVAFirstAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,38 +157,9 @@ public class LARVAFirstAgent extends LARVABaseAgent implements ActionListener {
usePerformatives = false;
private boolean profiling = false;
protected NetworkData nap;
protected NetworkCookie lastCookie;
protected String netMon = "", myGMap, profileDescription = "", profilingType;
protected Profiler MyCPUProfiler, MyNetworkProfiler;
private ACLMessage message;

public Profiler getMyCPUProfiler() {
return MyCPUProfiler;
}

public Profiler getMyNetworkProfiler() {
return MyNetworkProfiler;
}

public void activateMyCPUProfiler(String filename) {
getMyCPUProfiler().setActive(true);
getMyCPUProfiler().setOwner(getLocalName());
getMyCPUProfiler().setTsvFileName(filename+".tsv");
}

public void activateMyNetworkProfiler(String filename) {
getMyNetworkProfiler().setActive(true);
getMyNetworkProfiler().setOwner(getLocalName());
getMyNetworkProfiler().setTsvFileName(filename+".tsv");
}

public void deactivateMyCPUProfiler() {
getMyCPUProfiler().setActive(false);
}

public void deactivateMyNetworkProfiler() {
getMyNetworkProfiler().setActive(true);
}

protected Choice Ag(Environment E, DecisionSet A) {
if (G(E)) {
Expand Down Expand Up @@ -307,10 +278,6 @@ public void setup() {
this.activateSequenceDiagrams();
this.setContinuousSequenceDiagram(true);
doNotExit();
MyCPUProfiler = new Profiler();
MyCPUProfiler.setOwner(getLocalName());
MyNetworkProfiler = new Profiler();
MyNetworkProfiler.setOwner(getLocalName());
}

public void LARVAwait(int milis) {
Expand Down Expand Up @@ -380,7 +347,7 @@ protected void BehaviourDefaultSetup() {
public void action() {
doShield(() -> {
preExecute();
getMyCPUProfiler().profileThis("BODY", "CYCLE" + getNCycles(),
getMyCPUProfiler().profileThis(""+getNCycles(),
() -> {
Execute();
});
Expand Down Expand Up @@ -427,6 +394,7 @@ public boolean done() {

@Override
public void postExecute() {
super.postExecute();
myReport.tick();
if (this.frameDelay > 0 && (!remote || cont)) {
// LARVAwait(frameDelay);
Expand All @@ -437,6 +405,7 @@ public void postExecute() {

@Override
public void preExecute() {
super.preExecute();
waitRemoteSemaphore();
}

Expand Down Expand Up @@ -809,16 +778,11 @@ protected ACLMessage LARVAprocessSendMessage(ACLMessage msg) {
msg.setReplyWith("MyReport");
}
if (getMyNetworkProfiler().isActive()) {
if (lastCookie == null) {
lastCookie = new NetworkCookie();
}

if (lastCookie.getSize() < 0) {
lastCookie.setSize(msg.getContent().length());
}
// if (lastCookie.getSerie() < 0) {
lastCookie.setSerie((int) getNCycles());
// }
lastCookie.settUpstream(TimeHandler.Now());
lastCookie.settUpstream(TimeHandler.NetNow());
msg = Profiler.injectProfiler(msg, lastCookie);
// System.out.println("SENDING: " + Ole.objectToOle(lastCookie).toPlainJson().toString(WriterConfig.PRETTY_PRINT));
}
Expand All @@ -844,7 +808,7 @@ protected ACLMessage LARVAprocessReceiveMessage(ACLMessage msg) {
this.addSequenceDiagram(msg);

if (Profiler.isProfiler(msg) && getMyNetworkProfiler().isActive()) {
String stime = TimeHandler.Now();
String stime = TimeHandler.NetNow();
lastCookie = Profiler.extractProfiler(msg);
lastCookie.settReceive(stime);
if (ACLMessageTools.isZipped(msg)) {
Expand All @@ -863,7 +827,7 @@ protected ACLMessage LARVAprocessReceiveMessage(ACLMessage msg) {
+ "\tTimeline\t"+lastCookie.gettUpstream();
getMyNetworkProfiler().profileThis(label, label2, () -> {
// System.out.println("RECEIVING: " + Ole.objectToOle(lastCookie).toPlainJson().toString(WriterConfig.PRETTY_PRINT));
System.out.println(label + "" + label2);
// System.out.println(label + "" + label2);

});
}
Expand Down
6 changes: 4 additions & 2 deletions src/agents/XUIAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ public void setup() {
loadSessionAlias();
// Profiling
getMyCPUProfiler().setActive(true);
getMyCPUProfiler().setOwner("XUICPU");
getMyCPUProfiler().setOwner("XUI");
activateMyCPUProfiler("XUI-CPU");
// activateMyNetworkProfiler("XUI-NETWORK");
getMyNetworkProfiler().setActive(true);
getMyNetworkProfiler().setOwner("XUI");
activateMyNetworkProfiler("XUI-NETWORK");

myDashBoard.refProfiler.setOwner("DASHBOARD");
myDashBoard.refProfiler.setTsvFileName("DASHBOARD.tsv");
Expand Down
11 changes: 6 additions & 5 deletions src/profiling/Profiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,16 @@ public void sGo() {
}

public ProfilingTicket tic(String description, String series) {
if (!isActive()) {
// TimeHandler th = new TimeHandler();
if (!isActive()) {
return null;
}
// sWait("tic-"+description+"-"+series);
ProfilingTicket pt = new ProfilingTicket();
pt.setOwner(getOwner());
pt.setDescription(description);
pt.setSeries(series);
pt.setStart(TimeHandler.Now());
pt.setStart(TimeHandler.NetNow());
addTicket(pt);
// Tickets.put(pt.getId(), pt);
// if (!Stack.isEmpty()) {
Expand All @@ -216,13 +217,14 @@ public ProfilingTicket tic(String description) {
}

public ProfilingTicket toc(String description) {
// TimeHandler th = new TimeHandler();
if (!isActive()) {
return null;
}
// sWait("toc-" + description);
ProfilingTicket pt = getTail();
if (pt != null && pt.getDescription().equals(description)) {
pt.setEnd(TimeHandler.Now());
pt.setEnd(TimeHandler.NetNow());
saveTicket(pt);
removeTail();
}
Expand Down Expand Up @@ -394,6 +396,5 @@ public void setSeries(String series) {
getTail().setSeries(series);
}
}



}
Binary file added src/resources/dependencies/commons-net-3.9.0.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/swing/OleDashBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void OleDraw(Graphics2D g) {

// monitorSensors.clear();
// myg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
refProfiler.profileThis("DRAW", "DRAWING", () -> {
refProfiler.profileThis(""+this.myXUIAgent.getNCycles(), "DRAWING", () -> {
doSwingLater(() -> {
for (String s : layoutSensors) {
if (availableDashBoard) {
Expand Down
4 changes: 4 additions & 0 deletions src/tools/NetworkCookie.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ public void setSerie(int serie) {
}

public long getLatencyUp() {
try{
return new TimeHandler(this.gettUpstream()).elapsedTimeMilisecsUntil(new TimeHandler(this.gettArrive()));
} catch(Exception ex) {
return new TimeHandler(this.gettUpstream()).elapsedTimeMilisecsUntil(new TimeHandler(this.gettArrive()));
}
}

public long getLatencyDown() {
Expand Down
Loading

0 comments on commit a0c322e

Please sign in to comment.