Skip to content

Commit 3acf866

Browse files
committed
add cache info in inspect sources for resampled sources
1 parent e882bd3 commit 3acf866

File tree

5 files changed

+148
-1
lines changed

5 files changed

+148
-1
lines changed

.claude/memory.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# File Editing Rules
2+
- Use relative paths only
3+
- Use forward slashes (/) not backslashes (\)
4+
- Navigate to workspace root before any file operations
5+
```
6+
7+
## Alternative 1: Use VS Code Extension
8+
9+
Switch to the VS Code extension for a more stable Windows experience . The VS Code extension has better Windows compatibility than the CLI:
10+
11+
1. Install the Claude Code extension in VS Code
12+
2. Use it instead of the terminal version
13+
3. File editing works much more reliably
14+
15+
## Alternative 2: Use Java for File Edits
16+
17+
If you need Claude to make Java-based file edits, instruct it like this:
18+
```
19+
When editing files, use a Java snippet via bash:
20+
java -cp . -c 'String content = Files.readString(Path.of("file.java"));
21+
content = content.replace("old", "new");
22+
Files.writeString(Path.of("file.java"), content);'
23+
```
24+
25+
Or use Windows batch commands:
26+
```
27+
For file edits, use PowerShell commands:
28+
(Get-Content file.java) -replace 'old', 'new' | Set-Content file.java

src/main/java/sc/fiji/bdvpg/cache/AbstractGlobalCache.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,23 @@ public String getSizeInKB() {
171171
}
172172

173173
/**
174-
* Get cache statistics for a specific source and timepoint.
174+
* Get cache statistics for a specific source and timepoint (for SpimData sources).
175175
*
176176
* @param source the source object
177+
* @param setupId the setup ID
177178
* @param timepoint the timepoint (-1 for all timepoints)
178179
* @return cache statistics
179180
*/
180181
abstract public CacheStats getCacheStats(Object source, int setupId, int timepoint);
181182

183+
/**
184+
* Get cache statistics for a specific source and timepoint (for non-SpimData sources).
185+
* This version doesn't filter by setupId.
186+
*
187+
* @param source the source object
188+
* @param timepoint the timepoint (-1 for all timepoints)
189+
* @return cache statistics
190+
*/
191+
abstract public CacheStats getCacheStats(Object source, int timepoint);
192+
182193
}

src/main/java/sc/fiji/bdvpg/cache/BoundedLinkedHashMapGlobalCache.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,4 +247,40 @@ public CacheStats getCacheStats(Object source, int setupid, int timepoint) {
247247
}
248248
}
249249

250+
@Override
251+
public CacheStats getCacheStats(Object source, int timepoint) {
252+
long totalSize = 0;
253+
long cellCount = 0;
254+
255+
synchronized (cache) {
256+
for (Map.Entry<GlobalCacheKey, SoftReference<Object>> entry : cache
257+
.entrySet())
258+
{
259+
GlobalCacheKey key = entry.getKey();
260+
if (timepoint == -1) {
261+
// Match source for any timepoint
262+
if (key.getSource() == source) {
263+
Long cost = cache.cost.get(key);
264+
if (cost != null) {
265+
totalSize += cost;
266+
cellCount++;
267+
}
268+
}
269+
}
270+
else {
271+
// Match source and specific timepoint (any level)
272+
if (key.getSource() == source && key.getTimepoint() == timepoint) {
273+
Long cost = cache.cost.get(key);
274+
if (cost != null) {
275+
totalSize += cost;
276+
cellCount++;
277+
}
278+
}
279+
}
280+
}
281+
}
282+
283+
return new CacheStats(cellCount, totalSize);
284+
}
285+
250286
}

src/main/java/sc/fiji/bdvpg/cache/CaffeineGlobalCache.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,5 +183,37 @@ public CacheStats getCacheStats(Object source, int setupid, int timepoint) {
183183
return new CacheStats(0, 0);
184184
}
185185
}
186+
@Override
187+
public CacheStats getCacheStats(Object source, int timepoint) {
188+
long totalSize = 0;
189+
long cellCount = 0;
190+
191+
for (GlobalCacheKey key : cache.asMap().keySet()) {
192+
if (timepoint == -1) {
193+
// Match source for any timepoint
194+
if (key.getSource() == source) {
195+
Object value = cache.getIfPresent(key);
196+
if (value != null) {
197+
totalSize += getWeight(value);
198+
cellCount++;
199+
}
200+
}
201+
}
202+
else {
203+
// Match source and specific timepoint (any level)
204+
if (key.getSource() == source && key.getTimepoint() == timepoint) {
205+
Object value = cache.getIfPresent(key);
206+
if (value != null) {
207+
totalSize += getWeight(value);
208+
cellCount++;
209+
}
210+
}
211+
}
212+
}
213+
214+
return new CacheStats(cellCount, totalSize);
215+
}
216+
186217

187218
}
219+

src/main/java/sc/fiji/bdvpg/scijava/services/ui/SourceAndConverterInspector.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,46 @@ public String toString() {
277277
subSources.addAll(appendInspectorResult(wrappedSourceNode, src,
278278
sourceAndConverterService, registerIntermediateSources));
279279
}
280+
281+
// Add cache statistics for ResampledSource
282+
try {
283+
AbstractGlobalCache globalCache = SourceAndConverterServices
284+
.getSourceAndConverterService().getCache();
285+
if (globalCache != null) {
286+
DefaultMutableTreeNode cacheNode = new DefaultMutableTreeNode(
287+
"Cache Statistics");
288+
nodeResampledSource.add(cacheNode);
289+
290+
// Get cache stats for all timepoints
291+
AbstractGlobalCache.CacheStats allStats = globalCache.getCacheStats(
292+
source, -1);
293+
if (allStats.numberOfCells > 0) {
294+
cacheNode.add(new DefaultMutableTreeNode("All timepoints: " +
295+
allStats.numberOfCells + " cells, " + allStats.getSizeInMB() +
296+
" MB"));
297+
298+
// Also show per-timepoint breakdown if there are not too many
299+
// timepoints
300+
int numTimepoints = SourceAndConverterHelper.getMaxTimepoint(source)+1;
301+
for (int t = 0; t < numTimepoints; t++) {
302+
AbstractGlobalCache.CacheStats tpStats = globalCache
303+
.getCacheStats(source, t);
304+
if (tpStats.numberOfCells > 0) {
305+
cacheNode.add(new DefaultMutableTreeNode("Timepoint " + t +
306+
": " + tpStats.numberOfCells + " cells, " + tpStats
307+
.getSizeInMB() + " MB"));
308+
}
309+
}
310+
}
311+
else {
312+
cacheNode.add(new DefaultMutableTreeNode("No data in cache"));
313+
}
314+
}
315+
}
316+
catch (Exception e) {
317+
logger.debug("Could not get cache stats for ResampledSource: " + e
318+
.getMessage());
319+
}
280320
appendMetadata(nodeResampledSource, sac);
281321
}
282322

0 commit comments

Comments
 (0)