This commit is contained in:
qiuqiu 2025-04-11 21:47:05 +08:00
parent aaf6346f58
commit fb5cc465ac
19 changed files with 352 additions and 10 deletions

17
.idea/workspace.xml generated
View File

@ -8,6 +8,10 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="fec10672-acda-4616-894b-a4b6f93aea6f" name="Default Changelist" comment=""> <list default="true" id="fec10672-acda-4616-894b-a4b6f93aea6f" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/笔记文件/2.笔记/sqlite存在问题和修复.md" beforeDir="false" afterPath="$PROJECT_DIR$/笔记文件/2.笔记/sqlite存在问题和修复.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/笔记文件/2.笔记/性能检测平台 临时记录.md" beforeDir="false" afterPath="$PROJECT_DIR$/笔记文件/2.笔记/性能检测平台 临时记录.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/笔记文件/2.笔记/日志系统 临时记录.md" beforeDir="false" afterPath="$PROJECT_DIR$/笔记文件/2.笔记/日志系统 临时记录.md" afterDir="false" />
<change beforePath="$PROJECT_DIR$/笔记文件/日记/2025_04_11_星期五.md" beforeDir="false" afterPath="$PROJECT_DIR$/笔记文件/日记/2025_04_11_星期五.md" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -35,7 +39,7 @@
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" /> <property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" /> <property name="WebServerToolWindowFactoryState" value="false" />
<property name="cf.first.check.clang-format" value="false" /> <property name="cf.first.check.clang-format" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" /> <property name="last_opened_file_path" value="$PROJECT_DIR$/../code/git/lgcollecter" />
<property name="nodejs_package_manager_path" value="npm" /> <property name="nodejs_package_manager_path" value="npm" />
<property name="settings.editor.selected.configurable" value="preferences.general" /> <property name="settings.editor.selected.configurable" value="preferences.general" />
</component> </component>
@ -58,7 +62,7 @@
<workItem from="1743923141849" duration="49000" /> <workItem from="1743923141849" duration="49000" />
<workItem from="1743923197347" duration="53000" /> <workItem from="1743923197347" duration="53000" />
<workItem from="1743923256222" duration="1432000" /> <workItem from="1743923256222" duration="1432000" />
<workItem from="1744012644631" duration="5485000" /> <workItem from="1744012644631" duration="8122000" />
</task> </task>
<task id="LOCAL-00001" summary="测试提交"> <task id="LOCAL-00001" summary="测试提交">
<created>1742956649478</created> <created>1742956649478</created>
@ -193,7 +197,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1744275726721</updated> <updated>1744275726721</updated>
</task> </task>
<option name="localTasksCounter" value="20" /> <task id="LOCAL-00020" summary="提交">
<created>1744280785157</created>
<option name="number" value="00020" />
<option name="presentableId" value="LOCAL-00020" />
<option name="project" value="LOCAL" />
<updated>1744280785157</updated>
</task>
<option name="localTasksCounter" value="21" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">

View File

@ -0,0 +1,5 @@
#sql
![[Pasted image 20250411140706.png]]
![[Pasted image 20250411140720.png]]

View File

@ -2,4 +2,73 @@
![[img_v3_02kt_1fb5e484-9202-4f12-bc3e-dd7ae3b2dehu.jpg]] ![[img_v3_02kt_1fb5e484-9202-4f12-bc3e-dd7ae3b2dehu.jpg]]
![[Pasted image 20250401140148.png]] ![[Pasted image 20250401140148.png]]
```
[2025-04-09 16:33:36] {
"Sys": "Android",
"Ver": "0.14.5",
"IP": "24.234.138.39",
"Model": "Maxwest MX-A63",
"Uid": "53542198857",
"Device": "60e499bc255db385dcba58b44958a5fc"
}
SQLiteException: database disk image is malformed
SQLite.SQLiteCommand.ExecuteNonQuery () (at <00000000000000000000000000000000>:0)
SQLite.SQLiteConnection.Execute (System.String query, System.Object[] args) (at <00000000000000000000000000000000>:0)
SQLite4Unity3d.SQLiteManager.UpsertDataAsync (System.Collections.Generic.Dictionary`2[TKey,TValue] tableDataMap, System.String columnName) (at <00000000000000000000000000000000>:0)
SQLite4Unity3d.SQLiteManager.UpsertDataAsync (System.Collections.Generic.Dictionary`2[TKey,TValue] tableDataMap, System.String columnName) (at <00000000000000000000000000000000>:0)
CGBU_SDK.SessionCache+<>c__DisplayClass27_0.<UpdateSQLiteCache>b__0 () (at <00000000000000000000000000000000>:0)
CGBU_SDK.SessionCache+<>c__DisplayClass27_0.<UpdateSQLiteCache>b__0 () (at <00000000000000000000000000000000>:0)
SQLite4Unity3d.TaskQueue+<>c__DisplayClass7_0.<EnqueueTask>b__0 () (at <00000000000000000000000000000000>:0)
SQLite4Unity3d.TaskQueue+<>c__DisplayClass7_0.<EnqueueTask>b__0 () (at <00000000000000000000000000000000>:0)
SQLite4Unity3d.TaskQueue.ProcessQueue () (at <00000000000000000000000000000000>:0)
System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <00000000000000000000000000000000>:0)
--- End of stack trace from previous location where exception was thrown ---
CGBU_SDK.SessionCache+<>c__DisplayClass27_0.<UpdateSQLiteCache>b__0 () (at <00000000000000000000000000000000>:0)
CGBU_SDK.SessionCache+<>c__DisplayClass27_0.<UpdateSQLiteCache>b__0 () (at <00000000000000000000000000000000>:0)
SQLite4Unity3d.TaskQueue+<>c__DisplayClass7_0.<EnqueueTask>b__0 () (at <00000000000000000000000000000000>:0)
SQLite4Unity3d.TaskQueue+<>c__DisplayClass7_0.<EnqueueTask>b__0 () (at <00000000000000000000000000000000>:0)
SQLite4Unity3d.TaskQueue.ProcessQueue () (at <00000000000000000000000000000000>:0)
System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <00000000000000000000000000000000>:0)
--- End of stack trace from previous location where exception was thrown ---
SQLite4Unity3d.TaskQueue+<>c__DisplayClass7_0.<EnqueueTask>b__0 () (at <00000000000000000000000000000000>:0)
SQLite4Unity3d.TaskQueue+<>c__DisplayClass7_0.<EnqueueTask>b__0 () (at <00000000000000000000000000000000>:0)
SQLite4Unity3d.TaskQueue.ProcessQueue () (at <00000000000000000000000000000000>:0)
System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <00000000000000000000000000000000>:0)
--- End of stack trace from previous location where exception was thrown ---
Cysharp.Threading.Tasks.UniTaskCompletionSource`1[T].GetResult (System.Int16 token) (at <00000000000000000000000000000000>:0)
CGBU_SDK.SessionCache.UpdateSQLiteCache () (at <00000000000000000000000000000000>:0)
System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <00000000000000000000000000000000>:0)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+MoveNextRunner.Run () (at <00000000000000000000000000000000>:0)
Cysharp.Threading.Tasks.UniTaskCompletionSource`1[T].TrySignalCompletion (Cysharp.Threading.Tasks.UniTaskStatus status) (at <00000000000000000000000000000000>:0)
SQLite4Unity3d.TaskQueue+<>c__DisplayClass7_0.<EnqueueTask>b__0 () (at <00000000000000000000000000000000>:0)
SQLite4Unity3d.TaskQueue+<>c__DisplayClass7_0.<EnqueueTask>b__0 () (at <00000000000000000000000000000000>:0)
SQLite4Unity3d.TaskQueue.ProcessQueue () (at <00000000000000000000000000000000>:0)
System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <00000000000000000000000000000000>:0)
--- End of stack trace from previous location where exception was thrown ---
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <00000000000000000000000000000000>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <00000000000000000000000000000000>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <00000000000000000000000000000000>:0)
[2025-04-09 16:33:36] {
"Sys": "Android",
"Ver": "0.14.5",
"IP": "2607:fb91:1ee2:92c2:1d06:6a14:3704:fa2",
"Model": "motorola moto e6 (XT2005DL)",
"Uid": "29057263195",
"Device": "b6e46749ab02a9f03294b0eaa707ff17"
}
Creature1:2405: attempt to index a boolean value (field 'mVisitorInfo')
stack traceback:
LGReporter:59: in function 'debug.traceback'
[C]: in metamethod 'newindex'
Creature1:2405: in method 'SetMountAsset'
Creature1:2382: in method 'MountAssetActionStart'
Creature1:2361: in function <Creature1:2360>
f:SetMountAsset--l:4
v pMountAssetID:10001.000000
f:MountAssetActionStart--l:5
f:unknown--l:6
```

View File

@ -0,0 +1,217 @@
#python
#安卓
如果要通过python的形式检测安卓的cpu占用率是需要通过adb调试的形式一般是连线安卓实体机
在执行上述操作之前需要确认的是安卓的adb调试是已经配置完成和可用的参考[[设置adb环境变量]]还有python 3的环境变量也是需要的可参考[[python设置环境变量]],配置完成:
![[Pasted image 20250411151801.png]]
其中安卓的bundleid包名`com.DefaultCompany.LGCollecter`
![[Pasted image 20250411152113.png]]
这是考虑了cpu多核情况的python脚本1秒的时间间隔采集cpu时间可以直接执行
## cpu.py
``` py
import subprocess
import time
PACKAGE = "com.DefaultCompany.LGCollecter"
INTERVAL = 1.0
def get_cpu_cores():
"""获取CPU核心数"""
try:
output = subprocess.check_output(
"adb shell grep -c processor /proc/cpuinfo",
stderr=subprocess.STDOUT,
shell=True
)
return int(output.strip())
except:
return 1
def get_pid():
"""持续获取进程ID"""
while True:
try:
output = subprocess.check_output(
f"adb shell pidof {PACKAGE}",
stderr=subprocess.STDOUT,
shell=True
)
pid = output.decode().strip()
if pid:
return int(pid)
except subprocess.CalledProcessError:
pass
print("等待应用启动...")
time.sleep(2)
def read_proc_stat():
"""读取系统CPU总时间"""
output = subprocess.check_output(
"adb shell head -n1 /proc/stat",
stderr=subprocess.STDOUT,
shell=True
).decode()
parts = output.strip().split()[1:8]
return sum(map(int, parts))
def read_process_cpu(pid):
"""读取进程CPU时间"""
output = subprocess.check_output(
f"adb shell cat /proc/{pid}/stat",
stderr=subprocess.STDOUT,
shell=True
).decode()
parts = output.strip().split()
utime = int(parts[13])
stime = int(parts[14])
return utime + stime
def main():
cores = get_cpu_cores()
pid = get_pid()
print(f"监控开始 (PID: {pid}, CPU核心: {cores})")
prev_proc_time = read_process_cpu(pid)
prev_total_time = read_proc_stat()
while True:
time.sleep(INTERVAL)
curr_proc_time = read_process_cpu(pid)
curr_total_time = read_proc_stat()
proc_diff = curr_proc_time - prev_proc_time
total_diff = curr_total_time - prev_total_time
if total_diff == 0:
usage = 0.0
else:
# 计算实际CPU使用率考虑多核
usage = 100.0 * proc_diff / total_diff
# 转换为多核百分比(可选)
# usage = usage * 100.0 / cores
print(f"{time.strftime('%H:%M:%S')} CPU使用率: {usage:.1f}%")
prev_proc_time = curr_proc_time
prev_total_time = curr_total_time
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\n监控已停止")
except Exception as e:
print(f"发生错误: {str(e)}")
```
安卓相关的java逻辑也可以实现cpu占用率的测算但是这个不是非常准确另外安卓相关的如果要获取系统总的cpu频率等数据相关也就是`/proc/stat`系统级别的信息一般是不开放这个接口权限的所以不够adb方式的python脚本获取的数据准确
需先申请权限,参考一下,权限申请:
## AndroidManifest.xml
``` xml
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.PACKAGE_USAGE_STATS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_PROC_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application>
<activity android:name="com.unity3d.player.UnityPlayerActivity"
android:theme="@style/UnityThemeSelector">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
</application>
</manifest>
```
## Sys.java
``` java
public static float getProcessCPUUsageOnce() {
try {
// 第一次采样
BufferedReader br1 = new BufferedReader(new FileReader("/proc/self/stat"));
String line1 = br1.readLine();
String[] parts1 = line1.split("\\s+");
long utime1 = Long.parseLong(parts1[13]);
long stime1 = Long.parseLong(parts1[14]);
long cpuTime1 = utime1 + stime1;
// 等待1秒
Thread.sleep(1000);
// 第二次采样
BufferedReader br2 = new BufferedReader(new FileReader("/proc/self/stat"));
String line2 = br2.readLine();
String[] parts2 = line2.split("\\s+");
long utime2 = Long.parseLong(parts2[13]);
long stime2 = Long.parseLong(parts2[14]);
long cpuTime2 = utime2 + stime2;
// 计算使用率
int hz = getSystemClockTicks();
float usage = ((cpuTime2 - cpuTime1) / (float) hz) * 100f;
// 新增日志输出
Log.d("CPUUsage", "系统CPU使用率: " + String.format("%.2f", usage) + "%");
return Math.max(0, Math.min(usage, 100));
} catch (Exception e) {
Log.e("CPUUsage", "获取CPU使用率失败", e);
e.printStackTrace();
}
return -1f;
}
// 新增帮助方法 获取CPU时钟频率Hz
private static int getSystemClockTicks() {
try {
// 方法1通过系统属性获取需要API 21+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
int hz = (int) android.system.Os.sysconf(android.system.OsConstants._SC_CLK_TCK);
if (hz > 0) {
return hz;
}
}
// 方法2通过/proc文件系统动态计算
// 读取进程启动时间和系统运行时间
BufferedReader statBr = new BufferedReader(new FileReader("/proc/self/stat"));
String[] stat = statBr.readLine().split("\\s+");
long startTime = Long.parseLong(stat[21]); // 启动时间jiffies
long utime = Long.parseLong(stat[13]); // 用户态时间
BufferedReader uptimeBr = new BufferedReader(new FileReader("/proc/uptime"));
String uptimeStr = uptimeBr.readLine().split("\\s+")[0];
float uptime = Float.parseFloat(uptimeStr); // 系统运行时间(秒)
// 计算HZstartTime的单位是jiffiesuptime的单位是秒
// HZ = startTime / (uptime - (process_start_time_seconds))
long processStartSeconds = startTime / 100; // 假设初始HZ=100进行估算
float actualHz = startTime / (uptime - processStartSeconds);
// 取整并限制合理范围
int hz = Math.max(100, Math.min(1000, (int)actualHz));
Log.d("ClockTicks", "Calculated HZ: " + hz);
return hz;
} catch (Exception e) {
Log.e("ClockTicks", "Error calculating HZ, using default 100", e);
return 100; // 保底返回值
}
}
```

View File

@ -62,4 +62,28 @@
main函数运行到这里就可以判断和创建数据库了 main函数运行到这里就可以判断和创建数据库了
![[Pasted image 20250410175756.png]] ![[Pasted image 20250410175756.png]]
也是这里,就是服务端,采集到的,相关数据和解析
![[Pasted image 20250411111816.png]]
然后这里是之前的相关封装其中Msg和ExtMsg等 额外附加数据可以看到是封装放到Report里的
![[Pasted image 20250411111957.png]]
客户端的拼接和上报
![[Pasted image 20250411112239.png]]
结构体这里,也要加上:
![[Pasted image 20250411115605.png]]
断点可以采集到非空的fpsData相关数据
![[Pasted image 20250411141921.png]]
需要确认一下这里是不是三消的lua初始化相关
![[Pasted image 20250411154812.png]]

View File

@ -123,4 +123,8 @@ history
![[Pasted image 20250124165132.png]] ![[Pasted image 20250124165132.png]]
完成。 完成。
客户端上报
![[Pasted image 20250411104809.png]]

View File

@ -21,9 +21,13 @@
# 今日任务 # 今日任务
- [ ] 看是否可以加一下,运镜相关的效果 - [x] 记得带幼猫粮过去
- [ ] 记得带幼猫粮过去
- [ ] 明天记得换猫砂 - [ ] 明天记得换猫砂
- [ ] 调整一下sqlite的初始化throw异常抛出
- [x] 采集fps是1秒采集一次设置5秒才上报一次fps在服务端也要做相关兼容
- [x] 在原版日期创建表的同时新增fps表和用户表
- [x] 确认一下 ppt的视频是否已经替换
--- ---
[[NoSQL]]
[[安卓cpu占用率]]
# Journal # Journal

View File

@ -1,2 +1,10 @@
#unity/日常积累
可以直接在函数里面取当前线程id不一定是unity主线程
//using System.Threading; //using System.Threading;
int id = Thread.CurrentThread.ManagedThreadId; var currentThread = Thread.CurrentThread.ManagedThreadId;
unity主线程其实也是这个
var currentThread = Thread.CurrentThread.ManagedThreadId;

Binary file not shown.

After

Width:  |  Height:  |  Size: 685 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB