-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1043 from soot-oss/1035-feature-get-performance-o…
…f-bodyinterceptors-runtime-and-memory-consumption runtime & memory usage to body interceptors
- Loading branch information
Showing
3 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
sootup.core/src/main/java/sootup/core/transform/BodyInterceptorMetric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package sootup.core.transform; | ||
|
||
/*- | ||
* #%L | ||
* Soot - a J*va Optimization Framework | ||
* %% | ||
* Copyright (C) 2024 Sahil Agichani | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation, either version 2.1 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Lesser Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Lesser Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
* #L% | ||
*/ | ||
|
||
public class BodyInterceptorMetric { | ||
|
||
private long runtime; | ||
private long memoryUsage; | ||
|
||
public BodyInterceptorMetric(long runtime, long memoryUsage) { | ||
this.runtime = runtime; | ||
this.memoryUsage = memoryUsage; | ||
} | ||
|
||
public long getRuntime() { | ||
return runtime; | ||
} | ||
|
||
public void setRuntime(long runtime) { | ||
this.runtime = runtime; | ||
} | ||
|
||
public long getMemoryUsage() { | ||
return memoryUsage; | ||
} | ||
|
||
public void setMemoryUsage(long memoryUsage) { | ||
this.memoryUsage = memoryUsage; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
sootup.core/src/main/java/sootup/core/transform/RunTimeBodyInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package sootup.core.transform; | ||
|
||
/*- | ||
* #%L | ||
* Soot - a J*va Optimization Framework | ||
* %% | ||
* Copyright (C) 2024 Sahil Agichani | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation, either version 2.1 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Lesser Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Lesser Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
* #L% | ||
*/ | ||
|
||
import javax.annotation.Nonnull; | ||
import sootup.core.model.Body; | ||
import sootup.core.views.View; | ||
|
||
public class RunTimeBodyInterceptor implements BodyInterceptor { | ||
|
||
private BodyInterceptorMetric biMetric = new BodyInterceptorMetric(0L, 0L); | ||
|
||
private final BodyInterceptor bodyInterceptor; | ||
|
||
public RunTimeBodyInterceptor(BodyInterceptor bodyInterceptor) { | ||
this.bodyInterceptor = bodyInterceptor; | ||
} | ||
|
||
public BodyInterceptorMetric getBiMetric() { | ||
return biMetric; | ||
} | ||
|
||
public BodyInterceptor getBodyInterceptor() { | ||
return bodyInterceptor; | ||
} | ||
|
||
@Override | ||
public void interceptBody(@Nonnull Body.BodyBuilder builder, @Nonnull View view) { | ||
long startTime = System.currentTimeMillis(); // Start time | ||
final int MB = 1024 * 1024; | ||
Runtime runtime = Runtime.getRuntime(); | ||
long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory(); | ||
|
||
bodyInterceptor.interceptBody(builder, view); | ||
|
||
long endTime = System.currentTimeMillis(); // End time | ||
long duration = endTime - startTime; | ||
long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory(); | ||
long memoryUsed = (usedMemoryAfter - usedMemoryBefore) / MB; | ||
|
||
biMetric.setRuntime(biMetric.getRuntime() + duration); | ||
biMetric.setMemoryUsage(biMetric.getMemoryUsage() + memoryUsed); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters