在C ++中使用Perflib 2.0 - 示例和帮助 [英] Using Perflib 2.0 in C++ - examples and help

查看:86
本文介绍了在C ++中使用Perflib 2.0 - 示例和帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在尝试用C ++编写一个使用PERFLIB 2.0性能计数器的程序。我写了一个简单的xml清单,其中包含3个计数器 - 一个计数器,一个平均基数和一个平均计时器。我编译了它们,将它们包含在代码中。

I am trying to write a program in C++ that uses performance counters with PERFLIB 2.0. I wrote a simple xml manifest which contains 3 counters - a counter, an average base and an average timer. I compiled them, included them in the code.

现在,我正在尝试实际使用它们 - 但我似乎无法设置平均计数器的值 - 它一直在扔我87错误(参数不正确),即使我非常确定参数是否正常 - 我使用它们,上面一行,设置
基本计数器,并且工作正常。

Now, I am trying to actually use them - but I seem to be unable to set the value of the average counter - It keeps throwing me the 87 error (incorrect parameter), even though I'm pretty sure the parameters are OK - I use them, one line above, to set the base counter, and that works fine.

我已经在互联网上获取了文档,任何类型的例子或帮助 - 但除了本网站上的文章之外没有任何内容,这些文章非常高级且相当无益,而且没有任何内容代码示例。有一些C#,
的文档,但这对我没有帮助。

I've scored the internet for documentation, for any kind of examples or help - but there isn't anything except the articles on this site, which are very high-level and rather unhelpful, and there aren't any code samples. There is some documentation for C#, but that doesn't help me.

以下是相关代码:

XML文件:

<!-- <?xml version="1.0" encoding="UTF-16"?> -->
<instrumentationManifest     
    xmlns="http://schemas.microsoft.com/win/2004/08/events" 
    xmlns:win="http://manifests.microsoft.com/win/2004/08/windows/events"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"    
    >
    <instrumentation>
        <counters xmlns="http://schemas.microsoft.com/win/2005/12/counters" schemaVersion="1.1">
            <provider callback = "custom"
	      symbol="TestCounters"
              applicationIdentity = "TestCounters.exe"
              providerType = "userMode"
              providerGuid = "{ab8e1320-965a-4cf9-9c07-fe25378c2a23}">
                <counterSet guid = "{f72fdf55-eaa6-45ba-bf6d-4c7cb0d6ef73}"
                  uri = "Microsoft.Windows.System.PerfCounters.TestCounterSet"
                  name = "Counters Test"
		              symbol="CountersTest"
                  description = "Test of Counters"
                  instances = "single">
                    <counter id = "1"
                      uri = "Microsoft.Windows.System.PerfCounters.TestCounterSet.opTimeBase"
                      name = "Operation Time base"
                      description = "Count Operation Time Average"
                      type = "perf_average_base"
                      detailLevel = "standard"
                      defaultScale = "1">
                    </counter>
                    <counter id = "2"
                      uri = "Microsoft.Windows.System.PerfCounters.TestCounterSet.opTime"
                      name = "Operation Time"
                      description = "Count Operation Time"
		                  type = "perf_average_timer"
		                  baseID = "1"
		                  detailLevel = "standard">
                    </counter>
                    <counter id = "3"
                      uri = "Microsoft.Windows.System.PerfCounters.TestCounterSet.countOps"
                      name = "Count operations"
                      description = "operations count."
                      type = "perf_counter_counter"
                      detailLevel = "standard"
                      defaultScale = "1">
                      <counterAttributes>
                        <counterAttribute name = "reference" />
                      </counterAttributes>
                    </counter>
                </counterSet>
            </provider>
        </counters>
    </instrumentation>
</instrumentationManifest>







我的代码:

...

	ULONG countOps = 0;  // The by-reference counter variable
	double countAverageDuration ;
	ULONG res;
	res = PerfAutoInitialize();

	if (res != ERROR_SUCCESS)
		throw string("Failed to initialize");

	PPERF_COUNTERSET_INSTANCE cinst = PerfCreateInstance(
		hProvider, 
		&CounterSet_GUID, 
		L"My First Counters", 
		1);

	if (cinst == NULL)
		throw string("Could not create counter instance");

	res = PerfSetCounterRefValue(
		hProvider,
		cinst,
		3,
		&countOps
		);

	if (res != ERROR_SUCCESS) {

		throw string("Could not set counter ref value!");
	}


	srand(time(NULL));

	while (true) {
		int ops = rand() % 100000 + 2000;

		for (int i = 0; i < ops; i++) {
			countOps++;

			int duration = rand() % 1000;

			// Increase the base

			res = PerfIncrementULongCounterValue(hProvider, cinst, 1, 1);
			if (res != ERROR_SUCCESS)
				throw string("Could not increment base average counter");

			// Increase the average -- this line keeps throwing error 87

			res = PerfIncrementULongCounterValue(hProvider, cinst, 2, duration);

			if (res != ERROR_SUCCESS)
				throw string("Could not increment average counter");

			BlaBla(duration);
		}

		if (ops == 2000) break;
	}

	PerfDeleteInstance(hProvider, cinst);

	PerfStopProvider(hProvider);
	return 0;

请帮助!

谢谢,

G。







推荐答案

您好Gimelit,

Hi Gimelit,

我想将此主题移至Windows Performance Toolkit(WPT)v5论坛以获得更好的效果支持。

I'd like to move this thread to Windows Performance Toolkit (WPT) v5 forum for better support.

感谢您的理解。

祝你好运,

Thanks for your understanding.
Best regards,


这篇关于在C ++中使用Perflib 2.0 - 示例和帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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