Coder Social home page Coder Social logo

winprocessinfo's Introduction

WinProcessInfo : Sample Windows process information

CodeQL Build Status

Objective

Provide for a simple "stats" for a daemon/service without the heft of the full process information library.

  • Minimal footprint
  • Serializer for nlohmann::json (you must include the library prior to this header file)
  • Serializer for std::format (if supported by your compiler)

Requirements

  • We use nlohmann::json only in our tests and the library is aware to provide a conversion operator if library is detected.
  • We use std::format if present

Usage

Interface

WinProcessInfo
- uptime()
- snapshot()
- serializer for nlohmann::json
- serializer for std::format

Example

#include "gtest/gtest.h"
#include <format>
#include "nlohmann/json.hpp"
#include "siddiqsoft/WinProcessInfo.hpp"

TEST(examples, Example2)
{
   try {
      siddiqsoft::WinProcessInfo procInfo;

      // We must perform the snapshot to obtain memory and thread usage
      procInfo.snapshot();

      // tip: do not use brace-init/assignment as it will create an array instead of object!
      nlohmann::json info(procInfo);

      std::cerr << info.dump() << std::endl;
      EXPECT_EQ(GetCurrentProcessId(), info.value("processId", 0));
   }
   catch (std::exception& e) {
      EXPECT_TRUE(false) << e.what(); // if we throw then the test fails.
   }
}

Output

Member Field json Field Comments
cpuCores cpuCount Number of cores/cpu
cpuHandles cpuHandles Handle count
cpuThreads cpuThreads Thread count. This is expensive.
memPeakWorkingSet memPeakWorkingSet Peak virtual working memory in Kbytes.
memWorkingSet memWorkingSet Current working set in Kbytes.
memPrivate memPrivate Current physically allocated memory for this process in Kbytes.
nameHostname hostname The local hostname
nameDomainName domain The fully qualified domain portion
nameHostnamePhysical localFqdn The local physical hostname
nameFqdn fqdn The fully qualified dns name
processId processId The process id
timeStartup timeStartup The startup timestamp as ISO 8601 format. This is the time of instance of this object.
  timeCurrent The current timestamp as ISO 8601 format when the serialization took place.
  uptime The number of microseconds between the timeStartup and timeCurrent.
Use the method uptime() and duration_cast<> to your desired ratio.
{
    "cpuCores": 8,
    "cpuHandles": 48,
    "cpuThreads": 4,
    "domain": "",
    "fqdn": "istanbul",
    "hostname": "istanbul",
    "localFqdn": "istanbul",
    "memPeakWorkingSet": 42960, // KBytes
    "memPrivateBytes": 84452,   // Kbytes
    "memWorkingSet": 42584,     // Kbytes
    "processId": 10828,
    "timeCurrent": "2021-07-30T06:43:54.8649027Z",
    "timeStartup": "2021-07-30T06:43:54.8599558Z",
    "uptime": 5124              // Microseconds
}

© 2021 Siddiq Software LLC. All rights reserved.

winprocessinfo's People

Contributors

abdulkareem-siddiq avatar keiichi-morisato avatar

winprocessinfo's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.