未確認だが問題回避のためプッシュ
This commit is contained in:
@ -1,6 +1,12 @@
|
||||
import 'dart:async';
|
||||
//import 'dart:convert';
|
||||
//import 'dart:developer';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_map_tile_caching/flutter_map_tile_caching.dart';
|
||||
import 'package:get/get.dart';
|
||||
//import 'package:vm_service/vm_service.dart';
|
||||
//import 'package:dart_vm_info/dart_vm_info.dart';
|
||||
|
||||
import 'package:rogapp/pages/destination/destination_controller.dart';
|
||||
import 'package:rogapp/pages/index/index_binding.dart';
|
||||
import 'package:rogapp/routes/app_pages.dart';
|
||||
@ -66,6 +72,8 @@ void main() async {
|
||||
ErrorService.reportError(details.exception, details.stack ?? StackTrace.current, deviceInfo);
|
||||
};
|
||||
|
||||
// startMemoryMonitoring(); // 2024-4-8 Akira: メモリ使用量のチェックを開始 See #2810
|
||||
|
||||
runZonedGuarded(() {
|
||||
runApp(const ProviderScope(child: MyApp()));
|
||||
}, (error, stackTrace) {
|
||||
@ -75,6 +83,72 @@ void main() async {
|
||||
//runApp(const MyApp());
|
||||
}
|
||||
|
||||
// メモリ使用量の解説:https://qiita.com/hukusuke1007/items/e4e987836412e9bc73b9
|
||||
|
||||
/*
|
||||
// 2024-4-8 Akira: メモリ使用量のチェックのため追加 See #2810
|
||||
// startMemoryMonitoring関数が5分ごとに呼び出され、メモリ使用量をチェックします。
|
||||
// メモリ使用量が閾値(ここでは500MB)を超えた場合、エラーメッセージとスタックトレースをレポートします。
|
||||
//
|
||||
void startMemoryMonitoring() {
|
||||
const threshold = 500 * 1024 * 1024; // 500MB
|
||||
|
||||
// メモリ使用量情報を取得
|
||||
final memoryUsage = MemoryUsage.fromJson(DartVMInfo.getAllocationProfile());
|
||||
|
||||
if (memoryUsage.heapUsage > threshold) {
|
||||
final now = DateTime.now().toIso8601String();
|
||||
final message = 'High memory usage detected at $now: ${memoryUsage.heapUsage} bytes';
|
||||
print(message);
|
||||
reportError(message, StackTrace.current);
|
||||
showMemoryWarningDialog();
|
||||
}
|
||||
|
||||
Timer(const Duration(minutes: 5), startMemoryMonitoring);
|
||||
}
|
||||
|
||||
class MemoryUsage {
|
||||
final int heapUsage;
|
||||
|
||||
MemoryUsage({required this.heapUsage});
|
||||
|
||||
factory MemoryUsage.fromJson(Map<String, dynamic> json) {
|
||||
return MemoryUsage(
|
||||
heapUsage: json['heapUsage'] as int,
|
||||
);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// 2024-4-8 Akira: メモリ使用量のチェックのため追加 See #2810
|
||||
// reportError関数でエラーレポートを送信します。具体的な実装は、利用するエラー報告サービスによって異なります。
|
||||
void reportError(String message, StackTrace stackTrace) async {
|
||||
// エラーレポートの送信処理を実装
|
||||
// 例: SentryやFirebase Crashlyticsなどのエラー報告サービスを利用
|
||||
print("ReportError : ${message} . stacktrace : ${stackTrace}");
|
||||
}
|
||||
|
||||
// 2024-4-8 Akira: メモリ使用量のチェックのため追加 See #2810
|
||||
// showMemoryWarningDialog関数で、メモリ使用量が高い場合にユーザーに警告ダイアログを表示します。
|
||||
//
|
||||
void showMemoryWarningDialog() {
|
||||
if (Get.context != null) {
|
||||
showDialog(
|
||||
context: Get.context!,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('メモリ使用量の警告'),
|
||||
content: const Text('アプリのメモリ使用量が高くなっています。アプリを再起動することをお勧めします。'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyApp extends StatefulWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user