Linux中的应用程序计数器? (和OSX?) [英] Application counters in Linux? (and OSX?)

查看:90
本文介绍了Linux中的应用程序计数器? (和OSX?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试确定是否有一个库可以给我一些类似于Windows自定义性能计数器的库(在此描述

I'm trying to figure out if there is a library that gives me something near the equivalent of Windows custom performance counters (described here http://geekswithblogs.net/.NETonMyMind/archive/2006/08/20/88549.aspx)

基本上,我正在寻找可用于跟踪应用程序中的全局计数器的东西,(理想情况下)正在寻找一种通过明确定义的接口将该信息提供给其他应用程序/用户的东西.这些是应用程序统计信息;诸如内存和磁盘之类的东西可以通过其他方式捕获,但我希望公开在应用程序生命周期内处理的吞吐量/事务/小部件".

Basically, I'm looking for something that can be used to both track global counters within an application, and (ideally) something that presents that information via a well-defined interface to other applications/users. These are application statistics; stuff like memory and disk can be captured in other ways, but I'm looking to expose throughput/transactions/"widgets" handled during the lifetime of my application.

我已经看到了这个问题:

I've seen this question:

性能计数器"的概念在Linux/Unix中

还有这个

可从Java访问的Linux中的注册表级别计数器

但两者都不是我想要的.我不想写一个静态文件(毕竟这是动态信息;即使磁盘已满,我也应该能够得到它),如果可能的话,我宁愿避免使用自己编写的代码集.理想情况下,至少在Linux上,(我认为)此数据将以某种方式通过/proc浮出水面,尽管我尚不清楚是否可以从用户级完成此操作(这并不重要,只要它在某些地方浮出水面即可).通往客户的方式.)

but neither is quite what I'm looking for. I don't want to write a static file (this is dynamic information after all; I should be able to get at it even if the disk is full etc.), and would rather avoid a homegrown set of code if at all possible. Ideally, at least on Linux, this data would (I think) be surfaced through /proc in some manner, though it's not clear to me if that can be done from userland (this is less important, as long as it is surfaced in some way to clients.)

但是回到问题的症结所在:是否有任何内置或合适的第三方库为我提供了适用于我可以在Linux和其他操作系统上使用的应用程序指标的自定义全局(线程安全,高性能)计数器NIXy操作系统? (并且可以从C/C ++接口吗?)

But back to the crux of the question: is there any built-in or suitable 3rd-party library that gives me custom global (thread-safe, performant) counters suitable for application metrics that I can use on Linux and other *NIXy operating systems? (And can be interfaced from C/C++?)

推荐答案

除了 @ user964970 评论/解决方案,我建议使其与操作系统无关.

In addition to @user964970 comment/solution, I suggest making it OS agnostic.

使用诸如ACE或BOOST之类的与操作系统无关的API创建自己的库,并提供一个位于命名共享内存段内的命名信号写保护计数器.

Use an OS agnostic API, like ACE or BOOST, to create your own library, supplying a named-semaphore write-protected-counter, placed inside a named-shared-memory segment.

这应该是您图书馆的API:

This should be your library's API :

long * createCounter(const char * name); // Create a counter
                                         // Will create a named semaphore and a named
                                         // shared memory segment, holding the counter     
                                         // value. Will return pointer to counter
long * getCounter(const char * name); // Get existing counter pointer
                                      // in the calling process' address space
long incCounter(const char * name);   // increment existing counter

这篇关于Linux中的应用程序计数器? (和OSX?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆