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.

117 lines
1.9 KiB

  1. /*++
  2. Copyright (c) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. stats.c
  5. Abstract:
  6. routines for PS statistics
  7. Author:
  8. Yoram Bernet (yoramb) 23-May-1998
  9. Rajesh Sundaram (rajeshsu) 01-Aug-1998
  10. Environment:
  11. Kernel Mode
  12. Revision History:
  13. --*/
  14. #include "psched.h"
  15. #pragma hdrstop
  16. /* External */
  17. /* Static */
  18. /* Forward */
  19. /* End Forward */
  20. NDIS_STATUS
  21. CreateAveragingArray(
  22. OUT PRUNNING_AVERAGE *RunningAverage,
  23. IN ULONG ArraySize
  24. )
  25. {
  26. PRUNNING_AVERAGE runningAverage;
  27. ULONG i;
  28. PsAllocatePool(runningAverage,
  29. sizeof(RUNNING_AVERAGE),
  30. PsMiscTag);
  31. if(!runningAverage)
  32. {
  33. *RunningAverage = NULL;
  34. return(NDIS_STATUS_RESOURCES);
  35. }
  36. PsAllocatePool(runningAverage->Elements,
  37. ArraySize * sizeof(ULONG),
  38. PsMiscTag);
  39. if(!runningAverage->Elements)
  40. {
  41. PsFreePool(runningAverage);
  42. *RunningAverage = NULL;
  43. return(NDIS_STATUS_RESOURCES);
  44. }
  45. for(i=0; i < ArraySize; i++){
  46. runningAverage->Elements[i] = 0;
  47. }
  48. runningAverage->Index = 0;
  49. runningAverage->Sum = 0;
  50. runningAverage->Size = ArraySize;
  51. *RunningAverage = runningAverage;
  52. return(NDIS_STATUS_SUCCESS);
  53. }
  54. ULONG
  55. RunningAverage(
  56. IN PRUNNING_AVERAGE RunningAverage,
  57. IN ULONG NewValue
  58. )
  59. {
  60. ULONG i;
  61. i = RunningAverage->Index;
  62. RunningAverage->Sum -= RunningAverage->Elements[i];
  63. RunningAverage->Sum += NewValue;
  64. RunningAverage->Elements[i] = NewValue;
  65. if(++i == RunningAverage->Size){
  66. i = 0;
  67. }
  68. RunningAverage->Index = i;
  69. return((RunningAverage->Sum)/(RunningAverage->Size));
  70. }
  71. VOID
  72. DeleteAveragingArray(
  73. PRUNNING_AVERAGE RunningAverage
  74. )
  75. {
  76. PsFreePool(RunningAverage->Elements);
  77. PsFreePool(RunningAverage);
  78. }
  79. /* End stats.c */