在探查器中创建日志的格式是什么?
在我正在编写的探查器(实际上是 Java 程序的 JVMTI 代理)中,我需要一种格式来记录收集的事件。此外,这些日志必须发送到套接字并由其他地方的 GUI 读取。所以我需要两种语言之间的有效序列化。
我已经在 XML 中实现了我自己的协议,并且效果非常好。然而我被告知要考虑另一种格式。由于 XML 构建可能非常慢,并且分析器中执行的每个附加代码都会严重影响分析程序。这是事实,但是 XML DOM 构建需要那么长时间吗?
到目前为止我使用的是 TinyXML。我希望没有人指出 RapidXML,因为我希望在非嵌入式机器上没有那么不同。
你怎么认为?目前我正在尝试用protobuf重新实现它,它声称比XML快n倍。
In the profiler I am writing, which is in fact a JVMTI agent for Java programs, I need a format to log the events collected. Further these logs have to be send to a socket and read by a GUI somewhere else. So I need a working serialization between two languages.
I already implemented my own protocol in XML and it worked very well. However I was told to consider another format. As XML building might be very slow and every additional code executed in the profiler influences heavily the profiled program. This is true, but does XML DOM Building take that long?
I used TinyXML so far. I hope no one points to RapidXML, as I hope there are not that different on a not-embedded machine.
What do you think? Currently I am trying to reimplement it with protobuf, which claims to be n times faster then XML.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在为我职责范围内的所有日志文件进行设计。我以 JSON 格式记录数据,但 JSON 数据嵌套在非常简单的 xml 格式中。
例如
,这样我就可以轻松地将数据和日志记录分开,但又可以避免日志记录目录变得复杂。还省去了为自定义格式编写自己的解析器的麻烦。然而,考虑到你的情况,我建议仅使用 JSON,前提是你基本上使用序列化。当格式正确时,JSON 非常适合人类可读,它可以非常简洁,并且有稳定的解析器。
I have a design I am working on for all log file in my remit. I record data in JSON but the JSON data is nested in a very simple xml format.
eg
That way I can easily separate out data and logging, but keep the logging directory from being complicated. Also saves having to write my own parser for a custom format. However given your situation I recommend using JSON only given that you are basically using to serialise. JSON is very much human-readable when it is formatted correctly, it can be very concise, and there are stable parsers for it.
我的第一选择始终是传统的 txt 文件。
您可以在文件末尾(底部)附加新条目
my first choice is always the traditional txt file.
you can append new entries at the end of file (bottom)