diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/evas/src/bin/evas_cserve_tool.c | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/libraries/evas/src/bin/evas_cserve_tool.c b/libraries/evas/src/bin/evas_cserve_tool.c new file mode 100644 index 0000000..acaa703 --- /dev/null +++ b/libraries/evas/src/bin/evas_cserve_tool.c | |||
@@ -0,0 +1,160 @@ | |||
1 | #ifdef HAVE_CONFIG_H | ||
2 | # include "config.h" | ||
3 | #endif | ||
4 | |||
5 | #include "evas_cs.h" | ||
6 | |||
7 | int _cserve_tool_log_dom = -1; | ||
8 | |||
9 | int | ||
10 | main(int argc, char **argv) | ||
11 | { | ||
12 | int i; | ||
13 | |||
14 | evas_init(); | ||
15 | if (!evas_cserve_init()) | ||
16 | { | ||
17 | printf("ERROR: Cannot connect to cserve. abort\n"); | ||
18 | exit(-1); | ||
19 | } | ||
20 | |||
21 | for (i = 1; i < argc; i++) | ||
22 | { | ||
23 | if ((!strcmp(argv[i], "-h")) || | ||
24 | (!strcmp(argv[i], "-help")) || | ||
25 | (!strcmp(argv[i], "--help"))) | ||
26 | { | ||
27 | printf("Options:\n" | ||
28 | "\t-h This help\n" | ||
29 | "\tgetconfig Get configuration values\n" | ||
30 | "\tsetconfig CSIZE CTIME CTIMECHECK Set the config values\n" | ||
31 | "\tgetstats Get current cache statistics\n" | ||
32 | "\tgetinfo Get current cache content info\n" | ||
33 | ); | ||
34 | exit(0); | ||
35 | } | ||
36 | else if ((!strcmp(argv[i], "getconfig"))) | ||
37 | { | ||
38 | Op_Getconfig_Reply config; | ||
39 | |||
40 | if (!evas_cserve_raw_config_get(&config)) | ||
41 | { | ||
42 | printf("ERROR: cannot fetch config.\n"); | ||
43 | exit(-1); | ||
44 | } | ||
45 | printf("-REPLY-\n"); | ||
46 | printf("csize: %i\n", config.cache_max_usage); | ||
47 | printf("ctime: %i\n", config.cache_item_timeout); | ||
48 | printf("ctimecheck: %i\n", config.cache_item_timeout_check); | ||
49 | printf("-OK-\n"); | ||
50 | } | ||
51 | else if ((!strcmp(argv[i], "setconfig")) && (i < (argc - 3))) | ||
52 | { | ||
53 | Op_Setconfig config; | ||
54 | |||
55 | i++; | ||
56 | config.cache_max_usage = atoi(argv[i]); | ||
57 | i++; | ||
58 | config.cache_item_timeout = atoi(argv[i]); | ||
59 | i++; | ||
60 | config.cache_item_timeout_check = atoi(argv[i]); | ||
61 | if (!evas_cserve_raw_config_set(&config)) | ||
62 | { | ||
63 | printf("ERROR: cannot set config.\n"); | ||
64 | exit(-1); | ||
65 | } | ||
66 | } | ||
67 | else if ((!strcmp(argv[i], "getstats"))) | ||
68 | { | ||
69 | Op_Getstats_Reply stats; | ||
70 | |||
71 | if (!evas_cserve_raw_stats_get(&stats)) | ||
72 | { | ||
73 | printf("ERROR: cannot fetch stats.\n"); | ||
74 | exit(-1); | ||
75 | } | ||
76 | printf("-REPLY-\n"); | ||
77 | printf("saved_memory: %i Kb\n", stats.saved_memory / 1024); | ||
78 | printf("wasted_memory: %i Kb\n", stats.wasted_memory / 1024); | ||
79 | printf("saved_memory_peak: %i Kb\n", stats.saved_memory_peak / 1024); | ||
80 | printf("wasted_memory_peak: %i Kb\n", stats.wasted_memory_peak / 1024); | ||
81 | printf("saved_time_image_header_load: %1.3f sec\n", stats.saved_time_image_header_load); | ||
82 | printf("saved_time_image_data_load: %1.3f sec\n", stats.saved_time_image_data_load); | ||
83 | printf("-OK-\n"); | ||
84 | } | ||
85 | else if ((!strcmp(argv[i], "getinfo"))) | ||
86 | { | ||
87 | Op_Getinfo_Reply *info; | ||
88 | unsigned char *p; | ||
89 | int h, j; | ||
90 | |||
91 | info = evas_cserve_raw_info_get(); | ||
92 | if (!info) | ||
93 | { | ||
94 | printf("ERROR: cannot fetch info.\n"); | ||
95 | exit(-1); | ||
96 | } | ||
97 | j = info->active.count + info->cached.count; | ||
98 | printf("-REPLY-\n"); | ||
99 | printf("active_count: %i\n", info->active.count); | ||
100 | printf("active_memory: %i Kb\n", info->active.mem_total); | ||
101 | printf("cache_count: %i\n", info->cached.count); | ||
102 | printf("cache_memory: %i Kb\n", info->cached.mem_total); | ||
103 | p = (unsigned char *)info; | ||
104 | p += sizeof(Op_Getinfo_Reply); | ||
105 | for (h = 0; h < j; h++) | ||
106 | { | ||
107 | Op_Getinfo_Item it; | ||
108 | char *file, *key, buf[512]; | ||
109 | struct tm *ltm; | ||
110 | |||
111 | memcpy(&it, p, sizeof(Op_Getinfo_Item)); | ||
112 | file = (char*) (p + sizeof(Op_Getinfo_Item)); | ||
113 | key = file + strlen(file) + 1; | ||
114 | printf("-IMAGE- [#%i]\n", h); | ||
115 | printf(" file : %s\n", file); | ||
116 | printf(" key : %s\n", key); | ||
117 | printf(" size : %i x %i\n", it.w, it.h); | ||
118 | printf(" active : %i\n", (int)it.active); | ||
119 | printf(" memory used: %i bytes (%i Kb)\n", it.memory_footprint, (it.memory_footprint + 1023) / 1024); | ||
120 | printf(" has alpha : %i\n", (int)it.alpha); | ||
121 | printf(" data loaded: %i\n", (int)it.data_loaded); | ||
122 | printf(" dead : %i\n", (int)it.dead); | ||
123 | printf(" useless : %i\n", (int)it.useless); | ||
124 | printf(" image refs : %i\n", it.refcount); | ||
125 | printf(" data refs : %i\n", it.data_refcount); | ||
126 | printf(" header load: %1.5f sec\n", it.head_load_time); | ||
127 | printf(" data load : %1.5f sec\n", it.data_load_time); | ||
128 | if (it.cached_time == 0) | ||
129 | printf(" cached at : N/A\n"); | ||
130 | else | ||
131 | { | ||
132 | ltm = localtime(&(it.cached_time)); | ||
133 | if (ltm) | ||
134 | { | ||
135 | strftime(buf, sizeof(buf), "%Y.%m.%d %T", ltm); | ||
136 | printf(" cached at : %s\n", buf); | ||
137 | } | ||
138 | } | ||
139 | ltm = localtime(&(it.file_mod_time)); | ||
140 | if (ltm) | ||
141 | { | ||
142 | strftime(buf, sizeof(buf), "%Y.%m.%d %T", ltm); | ||
143 | printf(" file mod at: %s\n", buf); | ||
144 | } | ||
145 | ltm = localtime(&(it.file_checked_time)); | ||
146 | if (ltm) | ||
147 | { | ||
148 | strftime(buf, sizeof(buf), "%Y.%m.%d %T", ltm); | ||
149 | printf(" file check : %s\n", buf); | ||
150 | } | ||
151 | p += sizeof(Op_Getinfo_Item) + it.file_key_size; | ||
152 | } | ||
153 | free(info); | ||
154 | printf("-OK-\n"); | ||
155 | } | ||
156 | } | ||
157 | evas_cserve_shutdown(); | ||
158 | evas_shutdown(); | ||
159 | return 0; | ||
160 | } | ||