<commit_before>// System Includes
#include <sys/time.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <math.h>

// Foreign includes
#include "readproc.h"
#include "sysinfo.h"
#include "escape.h"

// Local Includes
#include "Screen.h"
#include "MatrixColumn.h"
#include "PSModule.h"

PSModule::PSModule()
{
	pthread_mutex_init(&_lock, NULL);
	pthread_cond_init(&_cond, NULL);
}

PSModule::~PSModule()
{
	pthread_mutex_destroy(&_lock);
	pthread_cond_destroy(&_cond);
}

// AbstractModule Interface specification
void PSModule::processchar (int c)
{
	pthread_mutex_lock(&_lock);
	_charqueue.push_back(c);
	pthread_cond_signal(&_cond);
	pthread_mutex_unlock(&_lock);
}


AbstractModule * PSModule::execute(Screen & scr, std::vector<MatrixColumn *> & MClist)
{
	// FILE * log = fopen ("PSMatrix.log", "w+");
	// Seed the MC maps
	int i = 0;
	for (std::vector<MatrixColumn *>::iterator MCitr = MClist.begin();
			MCitr != MClist.end();
			MCitr++)
	{
		// Mark odd columns as unassigned (NULL)
		if (++i % 2)
			_MC_Proc_map.insert(std::pair < MatrixColumn *, Proc * > (*MCitr, NULL));
	}

	bool firstloop = true;
	///////////////////////
	// Main processing loop
	///////////////////////
	struct timeval oldtimev;
	struct timeval timev;
	_terminate = false;
	while (!_terminate)
	{
		// Figure out the elapsed time
		gettimeofday(&timev, NULL);
		float elapsed = (float) (timev.tv_sec - oldtimev.tv_sec)
			+ (float) (timev.tv_usec - oldtimev.tv_usec) / 1000000.0;
		oldtimev.tv_sec = timev.tv_sec;
		oldtimev.tv_usec = timev.tv_usec;
		float timescale = 100.0f / ((float)Hertz * (float)elapsed);

		// Clear speed sorted list
		_cpu_Proc_map.clear();
		// Scan the list and mark everyone as old and dead
		for (std::map<int, Proc>::iterator procitr = _pid_Proc_map.begin();
				procitr != _pid_Proc_map.end();
				procitr++)
		{
			//fprintf (log, "Mark OldDead: %d\n",procitr->first);
			assert (procitr->first == procitr->second._ptsk->tid);
			procitr->second._pnew = false;
			procitr->second._palive = false;
			procitr->second._cpu = 0;
		}

		// Do proc list processing
		PROCTAB* PT = openproc(PROC_FILLARG|PROC_FILLCOM|PROC_FILLMEM|PROC_FILLSTAT);
		proc_t * ptsk;
		while ( (ptsk = readproc(PT, NULL)) )
		{
			if (ptsk->cmdline == NULL)
			{
				free (ptsk);
				continue;
			}
			// Look up proc in Full list
			std::map <int, Proc>::iterator procitr = _pid_Proc_map.find(ptsk->tid);
			// if doesn't exist
			if (procitr == _pid_Proc_map.end())
			{
				procitr = _pid_Proc_map.insert(std::pair<int, Proc>(ptsk->tid,Proc(ptsk))).first;
				char cmd[1024];
				int cmdlen = 1024;
				escape_command(cmd,procitr->second._ptsk,1024,&cmdlen,ESC_ARGS);
				snprintf (procitr->second._buf, 1024, "%d %s *** ",
						procitr->second._ptsk->tid,
						cmd);
				//fprintf (log, "Mark New: %d\n",procitr->first);
			} else
			// if exists<commit_msg>	Make user info show up in drop string.<commit_after>// System Includes
#include <sys/time.h>
#include <unistd.h>
#include <stdio.h>
#include <signal.h>
#include <math.h>

// Foreign includes
#include "readproc.h"
#include "sysinfo.h"
#include "escape.h"

// Local Includes
#include "Screen.h"
#include "MatrixColumn.h"
#include "PSModule.h"

PSModule::PSModule()
{
	pthread_mutex_init(&_lock, NULL);
	pthread_cond_init(&_cond, NULL);
}

PSModule::~PSModule()
{
	pthread_mutex_destroy(&_lock);
	pthread_cond_destroy(&_cond);
}

// AbstractModule Interface specification
void PSModule::processchar (int c)
{
	pthread_mutex_lock(&_lock);
	_charqueue.push_back(c);
	pthread_cond_signal(&_cond);
	pthread_mutex_unlock(&_lock);
}


AbstractModule * PSModule::execute(Screen & scr, std::vector<MatrixColumn *> & MClist)
{
	// FILE * log = fopen ("PSMatrix.log", "w+");
	// Seed the MC maps
	int i = 0;
	for (std::vector<MatrixColumn *>::iterator MCitr = MClist.begin();
			MCitr != MClist.end();
			MCitr++)
	{
		// Mark odd columns as unassigned (NULL)
		if (++i % 2)
			_MC_Proc_map.insert(std::pair < MatrixColumn *, Proc * > (*MCitr, NULL));
	}

	bool firstloop = true;
	///////////////////////
	// Main processing loop
	///////////////////////
	struct timeval oldtimev;
	struct timeval timev;
	_terminate = false;
	while (!_terminate)
	{
		// Figure out the elapsed time
		gettimeofday(&timev, NULL);
		float elapsed = (float) (timev.tv_sec - oldtimev.tv_sec)
			+ (float) (timev.tv_usec - oldtimev.tv_usec) / 1000000.0;
		oldtimev.tv_sec = timev.tv_sec;
		oldtimev.tv_usec = timev.tv_usec;
		float timescale = 100.0f / ((float)Hertz * (float)elapsed);

		// Clear speed sorted list
		_cpu_Proc_map.clear();
		// Scan the list and mark everyone as old and dead
		for (std::map<int, Proc>::iterator procitr = _pid_Proc_map.begin();
				procitr != _pid_Proc_map.end();
				procitr++)
		{
			//fprintf (log, "Mark OldDead: %d\n",procitr->first);
			assert (procitr->first == procitr->second._ptsk->tid);
			procitr->second._pnew = false;
			procitr->second._palive = false;
			procitr->second._cpu = 0;
		}

		// Do proc list processing
		PROCTAB* PT = openproc(PROC_FILLARG|PROC_FILLCOM|PROC_FILLUSR|PROC_FILLSTAT);
		proc_t * ptsk;
		while ( (ptsk = readproc(PT, NULL)) )
		{
			if (ptsk->cmdline == NULL)
			{
				free (ptsk);
				continue;
			}
			// Look up proc in Full list
			std::map <int, Proc>::iterator procitr = _pid_Proc_map.find(ptsk->tid);
			// if doesn't exist
			if (procitr == _pid_Proc_map.end())
			{
				procitr = _pid_Proc_map.insert(std::pair<int, Proc>(ptsk->tid,Proc(ptsk))).first;
				char cmd[1024];
				int cmdlen = 1024;
				escape_command(cmd,procitr->second._ptsk,1024,&cmdlen,ESC_ARGS);
				snprintf (procitr->second._buf, 1024, "%d %s %s *** ",
						procitr->second._ptsk->tid,
						procitr->second._ptsk->euser,
						cmd);
				//fprintf (log, "Mark New: %d\n",procitr->first);
			} else
			// if exists
{'fraction_non_alphanumeric': 0.17283525563780341, 'fraction_numerical': 0.010673093475641247, 'mean_word_length': 3.585635359116022, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3589671', 'n_tokens_mistral': 2454, 'n_tokens_neox': 2209, 'n_words': 459}