Skip to content

Instantly share code, notes, and snippets.

@cyring
Last active May 16, 2019 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyring/cba5abfa6bcf6829cc6a04e90d8f0801 to your computer and use it in GitHub Desktop.
Save cyring/cba5abfa6bcf6829cc6a04e90d8f0801 to your computer and use it in GitHub Desktop.
Client: Idle States
Give more room to the Kernel window do display the idle states parameters
@cyring
Copy link
Author

cyring commented May 16, 2019

REASON_CODE SysInfoKernel(Window *win, CUINT width, CELL_FUNC OutFunc)
{
	REASON_INIT(reason);
	size_t	len = KMAX(1 + width,
			1 + 16 + (8 * Shm->SysGate.IdleDriver.stateCount));
	char	*item = NULL, *str = NULL;
	int	idx = 0;

  if ((item = malloc(len)) == NULL) {
	REASON_SET(reason, RC_MEM_ERR);
  } else if ((str = malloc(len)) == NULL) {
	REASON_SET(reason, RC_MEM_ERR);
	free(item);
  } else
  {
/* Section Mark */
	PUT(SCANKEY_NULL, RSC(SYSINFO_KERNEL).ATTR(), width, 0,
		"%s:", Shm->SysGate.sysname);

	PUT(SCANKEY_NULL, RSC(KERNEL_RELEASE).ATTR(), width, 2,
		"%s%.*s[%s]", RSC(KERNEL_RELEASE).CODE(),
		width - 5 - RSZ(KERNEL_RELEASE)- strlen(Shm->SysGate.release),
		hSpace, Shm->SysGate.release);

	PUT(SCANKEY_NULL, RSC(KERNEL_VERSION).ATTR(), width, 2,
		"%s%.*s[%s]", RSC(KERNEL_VERSION).CODE(),
		width - 5 - RSZ(KERNEL_VERSION) - strlen(Shm->SysGate.version),
		hSpace, Shm->SysGate.version);

	PUT(SCANKEY_NULL, RSC(KERNEL_MACHINE).ATTR(), width, 2,
		"%s%.*s[%s]", RSC(KERNEL_MACHINE).CODE(),
		width - 5 - RSZ(KERNEL_MACHINE) - strlen(Shm->SysGate.machine),
		hSpace, Shm->SysGate.machine);
/* Section Mark */
	PUT(SCANKEY_NULL, RSC(KERNEL_MEMORY).ATTR(), width, 0,
		"%s:%.*s", RSC(KERNEL_MEMORY).CODE(),
		width - 1 - RSZ(KERNEL_MEMORY), hSpace);

	len = sprintf(str, "%lu", Shm->SysGate.memInfo.totalram);
	PUT(SCANKEY_NULL, RSC(KERNEL_TOTAL_RAM).ATTR(), width, 2,
		"%s%.*s" "%s KB", RSC(KERNEL_TOTAL_RAM).CODE(),
		width - 6 - RSZ(KERNEL_TOTAL_RAM) - len, hSpace, str);

	len = sprintf(str, "%lu", Shm->SysGate.memInfo.sharedram);
	GridCall(PUT(SCANKEY_NULL, RSC(KERNEL_SHARED_RAM).ATTR(), width, 2,
			"%s%.*s" "%s KB", RSC(KERNEL_SHARED_RAM).CODE(),
			width - 6 - RSZ(KERNEL_SHARED_RAM) - len, hSpace, str),
		KernelUpdate, &Shm->SysGate.memInfo.sharedram);

	len = sprintf(str, "%lu", Shm->SysGate.memInfo.freeram);
	GridCall(PUT(SCANKEY_NULL, RSC(KERNEL_FREE_RAM).ATTR(), width, 2,
			"%s%.*s" "%s KB", RSC(KERNEL_FREE_RAM).CODE(),
			width - 6 - RSZ(KERNEL_FREE_RAM) - len, hSpace, str),
		KernelUpdate, &Shm->SysGate.memInfo.freeram);

	len = sprintf(str, "%lu", Shm->SysGate.memInfo.bufferram);
	GridCall(PUT(SCANKEY_NULL, RSC(KERNEL_BUFFER_RAM).ATTR(), width, 2,
			"%s%.*s" "%s KB", RSC(KERNEL_BUFFER_RAM).CODE(),
			width - 6 - RSZ(KERNEL_BUFFER_RAM) - len, hSpace, str),
		KernelUpdate, &Shm->SysGate.memInfo.bufferram);

	len = sprintf(str, "%lu", Shm->SysGate.memInfo.totalhigh);
	GridCall(PUT(SCANKEY_NULL, RSC(KERNEL_TOTAL_HIGH).ATTR(), width, 2,
			"%s%.*s" "%s KB", RSC(KERNEL_TOTAL_HIGH).CODE(),
			width - 6 - RSZ(KERNEL_TOTAL_HIGH) - len, hSpace, str),
		KernelUpdate, &Shm->SysGate.memInfo.totalhigh);

	len = sprintf(str, "%lu", Shm->SysGate.memInfo.freehigh);
	GridCall(PUT(SCANKEY_NULL, RSC(KERNEL_FREE_HIGH).ATTR(), width, 2,
			"%s%.*s" "%s KB", RSC(KERNEL_FREE_HIGH).CODE(),
			width - 6 - RSZ(KERNEL_FREE_HIGH) - len, hSpace, str),
		KernelUpdate, &Shm->SysGate.memInfo.freehigh);
/* Section Mark */
    if ((len = strlen(Shm->SysGate.IdleDriver.Name)
		+ strlen(Shm->SysGate.IdleDriver.Governor)) > 0)
    {
	PUT(SCANKEY_NULL, RSC(KERNEL_IDLE_DRIVER).ATTR(), width, 0,
		"%s%.*s[%s@%s]", RSC(KERNEL_IDLE_DRIVER).CODE(),
		width - 3 - RSZ(KERNEL_IDLE_DRIVER) - len, hSpace,
		Shm->SysGate.IdleDriver.Governor, Shm->SysGate.IdleDriver.Name);
/* Row Mark */
	sprintf(item, "%s:%.*s", RSC(KERNEL_STATE).CODE(),
			10 - (int) RSZ(KERNEL_STATE), hSpace);
      for (idx = 0; idx < Shm->SysGate.IdleDriver.stateCount; idx++)
      {
	sprintf(str, "%-8.*s", 8,
		Shm->SysGate.IdleDriver.State[idx].Name);
	strcat(item, str);
      }
	PUT(SCANKEY_NULL, RSC(KERNEL_STATE).ATTR(), width, 3,
		 "%.*s", width - (OutFunc == NULL ? 6 : 3), item);
/* Row Mark */
	sprintf(item, "%.*s", 11, hSpace);
      for (idx = 0; idx < Shm->SysGate.IdleDriver.stateCount; idx++)
      {
	sprintf(str, "%-8.*s", 8,
		Shm->SysGate.IdleDriver.State[idx].Desc);
	strcat(item, str);
      }
	PUT(SCANKEY_NULL, RSC(KERNEL_STATE).ATTR(), width, 3,
		"%.*s", width - (OutFunc == NULL ? 6 : 3), item);
/* Row Mark */
	sprintf(item, "%s:%.*s", RSC(KERNEL_POWER).CODE(),
			10 - (int) RSZ(KERNEL_POWER), hSpace);
      for (idx = 0; idx < Shm->SysGate.IdleDriver.stateCount;idx++ )
      {
	sprintf(str, "%-8d",
		Shm->SysGate.IdleDriver.State[idx].powerUsage);
	strcat(item, str);
      }
	PUT(SCANKEY_NULL, RSC(KERNEL_POWER).ATTR(), width, 3,
		"%.*s", width - (OutFunc == NULL ? 6 : 3), item);
/* Row Mark */
	sprintf(item, "%s:%.*s", RSC(KERNEL_LATENCY).CODE(),
			10 - (int) RSZ(KERNEL_LATENCY), hSpace);
      for (idx = 0; idx < Shm->SysGate.IdleDriver.stateCount; idx++)
      {
	sprintf(str, "%-8u",
		Shm->SysGate.IdleDriver.State[idx].exitLatency);
	strcat(item, str);
      }
	PUT(SCANKEY_NULL, RSC(KERNEL_LATENCY).ATTR(), width, 3,
		"%.*s", width - (OutFunc == NULL ? 6 : 3), item);
/* Row Mark */
	sprintf(item, "%s:%.*s", RSC(KERNEL_RESIDENCY).CODE(),
			10 - (int) RSZ(KERNEL_RESIDENCY), hSpace);
      for (idx = 0; idx < Shm->SysGate.IdleDriver.stateCount; idx++)
      {
	sprintf(str, "%-8u",
		Shm->SysGate.IdleDriver.State[idx].targetResidency);
	strcat(item, str);
      }
	PUT(SCANKEY_NULL, RSC(KERNEL_RESIDENCY).ATTR(), width, 3,
		"%.*s", width - (OutFunc == NULL ? 6 : 3), item);
    }
	free(item);
	free(str);
  }
	return(reason);
}

2019-05-16-102249_644x316_scrot

$ corefreq-cli -k
Linux:                                                                          
|- Release                                                 [5.0.13-arch1-1-ARCH]
|- Version                          [#1 SMP PREEMPT Sun May 5 18:05:41 UTC 2019]
|- Machine                                                              [x86_64]
Memory:                                                                         
|- Total RAM                                                         32854252 KB
|- Shared RAM                                                           13204 KB
|- Free RAM                                                          31595684 KB
|- Buffer RAM                                                           57364 KB
|- Total High                                                               0 KB
|- Free High                                                                0 KB
Idle driver                                                    [@corefreqk-idle]
   |- State:     POLL    C1      C1E     C3      C6      C7      C8      C9     
   |-            CPUIDLE SKL-C1  SKL-C1E SKL-C3  SKL-C6  SKL-C7  SKL-C8  SKL-C9 
   |- Power:     -1      0       0       0       0       0       0       0      
   |- Latency:   0       2       10      70      85      124     200     480    
   |- Residency: 0       2       20      100     200     800     800     5000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment