⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 perfgen.cpp

📁 EVC4.rar
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//**********************************************************************
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//**********************************************************************

/*++
Module Name:

    perfgen.c

Abstract:

    This file implements an Extensible Performance Object that displays
    the Tick Count from the Windows CE device

--*/

//
//  Include Files
//

#include <windows.h>
#include <string.h>
#include <winperf.h>
#include <math.h>
#include <tchar.h>
#include <stdio.h>
#include "genctrs.h" // error message definition
#include "perfmsg.h"
#include "perfutil.h"
#include "datagen.h"

//----------------------------------------------------------------------
// TODO: Include the header that defines the data structure that contains
//       the information retrieved by the device.
//----------------------------------------------------------------------
#include "CETickStructs.h"
#include "GetTickData.h"

#include "cemgr.h"

#include "cemgrui.h"
#include "cemgrui_i.c"

#include <initguid.h>
#include "rds.h"

IConnection *g_piConnection = NULL;
IConnectionStream *g_piStream = NULL;

HRESULT
Initialize();

//  define constant value counter's value here, any number will do.

#define CONSTANT_VALUE_VALUE    49

//----------------------------------------------------------------------
// TODO:  Declare extern data definition
//----------------------------------------------------------------------
//  References to constants which initialize the Object type definitions
//
extern CE_TICKSTATS_DATA_DEFINITION CE_TickStats_DataDefinition;

DWORD   dwOpenCount = 0;        // count of "Open" threads
BOOL    bInitOK = FALSE;        // true = DLL initialized OK

//
//  Function Prototypes
//
//      these are used to insure that the data collection functions
//      accessed by Perflib will have the correct calling format.
//
interface IUnknown;
typedef HRESULT (APIENTRY PM_SET_CONN)(IUnknown*);

//----------------------------------------------------------------------
// TODO:  Declare the aliases for the standard function names.  These
//        are the functions listed in CETickStats.cpp
//----------------------------------------------------------------------
PM_SET_CONN     SetITLConnectionCETickStats;
PM_OPEN_PROC    OpenCETickStats;
PM_COLLECT_PROC CollectCETickStats;
PM_CLOSE_PROC   CloseCETickStats;

static
DWORD
GetTimeInMilliSeconds ()
{
    SYSTEMTIME  st;
    DWORD       dwReturn;

    GetSystemTime (&st);
    dwReturn = (DWORD)st.wMilliseconds;
    dwReturn += (DWORD)st.wSecond * 1000L;
    dwReturn += (DWORD)st.wMinute * 60000L;
    dwReturn += (DWORD)st.wHour * 3600000L;
    dwReturn += (DWORD)st.wDay * 86500000L;

    // that's good enough for what it's for

    return dwReturn;
}

//----------------------------------------------------------------------
// TODO:  This is the real function that implements the SetITLConnection
//        function.  In general, this function can remain as is.
//----------------------------------------------------------------------
HRESULT APIENTRY
SetITLConnectionCETickStats(
    IUnknown *pUnk
    )

/*++

Routine Description:

    This routine will retrieve the IConnection interface pointer needed
    by the Platform Manager APIs.

Arguments:

    The IUnknown interface pointer to the IConnection object

Return Value:

    S_OK : if successful.

--*/

{
    HRESULT hr = E_NOINTERFACE;
    g_piStream = NULL;
    g_piConnection = NULL;

	// get the device manager interface
	IRDSDeviceManager* piDeviceManager = NULL;
    if (pUnk)
    {
        hr = pUnk->QueryInterface(IID_IRDSDeviceManager, (void **)&piDeviceManager);
    }

	// get the remote device and platform guid we are connected to
	GUID gdPlatform={0}, gdDevice={0};
	if (SUCCEEDED(hr) && piDeviceManager)
	{
		hr = piDeviceManager->GetConnectionIDs(&gdPlatform, &gdDevice);
	}

	// get the IRemoteDevice* interface based on the device guid we got above
	IRemoteDevice* piDevice = NULL;
	if (SUCCEEDED(hr))
	{
		IPlatformManager* piPlatman = NULL;
		hr = ::CoCreateInstance(CLSID_PlatformManager,
						NULL,
						CLSCTX_ALL,
						IID_IPlatformManager,
						(void **)&piPlatman);
		if (SUCCEEDED(hr) && piPlatman)
		{
			IPlatformCE* piPlatform = NULL;
			hr = piPlatman->GetPlatform(gdPlatform, &piPlatform);
			if (SUCCEEDED(hr) && piPlatform)
			{
				hr = piPlatform->GetDevice(gdDevice, &piDevice);
			}
			if (piPlatform)
			{
				piPlatform->Release();
				piPlatform = NULL;
			}
		}
		if (piPlatman)
		{
			piPlatman->Release();
			piPlatman = NULL;
		}
	}

	IPlatformManagerUI *piPlatManUI = NULL;
	if (SUCCEEDED(hr) && piDevice)
	{
		// get the IConnection interface
		hr = ::CoCreateInstance(CLSID_PlatformManagerUI,
								NULL,
								CLSCTX_INPROC_SERVER,
								IID_IPlatformManagerUI,
								(void **)&piPlatManUI);
	}
	if (SUCCEEDED(hr) && piPlatManUI)
	{
		hr = piPlatManUI->Connect(NULL,
								piDevice,
								&g_piConnection);
	}

	if (piPlatManUI)
	{
		piPlatManUI->Release();
		piPlatManUI = NULL;
	}
	if (piDeviceManager)
	{
		piDeviceManager->Release();
		piDeviceManager = NULL;
	}

    return hr;
}


//----------------------------------------------------------------------
// TODO: This is the Open function.
//----------------------------------------------------------------------
DWORD APIENTRY
OpenCETickStats(
    LPWSTR lpDeviceNames
    )

/*++

Routine Description:

    This routine will initialize the data structures used to pass
    data back to the registry

Arguments:

    Pointer to object ID of each device to be opened (PerfGen)

Return Value:

    None.

--*/

{
    LONG status;
    HKEY hKeyDriverPerf;
    DWORD size;
    DWORD type;
    DWORD dwFirstCounter;
    DWORD dwFirstHelp;

    //
    //  Since WINLOGON is multi-threaded and will call this routine in
    //  order to service remote performance queries, this library
    //  must keep track of how many times it has been opened (i.e.
    //  how many threads have accessed it). the registry routines will
    //  limit access to the initialization routine to only one thread
    //  at a time so synchronization (i.e. reentrancy) should not be
    //  a problem
    //


    if (!dwOpenCount) {
        // open Eventlog interface

        hEventLog = MonOpenEventLog();

        // get counter and help index base values from registry
        //      Open key to registry entry
        //      read First Counter and First Help values
        //      update static data strucutures by adding base to
        //          offset value in structure.

        //--------------------------------------------------------------
        // TODO: Replace parameter 2 with the appropriate subkey name
        //--------------------------------------------------------------
        status = RegOpenKeyEx (
            HKEY_LOCAL_MACHINE,
            "SYSTEM\\CurrentControlSet\\Services\\CETickStats_420\\Performance",
            0L,
            KEY_READ,
            &hKeyDriverPerf);

        if (status != ERROR_SUCCESS) {
            REPORT_ERROR_DATA (GENPERF_UNABLE_OPEN_DRIVER_KEY, LOG_USER,
                &status, sizeof(status));
            // this is fatal, if we can't get the base values of the
            // counter or help names, then the names won't be available
            // to the requesting application  so there's not much
            // point in continuing.
            goto OpenExitPoint;
        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -