<commit_before>/* gp-events.c -- Event operations
--  Copyright (C) 2011, 2012, 2013 <NAME>
--  Written by <NAME> (<EMAIL>)
--
--  Licensed under the Apache License, Version 2.0 (the "License");
--  you may not use this file except in compliance with the License.
--  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--  Unless required by applicable law or agreed to in writing, software
--  distributed under the License is distributed on an "AS IS" BASIS,
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--  See the License for the specific language governing permissions and
--  limitations under the License.
*/
#include "gp-config.h"
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include "gp-probe.h"
#include "gp-events.h"

void
gp_send_attributes (const struct gp_event_def *type)
{
  gp_uint8 len = strlen(type->name);
  gp_uint16 val = type->type;
  const struct gp_attr_def *attr;
  int i;
  
  gp_write ("BLOCK", 0, &len, sizeof (len));
  gp_write ("EVENT", 2, type->name, len);
  gp_write ("ID", 2, &val, sizeof (val));

  len = type->nr_attrs;
  gp_write ("COUNT", 2, &len, sizeof (len));

  attr = type->attributes;
  for (i = type->nr_attrs; --i >= 0; attr++)
    {
      len = strlen (attr->name);
      val = attr->size;
      gp_write ("A-LEN", 4, &len, sizeof (len));
      gp_write ("A-NAME", 4, attr->name, len);
      gp_write ("A-TYPE", 4, &val, sizeof (val));
    }
}

static int
gp_get_attribute_size (const struct gp_event_def *type)
{
  int result = sizeof (gp_uint8);
  const struct gp_attr_def *attr;
  int i;

  result += strlen (type->name);
  result += sizeof (gp_uint16);
  result += sizeof (gp_uint8);

  attr = type->attributes;
  for (i = type->nr_attrs; --i >= 0; attr++)
    {
      result += sizeof (gp_uint8) + sizeof (gp_uint16);
      result += strlen (attr->name);
    }
  
  return result;
}

void
gp_event_send (struct gp_probe *gp, int size,
               const struct gp_event_def *type, ...)
{
  gp_uint16 len;
  gp_uint16 val;
  const struct gp_attr_def *attr;
  int i;
  va_list argp;

  len = sizeof (gp_uint16)
    + size
    + gp_remote_sizeof_probe (gp);

  val = type->type;
  gp_write ("PROBE", 0, &len, sizeof (len));
  gp_write (type->name, 2, &val, sizeof (val));
  gp_remote_send_probe (gp);
  
  va_start (argp, type);
  attr = type->attributes;
  for (i = type->nr_attrs; --i >= 0; attr++)
    {
      union u
        {
          gp_uint8 u8;
          gp_uint16 u16;
          gp_uint32 u32;
          gp_uint64 u64;
      } u;
      
      switch (attr->size)
        {
        case 1:
          u.u8 = va_arg (argp, gp_uint8_varg);
          gp_write (attr->name, 4, &u.u8, sizeof (gp_uint8));
          break;

        case 2:
          u.u16 = va_arg (argp, gp_uint16_varg);
          gp_write (attr->name, 4, &u.u16, sizeof (gp_uint16));
          break;
          
        case 4:
          u.u32 = va_arg (argp, gp_uint32);
          gp_write (attr->name, 4, &u.u32, sizeof (gp_uint32));
          break;

        case 8:
          u.u64 = va_arg (argp, gp_uint64);
          gp_write (attr->name, 4, &u.u64, sizeof (gp_uint64));
          break;

        default:
          break;
        }
    }
  va_end (argp);
}

const struct gp_attr_def gp_malloc_attrs[] = {
  { "pointer", GP_TYPE_POINTER, sizeof (void*) },
  { "size",    GP_TYPE_SIZE_T,  sizeof (size_t) }
};

const struct gp_event_def gp_event_malloc_def = {
  "malloc",
  GP_EVENT_MALLOC,
  2,
  gp_malloc_attrs
};

void
gp_event_malloc (struct gp_probe *gp, void *p, size_t size)<commit_msg>Write a new line after each event (debug mode)<commit_after>/* gp-events.c -- Event operations
--  Copyright (C) 2011, 2012, 2013 <NAME>
--  Written by <NAME> (<EMAIL>)
--
--  Licensed under the Apache License, Version 2.0 (the "License");
--  you may not use this file except in compliance with the License.
--  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--  Unless required by applicable law or agreed to in writing, software
--  distributed under the License is distributed on an "AS IS" BASIS,
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--  See the License for the specific language governing permissions and
--  limitations under the License.
*/
#include "gp-config.h"
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include "gp-probe.h"
#include "gp-events.h"

void
gp_send_attributes (const struct gp_event_def *type)
{
  gp_uint8 len = strlen(type->name);
  gp_uint16 val = type->type;
  const struct gp_attr_def *attr;
  int i;
  
  gp_write ("BLOCK", 0, &len, sizeof (len));
  gp_write ("EVENT", 2, type->name, len);
  gp_write ("ID", 2, &val, sizeof (val));

  len = type->nr_attrs;
  gp_write ("COUNT", 2, &len, sizeof (len));

  attr = type->attributes;
  for (i = type->nr_attrs; --i >= 0; attr++)
    {
      len = strlen (attr->name);
      val = attr->size;
      gp_write ("A-LEN", 4, &len, sizeof (len));
      gp_write ("A-NAME", 4, attr->name, len);
      gp_write ("A-TYPE", 4, &val, sizeof (val));
    }
}

static int
gp_get_attribute_size (const struct gp_event_def *type)
{
  int result = sizeof (gp_uint8);
  const struct gp_attr_def *attr;
  int i;

  result += strlen (type->name);
  result += sizeof (gp_uint16);
  result += sizeof (gp_uint8);

  attr = type->attributes;
  for (i = type->nr_attrs; --i >= 0; attr++)
    {
      result += sizeof (gp_uint8) + sizeof (gp_uint16);
      result += strlen (attr->name);
    }
  
  return result;
}

void
gp_event_send (struct gp_probe *gp, int size,
               const struct gp_event_def *type, ...)
{
  gp_uint16 len;
  gp_uint16 val;
  const struct gp_attr_def *attr;
  int i;
  va_list argp;

  len = sizeof (gp_uint16)
    + size
    + gp_remote_sizeof_probe (gp);

  val = type->type;
  gp_write ("PROBE", 0, &len, sizeof (len));
  gp_write (type->name, 2, &val, sizeof (val));
  gp_remote_send_probe (gp);
  
  va_start (argp, type);
  attr = type->attributes;
  for (i = type->nr_attrs; --i >= 0; attr++)
    {
      union u
        {
          gp_uint8 u8;
          gp_uint16 u16;
          gp_uint32 u32;
          gp_uint64 u64;
      } u;
      
      switch (attr->size)
        {
        case 1:
          u.u8 = va_arg (argp, gp_uint8_varg);
          gp_write (attr->name, 4, &u.u8, sizeof (gp_uint8));
          break;

        case 2:
          u.u16 = va_arg (argp, gp_uint16_varg);
          gp_write (attr->name, 4, &u.u16, sizeof (gp_uint16));
          break;
          
        case 4:
          u.u32 = va_arg (argp, gp_uint32);
          gp_write (attr->name, 4, &u.u32, sizeof (gp_uint32));
          break;

        case 8:
          u.u64 = va_arg (argp, gp_uint64);
          gp_write (attr->name, 4, &u.u64, sizeof (gp_uint64));
          break;

        default:
          break;
        }
    }
  va_end (argp);
  write (STDERR_FILENO, "\n", 1);
}

const struct gp_attr_def gp_malloc_attrs[] = {
  { "pointer", GP_TYPE_POINTER, sizeof (void*) },
  { "size",    GP_TYPE_SIZE_T,  sizeof (size_t) }
};

const struct gp_event_def gp_event_malloc_def = {
  "malloc",
  GP_EVENT_MALLOC,
  2,
  gp_malloc_attrs
};

void
gp_event_malloc (struct gp_probe *gp, void *p, size_t size)
{'fraction_non_alphanumeric': 0.14107656485412956, 'fraction_numerical': 0.026160799890425968, 'mean_word_length': 2.5343659244917713, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6780962', 'n_tokens_mistral': 2834, 'n_tokens_neox': 2615, 'n_words': 761}