<commit_before>/* This file contains information dump procedures. During the initialization 
 * of the Information Service 'known' function keys are registered at the TTY
 * server in order to receive a notification if one is pressed. Here, the 
 * corresponding dump procedure is called.  
 *
 * The entry points into this file are
 *   handle_fkey:	handle a function key pressed notification
 */


/* Several header files from the kernel are included here so that we can use
 * the constants, macros, and types needed to make the debugging dumps.
 */
#include "is.h"
#include <timers.h>
#include <string.h>
#include <ibm/interrupt.h>
#include "../../kernel/const.h"
#include "../../kernel/type.h"
#include "../../kernel/proc.h"
#include "../../kernel/sendmask.h"

#define click_to_round_k(n) \
	((unsigned) ((((unsigned long) (n) << CLICK_SHIFT) + 512) / 1024))


/* Declare some local dump procedures. */
FORWARD _PROTOTYPE( char *proc_name, (int proc_nr)		);
FORWARD _PROTOTYPE( void proctab_dmp, (void)			);
FORWARD _PROTOTYPE( void memmap_dmp, (void)			);
FORWARD _PROTOTYPE( void sendmask_dmp, (void)			);
FORWARD _PROTOTYPE( void image_dmp, (void)			);
FORWARD _PROTOTYPE( void irqtab_dmp, (void)			);
FORWARD _PROTOTYPE( void kmessages_dmp, (void)			);
FORWARD _PROTOTYPE( void diagnostics_dmp, (void)		);
FORWARD _PROTOTYPE( void sched_dmp, (void)			);
FORWARD _PROTOTYPE( void monparams_dmp, (void)			);
FORWARD _PROTOTYPE( void kenv_dmp, (void)			);
FORWARD _PROTOTYPE( void memchunks_dmp, (void)			);

/* Some global data that is shared among several dumping procedures. 
 * Note that the process table copy has the same name as in the kernel
 * so that most macros and definitions from proc.h also apply here.
 */
struct proc proc[NR_TASKS + NR_PROCS];
struct system_image image[IMAGE_SIZE];


/*===========================================================================*
 *				handle_fkey				     *
 *===========================================================================*/
PUBLIC int do_fkey_pressed(message *m)
{
#if DEAD_CODE
    if (F1 <= m->FKEY_CODE && m->FKEY_CODE <= F12) {
        switch(m->FKEY_CODE) {
#else
    if (F1 <= m->NOTIFY_ARG && m->NOTIFY_ARG <= F12) {
        switch(m->NOTIFY_ARG) {
#endif
            case  F1:	proctab_dmp();		break;
            case  F2:	memmap_dmp();		break;
            case  F3:	image_dmp();		break;
            case  F4:	sendmask_dmp();		break;
            case  F5:	monparams_dmp();	break;
            case  F6:	irqtab_dmp();		break;
            case  F7:	kmessages_dmp();	break;
            case  F9:	diagnostics_dmp();	break;
            case F10:	kenv_dmp();		break;
            case F11:	memchunks_dmp();	break;
            case F12:	sched_dmp();		break;
            default: 
#if DEAD_CODE
            	printf("IS: unhandled notification for F%d\n", m->FKEY_NUM);
#else
            	printf("IS: unhandled notify for F%d (code %d)\n", 
            		m->NOTIFY_FLAGS, m->NOTIFY_ARG);
#endif
        }
    }
    return(EDONTREPLY);
}


/*===========================================================================*
 *				diagnostics_dmp				     *
 *===========================================================================*/
PRIVATE void diagnostics_dmp()
{
  char print_buf[DIAG_BUF_SIZE+1];	/* buffer used to print */
  int start;				/* calculate start of messages */
  int size, r;

  /* Try to print the kernel messages. First determine start and copy the
   * buffer into a print-buffer. This is done because the messages in the
   * copy may wrap (the kernel buffer is circular).
   */
  start = ((diag_next + DIAG_BUF_SIZE) - diag_size) % DIAG_BUF_SIZE;
  r = 0;
  size = diag_size;
  while (size > 0) {
  	print_buf[r] = diag_buf[(start+r) % DIAG_BUF_SIZE];
  	r ++;
  	size --;
  }
  print_buf[r] = 0;		/* make sure it terminates */
  printf("Dump of diagnostics from device drivers and servers.\n\n"); 
  printf(print_buf);		/* print the messages */
}


/*===========================================================================*
 *				kmessages_dmp				     *
 *===========================================================================*/
PRIVATE void kmessages_dmp()
{
  struct kmessages kmess;		/* get copy of kernel messages */
  char print_buf[KMESS_BUF_SIZE+1];	/* this one is used to print */
  int next, size;			/* vars returned by sys_kmess() */
  int start;				/* calculate start of messages */
  int r;

  /* Try to get a copy of the kernel messages. */
  if ((r = sys_getkmessages(&kmess)) != OK) {
      report("warning: couldn't get copy of kmessages", r);
      return;
  }

  /* Try to print the kernel messages. First determine start and copy the
   * buffer into a print-buffer. This is done because the messages in the
   * copy may wrap (the kernel buffer is circular).
   */
  start = ((kmess.km_next + KMESS_BUF_SIZE) - kmess.km_size) % KMESS_BUF_SIZE;
  r = 0;
  while (kmess.km_size > 0) {
  	print_buf[r] = kmess.km_buf[(start+r) % KMESS_BUF_SIZE];
  	r ++;
  	kmess.km_size --;
  }
  print_buf[r] = 0;		/* make sure it terminates */
  printf("Dump of all messages generated by the kernel.\n\n"); 
  printf(print_buf);		/* print the messages */
}


/*===========================================================================*
 *				monparams_dmp				     *
 *===========================================================================*/
PRIVATE void monparams_dmp()
{
  char val[1024];
  char *e;
  int r;

  /* Try to get a copy of the boot monitor parameters. */
  if ((r = sys_getmonparams(val, sizeof(val))) != OK) {
      report("warning: couldn't get copy of monitor params", r);
      return;
  }

  /* Append new lines to the result. */<commit_msg>Able to dump lock()/unlock() timing data<commit_after>/* This file contains information dump procedures. During the initialization 
 * of the Information Service 'known' function keys are registered at the TTY
 * server in order to receive a notification if one is pressed. Here, the 
 * corresponding dump procedure is called.  
 *
 * The entry points into this file are
 *   handle_fkey:	handle a function key pressed notification
 */


/* Several header files from the kernel are included here so that we can use
 * the constants, macros, and types needed to make the debugging dumps.
 */
#include "is.h"
#include <timers.h>
#include <string.h>
#include <ibm/interrupt.h>
#include <minix/config.h>
#include "../../kernel/const.h"
#include "../../kernel/type.h"
#include "../../kernel/proc.h"
#include "../../kernel/sendmask.h"

#define click_to_round_k(n) \
	((unsigned) ((((unsigned long) (n) << CLICK_SHIFT) + 512) / 1024))


/* Declare some local dump procedures. */
FORWARD _PROTOTYPE( char *proc_name, (int proc_nr)		);
FORWARD _PROTOTYPE( void proctab_dmp, (void)			);
FORWARD _PROTOTYPE( void memmap_dmp, (void)			);
FORWARD _PROTOTYPE( void sendmask_dmp, (void)			);
FORWARD _PROTOTYPE( void image_dmp, (void)			);
FORWARD _PROTOTYPE( void irqtab_dmp, (void)			);
FORWARD _PROTOTYPE( void kmessages_dmp, (void)			);
FORWARD _PROTOTYPE( void diagnostics_dmp, (void)		);
FORWARD _PROTOTYPE( void sched_dmp, (void)			);
FORWARD _PROTOTYPE( void monparams_dmp, (void)			);
FORWARD _PROTOTYPE( void kenv_dmp, (void)			);
FORWARD _PROTOTYPE( void memchunks_dmp, (void)			);
#if ENABLE_LOCK_TIMING
FORWARD _PROTOTYPE( void timing_dmp, (void)			);
#endif

/* Some global data that is shared among several dumping procedures. 
 * Note that the process table copy has the same name as in the kernel
 * so that most macros and definitions from proc.h also apply here.
 */
struct proc proc[NR_TASKS + NR_PROCS];
struct system_image image[IMAGE_SIZE];


/*===========================================================================*
 *				handle_fkey				     *
 *===========================================================================*/
PUBLIC int do_fkey_pressed(message *m)
{
#if DEAD_CODE
    if (F1 <= m->FKEY_CODE && m->FKEY_CODE <= F12) {
        switch(m->FKEY_CODE) {
#else
    if (F1 <= m->NOTIFY_ARG && m->NOTIFY_ARG <= F12) {
        switch(m->NOTIFY_ARG) {
#endif
            case  F1:	proctab_dmp();		break;
            case  F2:	memmap_dmp();		break;
            case  F3:	image_dmp();		break;
            case  F4:	sendmask_dmp();		break;
            case  F5:	monparams_dmp();	break;
            case  F6:	irqtab_dmp();		break;
            case  F7:	kmessages_dmp();	break;
#if ENABLE_LOCK_TIMING
            case  F8:	timing_dmp();		break;
#endif
            case  F9:	diagnostics_dmp();	break;
            case F10:	kenv_dmp();		break;
            case F11:	memchunks_dmp();	break;
            case F12:	sched_dmp();		break;
            default: 
#if DEAD_CODE
            	printf("IS: unhandled notification for F%d\n", m->FKEY_NUM);
#else
            	printf("IS: unhandled notify for F%d (code %d)\n", 
            		m->NOTIFY_FLAGS, m->NOTIFY_ARG);
#endif
        }
    }
    return(EDONTREPLY);
}


/*===========================================================================*
 *				diagnostics_dmp				     *
 *===========================================================================*/
PRIVATE void diagnostics_dmp()
{
  char print_buf[DIAG_BUF_SIZE+1];	/* buffer used to print */
  int start;				/* calculate start of messages */
  int size, r;

  /* Try to print the kernel messages. First determine start and copy the
   * buffer into a print-buffer. This is done because the messages in the
   * copy may wrap (the kernel buffer is circular).
   */
  start = ((diag_next + DIAG_BUF_SIZE) - diag_size) % DIAG_BUF_SIZE;
  r = 0;
  size = diag_size;
  while (size > 0) {
  	print_buf[r] = diag_buf[(start+r) % DIAG_BUF_SIZE];
  	r ++;
  	size --;
  }
  print_buf[r] = 0;		/* make sure it terminates */
  printf("Dump of diagnostics from device drivers and servers.\n\n"); 
  printf(print_buf);		/* print the messages */
}

#if ENABLE_LOCK_TIMING
/*===========================================================================*
 *				timing_dmp				     *
 *===========================================================================*/
PRIVATE void timing_dmp()
{
  static struct lock_timedata timingdata[TIMING_CATEGORIES];
  int r, c, f, skipped = 0, printed = 0, maxlines = 23, x = 0;
  static int offsetlines = 0;

  if ((r = sys_getlocktimings(timingdata)) != OK) {
      report("warning: couldn't get copy of lock timings", r);
      return;
  } 

  for(c = 0; c < TIMING_CATEGORIES; c++) {
	int b;
	if(!timingdata[c].lock_timings_range[0] || !timingdata[c].binsize)
		continue;
	x = printf("%-*s: misses %lu, resets %lu, measurements %lu: ",
	TIMING_NAME, timingdata[c].names,
		timingdata[c].misses,
		timingdata[c].resets,
		timingdata[c].measurements);
	for(b = 0; b < TIMING_POINTS; b++) {
		int w;
		if(!timingdata[c].lock_timings[b])
			continue;
		x += (w = printf(" %5d: %5d", timingdata[c].lock_timings_range[0] +
			b*timingdata[c].binsize,
			timingdata[c].lock_timings[b]));
	 	if(x + w >= 80) { printf("\n"); x = 0; }
	}
  	if(x > 0) printf("\n");
  }
}
#endif

/*===========================================================================*
 *				kmessages_dmp				     *
 *===========================================================================*/
PRIVATE void kmessages_dmp()
{
  struct kmessages kmess;		/* get copy of kernel messages */
  char print_buf[KMESS_BUF_SIZE+1];	/* this one is used to print */
  int next, size;			/* vars returned by sys_kmess() */
  int start;				/* calculate start of messages */
  int r;

  /* Try to get a copy of the kernel messages. */
  if ((r = sys_getkmessages(&kmess)) != OK) {
      report("warning: couldn't get copy of kmessages", r);
      return;
  }

  /* Try to print the kernel messages. First determine start and copy the
   * buffer into a print-buffer. This is done because the messages in the
   * copy may wrap (the kernel buffer is circular).
   */
  start = ((kmess.km_next + KMESS_BUF_SIZE) - kmess.km_size) % KMESS_BUF_SIZE;
  r = 0;
  while (kmess.km_size > 0) {
  	print_buf[r] = kmess.km_buf[(start+r) % KMESS_BUF_SIZE];
  	r ++;
  	kmess.km_size --;
  }
  print_buf[r] = 0;		/* make sure it terminates */
  printf("Dump of all messages generated by the kernel.\n\n"); 
  printf("%s", print_buf);		/* print the messages */
}


/*===========================================================================*
 *				monparams_dmp				     *
 *===========================================================================*/
PRIVATE void monparams_dmp()
{
  char val[1024];
  char *e;
  int r;

  /* Try to get a copy of the boot monitor parameters. */
  if ((r = sys_getmonparams(val, sizeof(val))) != OK) {
      report("warning: couldn't get copy of monitor params", r);
      return;
  }

  /* Append new lines to the result. */
{'fraction_non_alphanumeric': 0.22251968503937009, 'fraction_numerical': 0.007480314960629921, 'mean_word_length': 3.4039528432732316, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 34, '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': '5784525', 'n_tokens_mistral': 4406, 'n_tokens_neox': 4084, 'n_words': 1202}