2022-03-21 01:51:45 +01:00
|
|
|
#pragma once
|
|
|
|
|
#ifndef _TAGLIALEGNA
|
|
|
|
|
#define _TAGLIALEGNA
|
|
|
|
|
|
2022-04-09 00:37:56 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
2022-05-07 21:16:35 +02:00
|
|
|
#include "fileQueue.h"
|
2022-03-21 01:51:45 +01:00
|
|
|
|
|
|
|
|
typedef struct taglia_s {
|
|
|
|
|
FILE *file;
|
|
|
|
|
size_t max_files;
|
|
|
|
|
long max_size;
|
|
|
|
|
size_t cache_misses;
|
2022-05-07 21:16:35 +02:00
|
|
|
pthread_mutex_t m; /* per sincronizzare le scritture al file */
|
2022-03-21 01:51:45 +01:00
|
|
|
} taglia_t;
|
|
|
|
|
|
2022-05-07 21:16:35 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Creates new instance
|
|
|
|
|
*
|
|
|
|
|
* @param file path to file to write into
|
|
|
|
|
* @param n number of optional parameters, in order:
|
|
|
|
|
* int max_files, int max_size, int cache_misses
|
|
|
|
|
* @return created istance, NULL if error
|
|
|
|
|
*/
|
2022-03-21 01:51:45 +01:00
|
|
|
taglia_t *taglia_init(char *file, int n, ...);
|
|
|
|
|
|
2022-05-07 21:16:35 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Deallocates instance
|
|
|
|
|
*
|
|
|
|
|
* @param taglia instance to deallocate
|
|
|
|
|
*/
|
2022-03-21 01:51:45 +01:00
|
|
|
void taglia_del(taglia_t *taglia);
|
|
|
|
|
|
2022-05-07 21:16:35 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Writes buffer to the log
|
|
|
|
|
*
|
|
|
|
|
* @param taglia
|
|
|
|
|
* @param buf NULL terminated string to write
|
|
|
|
|
* @return number of char written, -1 if error occurred
|
|
|
|
|
*/
|
2022-03-21 01:51:45 +01:00
|
|
|
size_t taglia_write(taglia_t *taglia, char *buf);
|
|
|
|
|
|
2022-05-07 21:16:35 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Writes buffer to the log with timestamp
|
|
|
|
|
*
|
|
|
|
|
* @param taglia
|
|
|
|
|
* @param buf NULL terminated string to write
|
|
|
|
|
* @return number of char written, -1 if error occurred
|
|
|
|
|
*/
|
2022-03-21 01:51:45 +01:00
|
|
|
size_t taglia_log(taglia_t *taglia, char *buf);
|
|
|
|
|
|
2022-05-07 21:16:35 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Updates statistics
|
|
|
|
|
*
|
|
|
|
|
* @param taglia
|
|
|
|
|
* @param queue structure that holds the files
|
|
|
|
|
* @param miss number of cache misses to add
|
|
|
|
|
* @return 1 if success, -1 if error occurred
|
|
|
|
|
*/
|
2022-03-21 01:51:45 +01:00
|
|
|
int taglia_update(taglia_t *taglia, queueT *queue, int miss);
|
|
|
|
|
|
2022-05-07 21:16:35 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Writes stats to the stream and to the log
|
|
|
|
|
*
|
|
|
|
|
* @param taglia
|
|
|
|
|
* @param stream
|
|
|
|
|
* @return 0 if success, -1 if error occurred
|
|
|
|
|
*/
|
2022-03-21 01:51:45 +01:00
|
|
|
int taglia_stats(taglia_t *taglia, FILE *stream);
|
|
|
|
|
|
|
|
|
|
#endif /* _TAGLIALEGNA */
|