mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
Include test for memory leak with set bg image. Update pefr tests.
This commit is contained in:
@ -11,6 +11,7 @@ export function pageLoaded(args: EventData) {
|
||||
|
||||
let examples: Map<string, string> = new Map<string, string>();
|
||||
examples.set("properties", "perf/properties/main-page");
|
||||
examples.set("memory-leaks", "perf/memory-leaks/main-page");
|
||||
|
||||
let viewModel = new SubMainPageViewModel(wrapLayout, examples);
|
||||
page.bindingContext = viewModel;
|
||||
|
15
apps/app/ui-tests-app/perf/memory-leaks/background-image.css
Normal file
15
apps/app/ui-tests-app/perf/memory-leaks/background-image.css
Normal file
@ -0,0 +1,15 @@
|
||||
/*.bg-main-page{
|
||||
background-image: url('~/ui-tests-app/image-view/gravatar.png');
|
||||
}*/
|
||||
|
||||
/*.image {
|
||||
width:100;
|
||||
height:100;
|
||||
background-image: url('~/ui-tests-app/image-view/gravatar.png');
|
||||
clip-path: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%);
|
||||
}*/
|
||||
|
||||
|
||||
.info {
|
||||
font-size: 20;
|
||||
}
|
46
apps/app/ui-tests-app/perf/memory-leaks/background-image.ts
Normal file
46
apps/app/ui-tests-app/perf/memory-leaks/background-image.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import * as frame from "tns-core-modules/ui/frame";
|
||||
import { EventData } from "tns-core-modules/data/observable";
|
||||
import { Page } from "tns-core-modules/ui/page";
|
||||
import { Label } from "tns-core-modules/ui/label";
|
||||
import * as application from "tns-core-modules/application";
|
||||
|
||||
var indexCounter = 0;
|
||||
var navCounter = 0;
|
||||
var images = ["gravatar", "gravatar2", "red"];
|
||||
|
||||
export function onLoad(args: EventData) {
|
||||
let index = indexCounter++ % 3;
|
||||
let page = <Page>args.object;
|
||||
page.backgroundImage = '~/ui-tests-app/image-view/' + images[index] + '.png';
|
||||
setLabelText(args.object.page, navCounter, "countInfo");
|
||||
getMemoryUsage(args);
|
||||
}
|
||||
|
||||
export function navigate(args: EventData) {
|
||||
navCounter++;
|
||||
frame.topmost().navigate("ui-tests-app/perf/memory-leaks/background-image");
|
||||
}
|
||||
|
||||
export function navigateBack(args: EventData) {
|
||||
navCounter--;
|
||||
frame.topmost().goBack();
|
||||
}
|
||||
|
||||
function setLabelText(page: Page, text: number, id: string) {
|
||||
let label = page.getViewById(id);
|
||||
label.text = text + '';
|
||||
}
|
||||
|
||||
function getMemoryUsage(args: EventData) {
|
||||
var mi = new android.app.ActivityManager.MemoryInfo();
|
||||
var activityManager = application.android.context.getSystemService(android.content.Context.ACTIVITY_SERVICE);
|
||||
activityManager.getMemoryInfo(mi);
|
||||
let usedMemory = mi.totalMem - mi.availMem;
|
||||
|
||||
setLabelText(args.object, usedMemory, "usedMemory");
|
||||
|
||||
console.log("availMem in bytes: " + mi.availMem);
|
||||
console.log("Percentage usage: " + (mi.availMem / mi.totalMem));
|
||||
console.log("Available memory (megabytes): " + mi.availMem);
|
||||
console.log("Used memory (megabytes): " + usedMemory);
|
||||
}
|
20
apps/app/ui-tests-app/perf/memory-leaks/background-image.xml
Normal file
20
apps/app/ui-tests-app/perf/memory-leaks/background-image.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<Page navigatingTo="onLoad" class="bg-main-page">
|
||||
<Page.actionBar>
|
||||
<ActionBar title="">
|
||||
<NavigationButton text="go back"/>
|
||||
<ActionBar.actionItems>
|
||||
<ActionItem text="back" tap="navigateBack"/>
|
||||
<ActionItem text="forward" tap="navigate"/>
|
||||
</ActionBar.actionItems>
|
||||
</ActionBar>
|
||||
</Page.actionBar>
|
||||
<GridLayout rows="*, *, *" columns="*, *" class="info">
|
||||
<!--<Image class="image" />-->
|
||||
<Button tap="getMemoryUsage" text="Get memory info" height="60" colSpan="2"/>
|
||||
<Label text="navigation counter" row="1" />
|
||||
<Label text="navigation counter" id="countInfo" row="1" col="1" />
|
||||
<Label text="used memory" row="2" />
|
||||
<Label text="" id="usedMemory" row="2" col="1" />
|
||||
</GridLayout>
|
||||
</Page>
|
23
apps/app/ui-tests-app/perf/memory-leaks/main-page.ts
Normal file
23
apps/app/ui-tests-app/perf/memory-leaks/main-page.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { EventData } from "tns-core-modules/data/observable";
|
||||
import { MainPageViewModel } from "../../mainPage";
|
||||
import { WrapLayout } from "tns-core-modules/ui/layouts/wrap-layout";
|
||||
import { Page } from "tns-core-modules/ui/page";
|
||||
|
||||
export function pageLoaded(args: EventData) {
|
||||
let page = <Page>args.object;
|
||||
let view = require("ui/core/view");
|
||||
|
||||
let wrapLayout = view.getViewById(page, "wrapLayoutWithExamples");
|
||||
|
||||
let examples: Map<string, string> = new Map<string, string>();
|
||||
examples.set("background-image", "perf/memory-leaks/background-image");
|
||||
|
||||
let viewModel = new SubMainPageViewModel(wrapLayout, examples);
|
||||
page.bindingContext = viewModel;
|
||||
}
|
||||
|
||||
export class SubMainPageViewModel extends MainPageViewModel {
|
||||
constructor(container: WrapLayout, examples: Map<string, string>) {
|
||||
super(container, examples);
|
||||
}
|
||||
}
|
6
apps/app/ui-tests-app/perf/memory-leaks/main-page.xml
Normal file
6
apps/app/ui-tests-app/perf/memory-leaks/main-page.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<Page loaded="pageLoaded">
|
||||
<ScrollView orientation="vertical">
|
||||
<WrapLayout id="wrapLayoutWithExamples"/>
|
||||
</ScrollView>
|
||||
</Page>
|
@ -30,6 +30,7 @@ export function onTap3(args) {
|
||||
|
||||
function track(line: string) {
|
||||
console.log(line);
|
||||
result.fontSize = 10;
|
||||
result.text += line + "\n";
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingFrom="onNavigatingFrom">
|
||||
<GridLayout rows="auto, *">
|
||||
<StackLayout id="placeholder" rowSpan="2" opacity="0.2" />
|
||||
<Button text="Start test..." tap="onTap3"/>
|
||||
<TextView id="result" row="1" />
|
||||
<GridLayout rows="30,100,*">
|
||||
<Button text="Start test..." tap="onTap3" style="font-size:8" />
|
||||
<StackLayout id="placeholder" row="1"/>
|
||||
<TextView id="result" row="2" />
|
||||
</GridLayout>
|
||||
</Page>
|
@ -21,7 +21,7 @@ export function addRemove(counts: Array<number>, parent: LayoutBase): string {
|
||||
}
|
||||
});
|
||||
|
||||
result += `\t${time}`;
|
||||
result += setResultTime(time);
|
||||
});
|
||||
|
||||
return result;
|
||||
@ -36,7 +36,7 @@ export function setText(counts: Array<number>, parent?: LayoutBase): string {
|
||||
lbl.text = colors[i % 2];
|
||||
}
|
||||
});
|
||||
result += `\t${time}`;
|
||||
result += setResultTime(time);
|
||||
});
|
||||
|
||||
return result;
|
||||
@ -56,7 +56,7 @@ export function setBackgroundColor(counts: Array<number>, parent?: LayoutBase):
|
||||
style.backgroundColor = <any>colors[i % 2];
|
||||
}
|
||||
});
|
||||
result += `\t${time}`;
|
||||
result += setResultTime(time);
|
||||
});
|
||||
|
||||
return result;
|
||||
@ -80,7 +80,7 @@ export function setBorderWidths(counts: Array<number>, parent?: LayoutBase): str
|
||||
style.borderBottomWidth = borders[i % 3];
|
||||
}
|
||||
});
|
||||
result += `\t${time}`;
|
||||
result += setResultTime(time);
|
||||
});
|
||||
|
||||
return result;
|
||||
@ -96,7 +96,7 @@ export function setColor(counts: Array<number>, parent?: LayoutBase): string {
|
||||
style.color = <any>colors[i % 2];
|
||||
}
|
||||
});
|
||||
result += `\t${time}`;
|
||||
result += setResultTime(time);
|
||||
});
|
||||
|
||||
return result;
|
||||
@ -116,7 +116,7 @@ export function setColorWithParents(counts: Array<number>, parent: LayoutBase):
|
||||
style.color = <any>colors[i % 2];
|
||||
}
|
||||
});
|
||||
result += `\t${time}`;
|
||||
result += setResultTime(time);
|
||||
});
|
||||
|
||||
return result;
|
||||
@ -133,7 +133,7 @@ export function setFontSize(counts: Array<number>, parent?: LayoutBase): string
|
||||
style.fontSize = fontSizes[i % 2];
|
||||
}
|
||||
});
|
||||
result += `\t${time}`;
|
||||
result += setResultTime(time);
|
||||
});
|
||||
|
||||
return result;
|
||||
@ -153,7 +153,7 @@ export function setFontSizeWithParents(counts: Array<number>, parent: LayoutBase
|
||||
style.fontSize = fontSizes[i % 2];
|
||||
}
|
||||
});
|
||||
result += `\t${time}`;
|
||||
result += setResultTime(time);
|
||||
});
|
||||
|
||||
return result;
|
||||
@ -169,7 +169,7 @@ export function setFontWeight(counts: Array<number>, parent?: LayoutBase): strin
|
||||
style.fontWeight = i % 2 === 0 ? 'bold' : 'normal';
|
||||
}
|
||||
});
|
||||
result += `\t${time}`;
|
||||
result += setResultTime(time);
|
||||
});
|
||||
|
||||
return result;
|
||||
@ -189,7 +189,7 @@ export function setFontWeightWithParents(counts: Array<number>, parent: LayoutBa
|
||||
style.fontWeight = i % 2 === 0 ? 'bold' : 'normal'
|
||||
}
|
||||
});
|
||||
result += `\t${time}`;
|
||||
result += setResultTime(time);
|
||||
});
|
||||
|
||||
return result;
|
||||
@ -204,7 +204,7 @@ export function setBindingContext(counts: Array<number>, parent?: LayoutBase): s
|
||||
lbl.bindingContext = colors[i % 2];
|
||||
}
|
||||
});
|
||||
result += `\t${time}`;
|
||||
result += setResultTime(time);
|
||||
});
|
||||
|
||||
return result;
|
||||
@ -222,7 +222,7 @@ export function setBindingContextWithParents(counts: Array<number>, parent: Layo
|
||||
parent.bindingContext = colors[i % 2];
|
||||
}
|
||||
});
|
||||
result += `\t${time}`;
|
||||
result += setResultTime(time);
|
||||
});
|
||||
|
||||
return result;
|
||||
@ -241,7 +241,7 @@ export function setBindingContextWithParentsBound(counts: Array<number>, parent:
|
||||
parent.bindingContext = colors[i % 2];
|
||||
}
|
||||
});
|
||||
result += `\t${time}`;
|
||||
result += setResultTime(time);
|
||||
});
|
||||
|
||||
return result;
|
||||
@ -298,4 +298,8 @@ function executeTest(func: Function): string {
|
||||
const avg = total / average;
|
||||
const res = `${avg.toFixed(2)}`;
|
||||
return res;
|
||||
}
|
||||
|
||||
function setResultTime(time: string) {
|
||||
return ' ' + `\t${time}` + ' ';
|
||||
}
|
Reference in New Issue
Block a user