Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. Wperf.c
  5. Abstract:
  6. Win32 application to display performance statictics.
  7. Author:
  8. Ken Reneris
  9. Environment:
  10. console
  11. --*/
  12. //
  13. // set variable to define global variables
  14. //
  15. #include <nt.h>
  16. #include <ntrtl.h>
  17. #include <nturtl.h>
  18. #include <windows.h>
  19. #include <errno.h>
  20. #include <malloc.h>
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. //
  24. // global handles
  25. //
  26. UCHAR Usage[] = "ec: r addr len\n w addr value";
  27. HANDLE DriverHandle;
  28. UCHAR Buffer[256];
  29. //
  30. // Prototypes
  31. //
  32. BOOLEAN
  33. InitDriver ();
  34. int
  35. __cdecl
  36. main(USHORT argc, CHAR **argv)
  37. {
  38. BOOLEAN Write;
  39. ULONG Offset, Value;
  40. ULONG l, bw;
  41. //
  42. // Locate pentium perf driver
  43. //
  44. if (!InitDriver ()) {
  45. printf ("acpiec.sys is not installed\n");
  46. exit (1);
  47. }
  48. //
  49. // Check args
  50. //
  51. if (argc < 3) {
  52. printf (Usage);
  53. exit (1);
  54. }
  55. switch (argv[1][0]) {
  56. case 'r': Write = FALSE; break;
  57. case 'w': Write = TRUE; break;
  58. default: printf (Usage); exit(1);
  59. }
  60. Offset = atoi(argv[2]);
  61. if (Offset > 255) {
  62. printf ("ec: Offset must be 0-255\n");
  63. exit (1);
  64. }
  65. Value = atoi(argv[3]);
  66. if (Value > 255) {
  67. printf ("ec: len/value must be 0-255\n");
  68. exit (1);
  69. }
  70. l = SetFilePointer (DriverHandle, Offset, NULL, FILE_BEGIN);
  71. if (l == -1) {
  72. printf ("ec: Could not set file pointer\n");
  73. exit (1);
  74. }
  75. if (Write) {
  76. if (!WriteFile(DriverHandle, &Value, 1, &bw, NULL)) {
  77. printf ("ec: Write error\n");
  78. exit (1);
  79. }
  80. } else {
  81. if (!ReadFile(DriverHandle, Buffer, Value, &bw, NULL)) {
  82. printf ("ec: Read error\n");
  83. exit (1);
  84. }
  85. for (l=0; l < Value; l++) {
  86. printf ("%3d: %d\n", Offset + l, Buffer[l]);
  87. }
  88. }
  89. return 0;
  90. }
  91. BOOLEAN
  92. InitDriver ()
  93. {
  94. UNICODE_STRING DriverName;
  95. NTSTATUS status;
  96. OBJECT_ATTRIBUTES ObjA;
  97. IO_STATUS_BLOCK IOSB;
  98. SYSTEM_BASIC_INFORMATION BasicInfo;
  99. PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION PPerfInfo;
  100. int i;
  101. RtlInitUnicodeString(&DriverName, L"\\Device\\ACPIEC");
  102. InitializeObjectAttributes(
  103. &ObjA,
  104. &DriverName,
  105. OBJ_CASE_INSENSITIVE,
  106. 0,
  107. 0 );
  108. status = NtOpenFile (
  109. &DriverHandle, // return handle
  110. SYNCHRONIZE | FILE_READ_DATA | FILE_WRITE_DATA, // desired access
  111. &ObjA, // Object
  112. &IOSB, // io status block
  113. FILE_SHARE_READ | FILE_SHARE_WRITE, // share access
  114. FILE_SYNCHRONOUS_IO_ALERT // open options
  115. );
  116. return NT_SUCCESS(status) ? TRUE : FALSE;
  117. }