File: memusage.bsh

package info (click to toggle)
libreoffice 1%3A3.5.4%2Bdfsg2-0%2Bdeb7u3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,691,616 kB
  • sloc: cpp: 4,678,856; java: 395,153; xml: 170,215; ansic: 99,333; perl: 60,572; python: 27,776; sh: 17,789; makefile: 8,738; yacc: 8,219; cs: 6,648; asm: 3,257; objc: 2,349; lex: 2,103; pascal: 890; awk: 758; csh: 247; lisp: 115; php: 104; sed: 9
file content (120 lines) | stat: -rwxr-xr-x 3,786 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.Type;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.document.XEmbeddedObjectSupplier;
import com.sun.star.awt.ActionEvent;
import com.sun.star.awt.Rectangle;
import com.sun.star.beans.XPropertySet;
import com.sun.star.beans.PropertyValue;

import com.sun.star.container.*;
import com.sun.star.chart.*;
import com.sun.star.table.*;
import com.sun.star.sheet.*;

import com.sun.star.script.provider.XScriptContext;

createSpreadsheet()
{
    loader = (XComponentLoader)
        UnoRuntime.queryInterface(
            XComponentLoader.class, XSCRIPTCONTEXT.getDesktop());

    comp = loader.loadComponentFromURL(
        "private:factory/scalc", "_blank", 4, new PropertyValue[0]);

    doc = (XSpreadsheetDocument)
        UnoRuntime.queryInterface(XSpreadsheetDocument.class, comp);

    index = (XIndexAccess)
        UnoRuntime.queryInterface(XIndexAccess.class, doc.getSheets());

    sheet = (XSpreadsheet) AnyConverter.toObject(
        new Type(com.sun.star.sheet.XSpreadsheet.class), index.getByIndex(0));

    return sheet;
}

addData(sheet, date, total, free)
{
    // set the labels
    sheet.getCellByPosition(0, 0).setFormula("Used");
    sheet.getCellByPosition(0, 1).setFormula("Free");
    sheet.getCellByPosition(0, 2).setFormula("Total");

    // set the values in the cells
    sheet.getCellByPosition(1, 0).setValue(total - free);
    sheet.getCellByPosition(1, 1).setValue(free);
    sheet.getCellByPosition(1, 2).setValue(total);
}

addChart(sheet)
{
    rect = new Rectangle();
    rect.X = 500;
    rect.Y = 3000;
    rect.Width = 10000;
    rect.Height = 8000;

    range = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, sheet);
    myRange = range.getCellRangeByName("A1:B2");

    rangeAddr = (XCellRangeAddressable)
        UnoRuntime.queryInterface(XCellRangeAddressable.class, myRange);

    myAddr = rangeAddr.getRangeAddress();

    CellRangeAddress[] addr = new CellRangeAddress[1];
    addr[0] = myAddr;

    supp = (XTableChartsSupplier)
        UnoRuntime.queryInterface( XTableChartsSupplier.class, sheet);
    charts = supp.getCharts();
    charts.addNewByName("Example", rect, addr, false, true);

    try { Thread.sleep(3000); } catch (java.lang.InterruptedException e) { }

    // get the diagram and Change some of the properties
    chartsAccess = (XNameAccess)
        UnoRuntime.queryInterface( XNameAccess.class, charts);

    tchart = (XTableChart)
        UnoRuntime.queryInterface(
            XTableChart.class, chartsAccess.getByName("Example"));

    eos = (XEmbeddedObjectSupplier)
        UnoRuntime.queryInterface( XEmbeddedObjectSupplier.class, tchart );
    xifc = eos.getEmbeddedObject();

    xChart = (XChartDocument)
        UnoRuntime.queryInterface(XChartDocument.class, xifc);

    xDocMSF = (XMultiServiceFactory)
        UnoRuntime.queryInterface(XMultiServiceFactory.class, xChart);

    diagObject = xDocMSF.createInstance("com.sun.star.chart.PieDiagram");
    xDiagram = (XDiagram)
        UnoRuntime.queryInterface(XDiagram.class, diagObject);
    xChart.setDiagram(xDiagram);

    propset = (XPropertySet)
        UnoRuntime.queryInterface( XPropertySet.class, xChart.getTitle() );
    propset.setPropertyValue("String", "JVM Memory Usage");
}

runtime = Runtime.getRuntime();
generator = new Random();
date = new Date();

// allocate a random number of bytes so that the data changes
len = (int)(generator.nextFloat() * runtime.freeMemory() / 5);
bytes = new byte[len];

sheet = createSpreadsheet();
addData(sheet, date.toString(), runtime.totalMemory(), runtime.freeMemory());
addChart(sheet);

return 0;