<commit_before>/**
 * Polls an energymon at the provided interval and writes the output to the
 * file specified.
 *
 * @author <NAME>
 * @date 2015-07-09
 */
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "energymon-default.h"
#include "energymon-time-util.h"

// set a minimum sleep time between polls
#ifndef ENERGYMON_MIN_INTERVAL_US
  #define ENERGYMON_MIN_INTERVAL_US 100000
#endif

static volatile int running = 1;

static void print_usage(const char* app) {
  fprintf(stderr, "Usage:\n");
  fprintf(stderr, "  %s <output_file>\n", app);
}

void shandle(int sig) {
  switch (sig) {
    case SIGTERM:
    case SIGINT:
#ifdef SIGQUIT
    case SIGQUIT:
#endif
#ifdef SIGKILL
    case SIGKILL:
#endif
#ifdef SIGHUP
    case SIGHUP:
#endif
      running = 0;
    default:
      break;
  }
}

int main(int argc, char** argv) {
  energymon em;
  uint64_t us;
  uint64_t energy;
  FILE* fout;
  int ret = 0;
  if (argc < 2) {
    print_usage(argv[0]);
    return 1;
  }

  // register the signal handler
  signal(SIGINT, shandle);

  // initialize the energy monitor
  if (energymon_get_default(&em) || em.finit(&em)) {
    return 1;
  }

  // open the output file
  fout = fopen(argv[1], "wb");
  if (fout == NULL) {
    perror("Failed to open output file");
    em.ffinish(&em);
    return 1;
  }

  // get the update interval
  us = em.finterval(&em);
  if (us < ENERGYMON_MIN_INTERVAL_US) {
    us = ENERGYMON_MIN_INTERVAL_US;
  }

  // update file at regular intervals
  while (running) {
    energy = em.fread(&em);<commit_msg>fopen with w+, not wb<commit_after>/**
 * Polls an energymon at the provided interval and writes the output to the
 * file specified.
 *
 * @author <NAME>
 * @date 2015-07-09
 */
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "energymon-default.h"
#include "energymon-time-util.h"

// set a minimum sleep time between polls
#ifndef ENERGYMON_MIN_INTERVAL_US
  #define ENERGYMON_MIN_INTERVAL_US 100000
#endif

static volatile int running = 1;

static void print_usage(const char* app) {
  fprintf(stderr, "Usage:\n");
  fprintf(stderr, "  %s <output_file>\n", app);
}

void shandle(int sig) {
  switch (sig) {
    case SIGTERM:
    case SIGINT:
#ifdef SIGQUIT
    case SIGQUIT:
#endif
#ifdef SIGKILL
    case SIGKILL:
#endif
#ifdef SIGHUP
    case SIGHUP:
#endif
      running = 0;
    default:
      break;
  }
}

int main(int argc, char** argv) {
  energymon em;
  uint64_t us;
  uint64_t energy;
  FILE* fout;
  int ret = 0;
  if (argc < 2) {
    print_usage(argv[0]);
    return 1;
  }

  // register the signal handler
  signal(SIGINT, shandle);

  // initialize the energy monitor
  if (energymon_get_default(&em) || em.finit(&em)) {
    return 1;
  }

  // open the output file
  fout = fopen(argv[1], "w+");
  if (fout == NULL) {
    perror("Failed to open output file");
    em.ffinish(&em);
    return 1;
  }

  // get the update interval
  us = em.finterval(&em);
  if (us < ENERGYMON_MIN_INTERVAL_US) {
    us = ENERGYMON_MIN_INTERVAL_US;
  }

  // update file at regular intervals
  while (running) {
    energy = em.fread(&em);
{'fraction_non_alphanumeric': 0.1311124694376528, 'fraction_numerical': 0.01650366748166259, 'mean_word_length': 3.245136186770428, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 21, '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': '4420051', 'n_tokens_mistral': 1296, 'n_tokens_neox': 1236, 'n_words': 343}