Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've been playing with Performance Monitor in Windows 7 and have been able to create a data collector set that monitors a process and logs an alert when Private Bytes exceeds some threshold. I want to use this when we run certain tests as a crude catch for major memory leaks.

It seems like I have to start my application, then manually start the data collection set. Is there some way that the data collection set can just stay running, even when the process it monitors isn't running? If that's not possible, is there a way that I can tie the starting of the data collection set to the starting of my application?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

After poking around, I discovered that I can programmatically start the data collection set. My code looks something like this:

#include <pla.h>

void start_perfmon_data_collection_set(const wchar_t* dcs_name) 
{
    IDataCollectorSet* pdcs;
    HRESULT hr = CoCreateInstance(__uuidof(DataCollectorSet), 
                                  NULL, 
                                  CLSCTX_SERVER,
                                  __uuidof(IDataCollectorSet),
                                  (void**) &pdcs);

    if (FAILED(hr))
    {
        TRACE(L"CoCreateInstance(__uuidof(DataCollectorSet) failed with 0x%x.\n", hr);
        return;
    }

    if (FAILED(pdcs->Query(dcs_name, NULL)))
    {
        TRACE(L"unable to query %s\n", dcs_name);
    }
    else
    {
        if (FAILED(pdcs->Start(false)))
        {
            DataCollectorSetStatus status;
            pdcs->get_Status(&status);
            TRACE(L"status = %d\n", status);
        }
    }
    pdcs->Release();
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.