Commit 0ac3ddb8 authored by martin hou's avatar martin hou

perf trace

parent 14b905e3
...@@ -80,7 +80,7 @@ export function Home() { ...@@ -80,7 +80,7 @@ export function Home() {
const listFiles = async () => { const listFiles = async () => {
let files = await jensen.listFiles(); let files = await jensen.listFiles();
console.log(files); setFiles(files);
} }
const getBluetoothStatus = async () => { const getBluetoothStatus = async () => {
...@@ -88,6 +88,20 @@ export function Home() { ...@@ -88,6 +88,20 @@ export function Home() {
alert(JSON.stringify(info)); alert(JSON.stringify(info));
} }
const transferFile = async () => {
if (files.length == 0) return alert('No files found');
let idx = prompt('请输入文件序号(从0开始):', '0');
if (idx === undefined) return;
if (idx === null) return;
let num = parseInt(idx);
if (isNaN(num)) return;
if (num < 0 || num >= files.length) return alert('无效序号');
let file = files[num];
jensen.getFile(file.name, file.length, (segment) => {
// ...
});
}
return ( return (
<> <>
<div style={{ display: 'flex', flexDirection: 'row', gap: '16px', padding: '16px', alignItems: 'center' }}> <div style={{ display: 'flex', flexDirection: 'row', gap: '16px', padding: '16px', alignItems: 'center' }}>
...@@ -101,6 +115,7 @@ export function Home() { ...@@ -101,6 +115,7 @@ export function Home() {
Get Time Get Time
</button> </button>
<button style={{ width: '200px', height: '50px' }} onClick={listFiles}>List Files</button> <button style={{ width: '200px', height: '50px' }} onClick={listFiles}>List Files</button>
<button style={{ width: '200px', height: '50px' }} onClick={transferFile}>Transfer</button>
<button style={{ width: '200px', height: '50px' }} onClick={getBluetoothStatus}>Bluetooth Status</button> <button style={{ width: '200px', height: '50px' }} onClick={getBluetoothStatus}>Bluetooth Status</button>
<button style={{ width : '200px', height : '50px' }} onClick={bluetoothScan}>Bluetooth Scan</button> <button style={{ width : '200px', height : '50px' }} onClick={bluetoothScan}>Bluetooth Scan</button>
<button style={{ width : '200px', height : '50px' }} onClick={disconnectBTDevice}>Bluetooth Disconnect</button> <button style={{ width : '200px', height : '50px' }} onClick={disconnectBTDevice}>Bluetooth Disconnect</button>
......
...@@ -889,7 +889,7 @@ Jensen.prototype.getFile = async function (filename, length, ondata, onprogress) ...@@ -889,7 +889,7 @@ Jensen.prototype.getFile = async function (filename, length, ondata, onprogress)
// visibilitychange(); // visibilitychange();
// document.addEventListener('visibilitychange', visibilitychange); // document.addEventListener('visibilitychange', visibilitychange);
let stime = new Date();
let flen = 0; let flen = 0;
let handler = (msg) => { let handler = (msg) => {
if (msg != null) { if (msg != null) {
...@@ -901,6 +901,9 @@ Jensen.prototype.getFile = async function (filename, length, ondata, onprogress) ...@@ -901,6 +901,9 @@ Jensen.prototype.getFile = async function (filename, length, ondata, onprogress)
Logger.info('jensen', 'getFile', 'file transfer finish.'); Logger.info('jensen', 'getFile', 'file transfer finish.');
// clearEventAndTask(); // clearEventAndTask();
// return OK indicates all file blocks received // return OK indicates all file blocks received
let etime = new Date();
let cost = etime.getTime() - stime.getTime();
Logger.info('jensen', 'getFile', 'cost ' + cost + ' ms');
return 'OK'; return 'OK';
} }
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment