Skip to content

Commit 6b964ca

Browse files
committed
feat(tele): system info
1 parent 1941260 commit 6b964ca

4 files changed

Lines changed: 91 additions & 7 deletions

File tree

core/src/cn/harryh/arkpets/ArkPets.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import cn.harryh.arkpets.platform.WindowSystem;
1212
import cn.harryh.arkpets.render.PixmapWrapper;
1313
import cn.harryh.arkpets.telemetry.CorePerformanceSampler;
14+
import cn.harryh.arkpets.telemetry.wal.WalSystemInfoCodec;
15+
import cn.harryh.arkpets.telemetry.wal.WalWriter;
1416
import cn.harryh.arkpets.transitions.TransitionVector2;
1517
import cn.harryh.arkpets.tray.MemberTrayImpl;
1618
import cn.harryh.arkpets.utils.*;
@@ -20,6 +22,7 @@
2022
import com.badlogic.gdx.files.FileHandle;
2123
import com.badlogic.gdx.graphics.GL20;
2224

25+
import java.io.IOException;
2326
import java.util.HashMap;
2427
import java.util.List;
2528
import java.util.regex.Pattern;
@@ -119,6 +122,8 @@ public void create() {
119122
tray = new MemberTrayImpl(this, new SocketClient());
120123

121124
// Setup complete
125+
writeSystemInfo();
126+
122127
Logger.info("App", "Render");
123128
}
124129

@@ -536,4 +541,15 @@ public void sendMouseEvent(HWndCtrl.MouseEvent msg) {
536541
hWndCtrl.updated().sendMouseEvent(msg, relX, relY);
537542
}
538543
}
544+
545+
private void writeSystemInfo() {
546+
try (WalWriter writer = WalWriter.open(ProcessHandle.current().pid())) {
547+
writer.append(WalSystemInfoCodec.INSTANCE, new WalSystemInfoCodec.SystemInfo(
548+
Gdx.gl.glGetString(GL20.GL_VENDOR),
549+
Gdx.gl.glGetString(GL20.GL_VERSION)
550+
));
551+
} catch (IOException e) {
552+
Logger.warn("System", "Failed to write config snapshot");
553+
}
554+
}
539555
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package cn.harryh.arkpets.telemetry.wal;
2+
3+
import java.io.*;
4+
5+
6+
public class WalSystemInfoCodec implements WalCodec<WalSystemInfoCodec.SystemInfo>{
7+
public static final WalSystemInfoCodec INSTANCE = new WalSystemInfoCodec();
8+
9+
@Override
10+
public String type() {
11+
return "system_info";
12+
}
13+
14+
@Override
15+
public byte[] encode(WalSystemInfoCodec.SystemInfo value) throws IOException {
16+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
17+
try (DataOutputStream dos = new DataOutputStream(bos)) {
18+
dos.writeUTF(value.gpuName());
19+
dos.writeUTF(value.gpuVersion());
20+
dos.writeUTF(value.osName());
21+
dos.writeUTF(value.osArch());
22+
}
23+
return bos.toByteArray();
24+
}
25+
26+
@Override
27+
public WalSystemInfoCodec.SystemInfo decode(byte[] payload) throws IOException {
28+
try (DataInputStream dis = new DataInputStream(new ByteArrayInputStream(payload))) {
29+
String gpuInfo = dis.readUTF();
30+
String gpuVersion = dis.readUTF();
31+
String osName = dis.readUTF();
32+
String osArch = dis.readUTF();
33+
return new SystemInfo(gpuInfo, gpuVersion, osName, osArch);
34+
}
35+
}
36+
37+
public record SystemInfo(String gpuName, String gpuVersion, String osName, String osArch) {
38+
public SystemInfo(String gpuInfo, String gpuVersion) {
39+
this(gpuInfo, gpuVersion, System.getProperty("os.name"), System.getProperty("os.arch"));
40+
}
41+
}
42+
}

desktop/src/cn/harryh/arkpets/utils/SentryHelper.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,24 @@ private static void reportConfig(Map<String, Object> config, long timestampMilli
9595
Logger.debug("Telemetry", "Uploaded a CONFIG event");
9696
}
9797

98+
private static void reportSystemInfo(WalSystemInfoCodec.SystemInfo info, long timestampMillis) {
99+
if (!enable) return;
100+
Sentry.logger().log(
101+
SentryLogLevel.INFO,
102+
SentryLogParameters.create(
103+
new SentryLongDate(timestampMillis * 1_000_000L),
104+
SentryAttributes.of(
105+
SentryAttribute.stringAttribute("gpu.name", info.gpuName()),
106+
SentryAttribute.stringAttribute("gpu.version", info.gpuVersion()),
107+
SentryAttribute.stringAttribute("os.name", info.osName()),
108+
SentryAttribute.stringAttribute("os.arch", info.osArch())
109+
)
110+
),
111+
"SYSTEM_INFO"
112+
);
113+
Logger.debug("Telemetry", "Uploaded a SYSTEM_INFO event");
114+
}
115+
98116
private static void reportCorePerformance(
99117
CorePerformanceSnapshot performance,
100118
String asset,
@@ -245,6 +263,8 @@ private static void consumeWalRecords(List<WalRecord> records) {
245263
Map<String, Object> configSnapshot = null;
246264
long configTimestamp = 0;
247265
List<ModelHeartbeatRecord> modelHeartbeats = new ArrayList<>();
266+
WalSystemInfoCodec.SystemInfo systemInfo = null;
267+
long systemInfoTimestamp = 0;
248268
for (WalRecord record : records) {
249269
try {
250270
if (record.type().equals(WalCoreHeartbeatCodec.INSTANCE.type())) {
@@ -259,12 +279,17 @@ private static void consumeWalRecords(List<WalRecord> records) {
259279
} else if (record.type().equals(WalConfigCodec.INSTANCE.type())) {
260280
configSnapshot = WalConfigCodec.INSTANCE.decode(record.payload());
261281
configTimestamp = record.timestamp();
282+
} else if (record.type().equals(WalSystemInfoCodec.INSTANCE.type())) {
283+
systemInfo = WalSystemInfoCodec.INSTANCE.decode(record.payload());
284+
systemInfoTimestamp = record.timestamp();
262285
}
263286
} catch (IOException ignored) {
264287
}
265288
}
266289
if (configSnapshot != null)
267290
reportConfig(configSnapshot, configTimestamp);
291+
if (systemInfo != null)
292+
reportSystemInfo(systemInfo, systemInfoTimestamp);
268293
for (ModelHeartbeatRecord heartbeatRecord : modelHeartbeats) {
269294
reportCorePerformance(
270295
heartbeatRecord.heartbeat().performance(),

docs/Telemetry.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ ArkPets 内置了一套可自愿退出的遥测系统,用于收集程序在真
4444

4545
所有自动上报的事件分为以下几类:
4646

47-
| 事件 | 触发条件 | 上报内容 |
48-
|:-------------------------:|----------------|----------------------------------|
49-
| 模型会话<br>(MODEL_SESSION) | 桌宠每次退出时 | 使用的模型、本次运行时长;是正常退出、异常退出还是因崩溃结束运行 |
50-
| 桌面会话<br>(DESKTOP_SESSION) | 启动器每次退出时 | 本次启动器运行时长 |
51-
| 配置快照<br>(CONFIG) | 桌宠启动时 | 当时的各项设置值(排除敏感信息) |
52-
| 性能指标 | 桌宠运行期间每若干秒采集一次 | 渲染耗时、渲染分辨率、帧率、内存占用、CPU 占用 |
53-
| 崩溃报告 | 桌宠崩溃时 | 异常类型和调用堆栈 |
47+
| 事件 | 触发条件 | 上报内容 |
48+
|:-------------------------------:|------------------------------|------------------------------------------------------------------|
49+
| 模型会话<br>(MODEL_SESSION) | 桌宠每次退出时 | 使用的模型、本次运行时长;是正常退出、异常退出还是因崩溃结束运行 |
50+
| 桌面会话<br>(DESKTOP_SESSION) | 启动器每次退出时 | 本次启动器运行时长 |
51+
| 配置快照<br>(CONFIG) | 桌宠启动时 | 当时的各项设置值(排除敏感信息) |
52+
| 系统信息<br>(SYSTEM_INFO) | 桌宠 GL 上下文初始化后 | 系统的显卡供应商、驱动版本号、操作系统版本 |
53+
| 性能指标 | 桌宠运行期间每若干秒采集一次 | 渲染耗时、渲染分辨率、帧率、内存占用、CPU 占用 |
54+
| 崩溃报告 | 桌宠崩溃时 | 异常类型和调用堆栈 |
5455

5556
此外,当启动器出现错误对话框时,您可以手动点击「上传日志」按钮,将程序的日志文件作为反馈发送给我们。
5657

0 commit comments

Comments
 (0)