summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@samsung.com>2016-03-06 14:40:04 +0200
committerDaniel Zaoui <daniel.zaoui@samsung.com>2016-03-06 14:40:04 +0200
commitf8a7001395061ce9aa2cf90ec725df20f125f402 (patch)
tree89fefae0689115b36a704482b1ff7959a3d3af46
parent8d159c77ef178bdf1a395f7ba88a193d3f8a4bc4 (diff)
Add CSV format support
-rw-r--r--src/bin/espion_stats_format.c18
-rw-r--r--src/lib/stats_common.c33
-rw-r--r--src/lib/stats_common.h9
3 files changed, 40 insertions, 20 deletions
diff --git a/src/bin/espion_stats_format.c b/src/bin/espion_stats_format.c
index 5553b38..03e915c 100644
--- a/src/bin/espion_stats_format.c
+++ b/src/bin/espion_stats_format.c
@@ -7,12 +7,6 @@
7#include "stats_common.h" 7#include "stats_common.h"
8#include "eolian_common.h" 8#include "eolian_common.h"
9 9
10typedef enum
11{
12 NO_FORMAT,
13 EET_FORMAT
14} Format;
15
16Stat_Infos main_infos; 10Stat_Infos main_infos;
17 11
18static void 12static void
@@ -78,7 +72,7 @@ main(int argc, char **argv)
78 Stat_Info *info; 72 Stat_Info *info;
79 Eina_Bool help = EINA_FALSE, init = EINA_FALSE; 73 Eina_Bool help = EINA_FALSE, init = EINA_FALSE;
80 const char *output = NULL; 74 const char *output = NULL;
81 Format f = NO_FORMAT; 75 Stats_Output_Format f = STATS_NO_FORMAT;
82 eina_init(); 76 eina_init();
83 77
84 struct option opts[] = { 78 struct option opts[] = {
@@ -104,16 +98,17 @@ main(int argc, char **argv)
104 break; 98 break;
105 case 'f': 99 case 'f':
106 printf("Format: %s\n", optarg); 100 printf("Format: %s\n", optarg);
107 if (!strcmp(optarg, "eet")) f = EET_FORMAT; 101 if (!strcmp(optarg, "eet")) f = STATS_EET_FORMAT;
102 if (!strcmp(optarg, "csv")) f = STATS_CSV_FORMAT;
108 break; 103 break;
109 default: 104 default:
110 help = EINA_TRUE; 105 help = EINA_TRUE;
111 break; 106 break;
112 } 107 }
113 108
114 if (f == NO_FORMAT || help || !output) 109 if (f == STATS_NO_FORMAT || help || !output)
115 { 110 {
116 printf("Usage: %s [-h/--help] [-i/--init] --format/-f html/eet/ppt/xlsx --output/-o outfile file.eet ... \n", argv[0]); 111 printf("Usage: %s [-h/--help] [-i/--init] --format/-f html/eet/csv --output/-o outfile file.eet ... \n", argv[0]);
117 printf(" --init/-i Initializes the output with default values for all the Eo functions\n"); 112 printf(" --init/-i Initializes the output with default values for all the Eo functions\n");
118 printf(" --help/-h Print that help\n"); 113 printf(" --help/-h Print that help\n");
119 printf(" --output/-o Force output filename to 'outfile'\n"); 114 printf(" --output/-o Force output filename to 'outfile'\n");
@@ -145,7 +140,8 @@ main(int argc, char **argv)
145 } 140 }
146 } 141 }
147 142
148 stats_save(&main_infos, output); 143
144 stats_save(&main_infos, output, f);
149 EINA_LIST_FREE(main_infos.l, info) 145 EINA_LIST_FREE(main_infos.l, info)
150 { 146 {
151 free(info); 147 free(info);
diff --git a/src/lib/stats_common.c b/src/lib/stats_common.c
index 5ce2b5c..db5d7e3 100644
--- a/src/lib/stats_common.c
+++ b/src/lib/stats_common.c
@@ -8,7 +8,7 @@ static Eet_Data_Descriptor *_info_edd = NULL;
8static Eet_Data_Descriptor *_infos_edd = NULL; 8static Eet_Data_Descriptor *_infos_edd = NULL;
9 9
10static void 10static void
11_init() 11_eet_init()
12{ 12{
13 Eet_Data_Descriptor_Class eddc; 13 Eet_Data_Descriptor_Class eddc;
14 14
@@ -29,20 +29,37 @@ _init()
29} 29}
30 30
31Eina_Bool 31Eina_Bool
32stats_save(Stat_Infos *infos, const char *filename) 32stats_save(Stat_Infos *infos, const char *filename, Stats_Output_Format format)
33{ 33{
34 _init(); 34 Eina_Bool ret = EINA_TRUE;
35 Eet_File *file = eet_open(filename, EET_FILE_MODE_WRITE); 35 if (format == STATS_EET_FORMAT)
36 int ret = eet_data_write(file, _infos_edd, _EET_ENTRY, infos, EINA_TRUE); 36 {
37 eet_close(file); 37 _eet_init();
38 return !!ret; 38 Eet_File *file = eet_open(filename, EET_FILE_MODE_WRITE);
39 int nb = eet_data_write(file, _infos_edd, _EET_ENTRY, infos, EINA_TRUE);
40 eet_close(file);
41 ret = !!nb;
42 }
43 if (format == STATS_CSV_FORMAT)
44 {
45 FILE *fp = fopen(filename, "w");
46 Eina_List *itr;
47 Stat_Info *info;
48 fprintf(fp, "API,Counter\n");
49 EINA_LIST_FOREACH(infos->l, itr, info)
50 {
51 fprintf(fp, "%s,%lld\n", info->api_name, info->counter);
52 }
53 fclose(fp);
54 }
55 return ret;
39} 56}
40 57
41Stat_Infos * 58Stat_Infos *
42stats_load(const char *filename) 59stats_load(const char *filename)
43{ 60{
44 Stat_Infos *ret = NULL; 61 Stat_Infos *ret = NULL;
45 _init(); 62 _eet_init();
46 Eet_File *file = eet_open(filename, EET_FILE_MODE_READ); 63 Eet_File *file = eet_open(filename, EET_FILE_MODE_READ);
47 if (file) 64 if (file)
48 { 65 {
diff --git a/src/lib/stats_common.h b/src/lib/stats_common.h
index 94ac7f7..b3eb254 100644
--- a/src/lib/stats_common.h
+++ b/src/lib/stats_common.h
@@ -1,5 +1,12 @@
1#include <Eina.h> 1#include <Eina.h>
2 2
3typedef enum
4{
5 STATS_NO_FORMAT,
6 STATS_EET_FORMAT,
7 STATS_CSV_FORMAT
8} Stats_Output_Format;
9
3typedef struct 10typedef struct
4{ 11{
5 unsigned long long counter; 12 unsigned long long counter;
@@ -12,7 +19,7 @@ typedef struct
12} Stat_Infos; 19} Stat_Infos;
13 20
14Eina_Bool 21Eina_Bool
15stats_save(Stat_Infos *infos, const char *filename); 22stats_save(Stat_Infos *infos, const char *filename, Stats_Output_Format format);
16 23
17Stat_Infos * 24Stat_Infos *
18stats_load(const char *filename); 25stats_load(const char *filename);