C++ 运行时调试(诊断策略和构造)

发布于 2024-07-26 21:31:59 字数 937 浏览 9 评论 0原文

我计划在我的软件中添加广泛的诊断功能。 现在我正在考虑如何做到这一点的总体策略,因为简单地添加这样的代码可能会导致严重的混乱。

您有这方面的经验吗?

我想监控:

  1. 创建所选子集中的对象的密集程度。
  2. 如何密集选择的方法被调用。
  3. 选定时间段内其他事件的数量。
  4. 对于选定的方法,收集有关调用者的信息(libcwd 允许这样做吗?
  5. )每个线程按时间段顺序消耗。

我的软件是一个类似处理的工具,它通常像其他处理或计算工具一样工作,例如lame mp3编码器。 这就是为什么这种总体统计数据收集对我来说确实有意义。

我目前计划为每个我想要监视创建/销毁的对象添加一个基类。 基类将在其构造函数和析构函数中记录正确的信息。 还能做什么?

class LifeCycleProbe {
    char * name;
    LifeCycleProbe(char * _name) : name(_name) {
       some::important::object.created(_name);
    }
    ~LifeCycleProbe() {
       some::important::object.destroyed(_name);
    }
}
class MonitorMe : private LifeCycleProbe {
    MonitorMe() : LifeCycleProbe("MonitorMe") {
        // ...
    }
}

I'm planning to add extensive diagnostics into my software. Right now I'm thinking about overall strategy of how to do this, because adding such code simply ad hoc can result in serious mess.

Do you have any experience in this?

I want to monitor:

  1. How intensively objects from selected subset are created.
  2. How intensively selected methods are called.
  3. Number of other events in selected periods of time.
  4. For selected methods gather information about callers (libcwd allows this?)
  5. Amount of time consumed by each thread in sequence of time periods.

My software is a processing-like tool, which in general works like other processing or computing tools, like lame mp3 encoder for example. This is why such overall statistics harvesting does have sense for me.

I'm currently planning to add a base class for each object that I want to monitor for creations/destructions. The base class would log proper information in its constructors and destructors. What else can be done??

class LifeCycleProbe {
    char * name;
    LifeCycleProbe(char * _name) : name(_name) {
       some::important::object.created(_name);
    }
    ~LifeCycleProbe() {
       some::important::object.destroyed(_name);
    }
}
class MonitorMe : private LifeCycleProbe {
    MonitorMe() : LifeCycleProbe("MonitorMe") {
        // ...
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

知你几分 2024-08-02 21:31:59

我首先想到的是,您可能可以充分利用单独的分析工具。 这也将消除更改源代码以允许它的需要。

我可以推荐的工具:

这些工具可以轻松帮助您找到所有问题的答案。

The first thing I can think of is that you can probably make good use of a separate profiling tool. This would also remove the need to alter your source code to allow it.

Tools I can recommend:

These tools can easily help you find answers to all of your questions.

陌上青苔 2024-08-02 21:31:59

+1 给那些建议外部分析器的人。
我只会在开发或测试周期中的非常激烈的情况下绑定分析代码,而绝对不会在生产代码库中。

那时,当我从事 C++ 工作时,有一个非常棒的工具,叫做 BugTrapper。 大约七年前,他们还是一家初创公司,他们开发的软件令人印象深刻。 我认为从那时起他们已经成熟了很多,并且据我看看他们的网站。 曾经很酷的东西,虽然我不确定现在是什么样子。 无论如何,在重新发明轮子之前尝试现成的解决方案是值得的。 恕我直言。

+1 to those suggesting external profiler.
I'd bind profiling code only in a very drastic situations during development or testing cycles, and definitely not in production code base.

Back then, when I worked in C++, there was an absolutely fantastic tool called BugTrapper. It was about 7 years ago, they were a startup company, and it was impressive piece of software they made. I think they've matured a lot since then and stayed in business as far as I can tell by looking at their site. Used to be cool stuff, although I'm not sure what it's like now. In any case, it's worth trying off the shelf solution before reinventing the wheel. IMHO.

×纯※雪 2024-08-02 21:31:59

这看起来像一个好的分析器应该能够为您收集的东西,而无需更改您的源代码。

我使用 kprof 和 valgrind,也许这些工具可以帮助你。

This looks like something a good profiler should be able to gather for you, without changing your sourcecode.

I use kprof and valgrind, maybe those tools can help you.

丢了幸福的猪 2024-08-02 21:31:59

这听起来像是 YAGNI 的一个经典案例 - 我建议首先花时间正确设计和编写软件。

This sounds like a classic case of YAGNI - I'd suggest spendingv the time on desiginig and writing the software correctly in the first place.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文