Ignore:
Timestamp:
Dec 1, 1999, 7:40:49 PM (26 years ago)
Author:
sandervl
Message:

added GetProcessTimes + several fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/oslibdos.cpp

    r1914 r1924  
    1 /* $Id: oslibdos.cpp,v 1.11 1999-12-01 10:47:51 sandervl Exp $ */
     1/* $Id: oslibdos.cpp,v 1.12 1999-12-01 18:40:48 sandervl Exp $ */
    22
    33/*
     
    2323#include "initterm.h"
    2424#include "oslibdos.h"
     25#include "dosqss.h"
    2526
    2627APIRET APIENTRY DosAliasMem(PVOID pb, ULONG cb, PPVOID ppbAlias, ULONG fl);
     
    548549}
    549550//******************************************************************************
    550 //******************************************************************************
     551//Returns time spent in kernel & user mode in milliseconds
     552//******************************************************************************
     553BOOL OSLibDosQueryProcTimes(DWORD procid, ULONG *kerneltime, ULONG *usertime)
     554{
     555 APIRET rc;
     556 char *buf;
     557 ULONG size;
     558 ULONG nrthreads = 4;
     559
     560tryagain:
     561  size = sizeof(QTOPLEVEL)+sizeof(QGLOBAL)+sizeof(QPROCESS) + nrthreads*sizeof(QTHREAD);
     562  buf = (char *)malloc(size);
     563  rc = DosQuerySysState(0x1, RESERVED, procid, RESERVED, (PCHAR)buf, size);
     564
     565  if(rc) {
     566        free(buf);
     567        if(rc == ERROR_BUFFER_OVERFLOW) {
     568                nrthreads += 4;
     569                goto tryagain;
     570        }
     571        return FALSE;
     572  }
     573  PQTOPLEVEL top = (PQTOPLEVEL)buf;
     574
     575  *kerneltime = 0;
     576  *usertime = 0;
     577  for(int i=0;i<top->procdata->threadcnt;i++) {
     578        *kerneltime += top->procdata->threads[i].systime;
     579        *usertime   += top->procdata->threads[i].usertime;
     580  }
     581  free(buf);
     582  return TRUE;
     583}
     584//******************************************************************************
     585//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.