<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 <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "energymon.h"

// set a minimum sleep time between polls
#ifndef ENERGYMON_MIN_INTERVAL_US
  #define ENERGYMON_MIN_INTERVAL_US 1000
#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 dummy) {
  running = 0;
}

int main(int argc, char** argv) {
  em_impl impl;
  unsigned long long us;
  struct timespec ts;
  unsigned long long energy;
  FILE* fout;
  if (argc < 2) {
    print_usage(argv[0]);
    return 1;
  }

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

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

  // initialize the energy monitor
  if (em_impl_get(&impl) || impl.finit(&impl)) {
    fclose(fout);
    return 1;
  }

  // get the update interval
  us = impl.finterval(&impl);
  if (us < ENERGYMON_MIN_INTERVAL_US) {
    us = ENERGYMON_MIN_INTERVAL_US;
  }
  ts.tv_sec = us / 1000000;
  ts.tv_nsec = (us % 1000000) * 1000;

  // update file at regular intervals
  while (running) {
    energy = impl.fread(&impl);
    rewind(fout);
    if(fprintf(fout, "%llu\n", energy) < 0) {<commit_msg>Initialize reader before opening output file<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 <limits.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "energymon.h"

// set a minimum sleep time between polls
#ifndef ENERGYMON_MIN_INTERVAL_US
  #define ENERGYMON_MIN_INTERVAL_US 1000
#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 dummy) {
  running = 0;
}

int main(int argc, char** argv) {
  em_impl impl;
  unsigned long long us;
  struct timespec ts;
  unsigned long long energy;
  FILE* fout;
  if (argc < 2) {
    print_usage(argv[0]);
    return 1;
  }

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

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

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

  // get the update interval
  us = impl.finterval(&impl);
  if (us < ENERGYMON_MIN_INTERVAL_US) {
    us = ENERGYMON_MIN_INTERVAL_US;
  }
  ts.tv_sec = us / 1000000;
  ts.tv_nsec = (us % 1000000) * 1000;

  // update file at regular intervals
  while (running) {
    energy = impl.fread(&impl);
    rewind(fout);
    if(fprintf(fout, "%llu\n", energy) < 0) {
{'fraction_non_alphanumeric': 0.13553826199740596, 'fraction_numerical': 0.02529182879377432, 'mean_word_length': 3.388335704125178, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 19, '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': '2928891', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1128, 'n_words': 323}