summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2013-08-20 18:26:02 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2013-10-28 15:47:14 +0900
commit1e4ee656a0c44cbf915e124aa59c50fdde9f0973 (patch)
treebceb1a7ff13916bca910349d06ac8b777db4b885 /src/bin
parentdf31807329ca500eb579d538abe9f21208426934 (diff)
evas/cserve2: Fix cserve2_usage tool
Also, print shared arrays usage as it is sent as first message upon connection to the server. Add fonts to LRU and flush LRU as needed. Seems to work okay. Could probably be finetuned a bit.
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/evas/evas_cserve2.h1
-rw-r--r--src/bin/evas/evas_cserve2_cache.c495
-rw-r--r--src/bin/evas/evas_cserve2_debug.c136
-rw-r--r--src/bin/evas/evas_cserve2_index.c10
-rw-r--r--src/bin/evas/evas_cserve2_usage.c85
5 files changed, 244 insertions, 483 deletions
diff --git a/src/bin/evas/evas_cserve2.h b/src/bin/evas/evas_cserve2.h
index 88f4370346..badd33c8d6 100644
--- a/src/bin/evas/evas_cserve2.h
+++ b/src/bin/evas/evas_cserve2.h
@@ -352,6 +352,7 @@ const char *cserve2_shared_array_name_get(Shared_Array *sa);
352void cserve2_shared_array_del(Shared_Array *sa); 352void cserve2_shared_array_del(Shared_Array *sa);
353int cserve2_shared_array_size_get(Shared_Array *sa); 353int cserve2_shared_array_size_get(Shared_Array *sa);
354int cserve2_shared_array_count_get(Shared_Array *sa); 354int cserve2_shared_array_count_get(Shared_Array *sa);
355int cserve2_shared_array_map_size_get(Shared_Array *sa);
355int cserve2_shared_array_item_size_get(Shared_Array *sa); 356int cserve2_shared_array_item_size_get(Shared_Array *sa);
356int cserve2_shared_array_generation_id_get(Shared_Array *sa); 357int cserve2_shared_array_generation_id_get(Shared_Array *sa);
357int cserve2_shared_array_size_set(Shared_Array *sa, int newcount); 358int cserve2_shared_array_size_set(Shared_Array *sa, int newcount);
diff --git a/src/bin/evas/evas_cserve2_cache.c b/src/bin/evas/evas_cserve2_cache.c
index 7c7932ef8a..86fb80464c 100644
--- a/src/bin/evas/evas_cserve2_cache.c
+++ b/src/bin/evas/evas_cserve2_cache.c
@@ -1080,12 +1080,34 @@ _font_entry_key_hash(const Font_Entry *key, int key_length EINA_UNUSED)
1080 return hash; 1080 return hash;
1081} 1081}
1082 1082
1083static int
1084_font_entry_memory_usage_get(Font_Entry *fe)
1085{
1086 int size;
1087
1088 if (!fe) return 0;
1089 if (!fe->mempool && !fe->glyph_datas)
1090 return 0;
1091
1092 size = cserve2_shared_mempool_size_get(fe->mempool);
1093 size += cserve2_shared_array_map_size_get(fe->glyph_datas);
1094 size += fe->nglyphs * sizeof(Glyph_Entry);
1095
1096 return size;
1097}
1098
1083static void 1099static void
1084_font_entry_free(Font_Entry *fe) 1100_font_entry_free(Font_Entry *fe)
1085{ 1101{
1086 Font_Data *fd; 1102 Font_Data *fd;
1103 int size;
1087 1104
1088 if (!fe) return; 1105 if (!fe) return;
1106 size = _font_entry_memory_usage_get(fe);
1107
1108 DBG("Font memory usage down: %d -> %d / %d", font_mem_usage,
1109 font_mem_usage - size, max_font_usage);
1110 font_mem_usage -= size;
1089 1111
1090 fd = _font_data_find(fe->font_data_id); 1112 fd = _font_data_find(fe->font_data_id);
1091 if (fd) 1113 if (fd)
@@ -1098,6 +1120,7 @@ _font_entry_free(Font_Entry *fe)
1098 1120
1099 fash_gl_free(fe->glyph_entries); 1121 fash_gl_free(fe->glyph_entries);
1100 cserve2_shared_array_del(fe->glyph_datas); 1122 cserve2_shared_array_del(fe->glyph_datas);
1123 cserve2_shared_mempool_del(fe->mempool);
1101 cserve2_font_ft_free(fe->ft); 1124 cserve2_font_ft_free(fe->ft);
1102 fe->src->refcount--; 1125 fe->src->refcount--;
1103 if (fe->src->refcount <= 0) 1126 if (fe->src->refcount <= 0)
@@ -1141,79 +1164,49 @@ _font_source_free(Font_Source *fs)
1141 free(fs); 1164 free(fs);
1142} 1165}
1143 1166
1144#if 0
1145static void 1167static void
1146_font_shm_promote(Font_Cache *fc) 1168_font_lru_update(Font_Entry *fe)
1147{ 1169{
1148 Eina_List *l; 1170 Eina_List *l;
1149 l = eina_list_data_find_list(font_shm_lru, fc); 1171 l = eina_list_data_find_list(font_shm_lru, fe);
1150 font_shm_lru = eina_list_demote_list(font_shm_lru, l); 1172 if (l)
1151}
1152
1153static int
1154_font_shm_size_get(Font_Cache *fc)
1155{
1156 int size;
1157
1158 size = sizeof(*fc) + cserve2_shm_size_get(fc->shm);
1159
1160 return size;
1161}
1162
1163static void
1164_font_shm_free(Font_Cache *fc)
1165{
1166 Glyph_Data *gd;
1167 Font_Entry *fe = fc->fe;
1168 unsigned int k;
1169
1170 fe->caches = eina_list_remove(fe->caches, fc);
1171 if (fc == fe->last_cache)
1172 fe->last_cache = NULL;
1173
1174 for (k = 0; k < fc->nglyphs; k++)
1175 { 1173 {
1176 int *gldata_id = cserve2_shared_array_item_data_get(fc->glyphs, k); 1174 if (fe->unused)
1177 gd = _glyph_data_find(*gldata_id); 1175 font_shm_lru = eina_list_promote_list(font_shm_lru, l);
1178 fash_gl_del(fe->glyphs, gd->index); 1176 else
1177 font_shm_lru = eina_list_demote_list(font_shm_lru, l);
1179 } 1178 }
1180 1179 else
1181 cserve2_shared_array_del(fc->glyphs); 1180 font_shm_lru = eina_list_append(font_shm_lru, fe);
1182 cserve2_shm_unref(fc->shm);
1183 free(fc);
1184
1185 if (!fe->caches)
1186 eina_hash_del_by_key(font_entries, fe);
1187} 1181}
1188 1182
1189static void 1183static void
1190_font_shm_lru_flush(void) 1184_font_lru_flush(void)
1191{ 1185{
1192 Eina_List *l, *l_next; 1186 Eina_List *l, *l_next;
1193 1187
1194 l = font_shm_lru; 1188 l = font_shm_lru;
1195 l_next = eina_list_next(l); 1189 l_next = eina_list_next(l);
1196 1190
1191 DBG("Font memory usage [begin]: %d / %d", font_mem_usage, max_font_usage);
1192
1197 while (l && font_mem_usage > max_font_usage) 1193 while (l && font_mem_usage > max_font_usage)
1198 { 1194 {
1199 int size; 1195 Font_Entry *fe;
1200 Font_Cache *fc;
1201 1196
1202 fc = eina_list_data_get(l); 1197 fe = eina_list_data_get(l);
1203 if (fc->fe->unused && fc->inuse == 0) 1198 if (fe->unused)
1204 { 1199 {
1205 font_shm_lru = eina_list_remove_list(font_shm_lru, l); 1200 font_shm_lru = eina_list_remove_list(font_shm_lru, l);
1206 size = _font_shm_size_get(fc); 1201 eina_hash_del_by_key(font_entries, fe);
1207 size += fc->nglyphs * sizeof(Glyph_Entry);
1208 _font_shm_free(fc);
1209 font_mem_usage -= size;
1210 } 1202 }
1211 1203
1212 l = l_next; 1204 l = l_next;
1213 l_next = eina_list_next(l); 1205 l_next = eina_list_next(l);
1214 } 1206 }
1207
1208 DBG("Font memory usage [end]: %d / %d", font_mem_usage, max_font_usage);
1215} 1209}
1216#endif
1217 1210
1218void 1211void
1219cserve2_cache_init(void) 1212cserve2_cache_init(void)
@@ -1352,10 +1345,10 @@ _entry_reference_del(Entry *entry, Reference *ref)
1352 } 1345 }
1353 else if (entry->type == CSERVE2_FONT_ENTRY) 1346 else if (entry->type == CSERVE2_FONT_ENTRY)
1354 { 1347 {
1355 Font_Entry *fe = (Font_Entry *)entry; 1348 Font_Entry *fe = (Font_Entry *) entry;
1356 fe->unused = EINA_TRUE; 1349 fe->unused = EINA_TRUE;
1357 if (!fe->mempool) 1350 _font_lru_update(fe);
1358 eina_hash_del_by_key(font_entries, fe); 1351 _font_lru_flush();
1359 } 1352 }
1360 else 1353 else
1361 ERR("Wrong type of entry."); 1354 ERR("Wrong type of entry.");
@@ -1719,150 +1712,6 @@ _glyphs_request_check(Glyphs_Request *req, Eina_Bool report_load)
1719 return (req->nanswer == req->nglyphs); 1712 return (req->nanswer == req->nglyphs);
1720} 1713}
1721 1714
1722#if 0
1723/* organize answer (cache1{gl1, gl2,}, cache2{gl3,gl4,gl5}, cache3{gl6})
1724 */
1725static Eina_List *
1726_glyphs_group_create(Glyphs_Request *req)
1727{
1728 Eina_List *groups = NULL;
1729 unsigned int i;
1730 Glyphs_Group *gg;
1731
1732 gg = calloc(1, sizeof(*gg));
1733 groups = eina_list_append(groups, gg);
1734
1735 for (i = 0; i < req->nanswer; i++)
1736 gg->glyphs = eina_list_append(gg->glyphs, req->answer[i]);
1737
1738 return groups;
1739
1740 /*
1741 for (i = 0; i < req->nanswer; i++)
1742 {
1743 Eina_List *l;
1744 Glyphs_Group *iter, *gg = NULL;
1745 Font_Cache *fc = req->answer[i]->fc;
1746
1747 EINA_LIST_FOREACH(groups, l, iter)
1748 {
1749 if (iter->fc == fc)
1750 {
1751 gg = iter;
1752 break;
1753 }
1754 }
1755
1756 if (!gg)
1757 {
1758 gg = calloc(1, sizeof(*gg));
1759 gg->fc = fc;
1760 groups = eina_list_append(groups, gg);
1761 }
1762 gg->glyphs = eina_list_append(gg->glyphs, req->answer[i]);
1763 }
1764
1765 return groups;
1766 */
1767}
1768
1769static Msg_Font_Glyphs_Loaded *
1770_glyphs_loaded_msg_create(Glyphs_Request *req, int *resp_size)
1771{
1772 Msg_Font_Glyphs_Loaded msg;
1773 unsigned int size;
1774 Eina_List *ll, *answers = NULL;
1775 const char *shmname;
1776 unsigned int shmsize;
1777 char *resp, *buf;
1778 Glyphs_Group *iter;
1779
1780 memset(&msg, 0, sizeof(msg));
1781 msg.base.type = CSERVE2_FONT_GLYPHS_LOADED;
1782
1783 answers = _glyphs_group_create(req);
1784 msg.ncaches = eina_list_count(answers);
1785 size = sizeof(msg);
1786
1787 // calculate size of message
1788 // ncaches * sizeof(cache) + nglyphs1 * sizeof(glyph) +
1789 // nglyphs2 * sizeof(glyph)...
1790
1791 EINA_LIST_FOREACH(answers, ll, iter)
1792 {
1793 shmname = cserve2_shm_name_get(iter->fc->shm);
1794 shmsize = eina_stringshare_strlen(shmname) + 1;
1795 // shm namelen + name
1796 size += sizeof(int) + shmsize;
1797
1798 // nglyphs
1799 size += sizeof(int);
1800 // nglyphs * (index + offset + size + rows + width + pitch +
1801 // num_grays + pixel_mode)
1802 size += eina_list_count(iter->glyphs) * 9 * sizeof(int);
1803 }
1804
1805 resp = malloc(size);
1806 memcpy(resp, &msg, sizeof(msg));
1807 buf = resp + sizeof(msg);
1808
1809 EINA_LIST_FREE(answers, iter)
1810 {
1811 Glyph_Entry *gl;
1812 unsigned int nglyphs;
1813
1814 shmname = cserve2_shm_name_get(iter->fc->shm);
1815 shmsize = eina_stringshare_strlen(shmname) + 1;
1816 memcpy(buf, &shmsize, sizeof(int));
1817 buf += sizeof(int);
1818 memcpy(buf, shmname, shmsize);
1819 buf += shmsize;
1820
1821 nglyphs = eina_list_count(iter->glyphs);
1822 memcpy(buf, &nglyphs, sizeof(int));
1823 buf += sizeof(int);
1824
1825 iter->fc->inuse -= eina_list_count(iter->glyphs);
1826
1827 EINA_LIST_FREE(iter->glyphs, gl)
1828 {
1829 // TODO: Factorize memcpy
1830 Glyph_Data *gldata;
1831
1832 gldata = _glyph_data_find(gl->gldata_id);
1833 memcpy(buf, &gldata->index, sizeof(int));
1834 buf += sizeof(int);
1835 memcpy(buf, &gldata->shm_id, sizeof(string_t));
1836 buf += sizeof(string_t);
1837 memcpy(buf, &gldata->offset, sizeof(int));
1838 buf += sizeof(int);
1839 memcpy(buf, &gldata->size, sizeof(int));
1840 buf += sizeof(int);
1841 memcpy(buf, &gldata->rows, sizeof(int));
1842 buf += sizeof(int);
1843 memcpy(buf, &gldata->width, sizeof(int));
1844 buf += sizeof(int);
1845 memcpy(buf, &gldata->pitch, sizeof(int));
1846 buf += sizeof(int);
1847 memcpy(buf, &gldata->num_grays, sizeof(int));
1848 buf += sizeof(int);
1849 memcpy(buf, &gldata->pixel_mode, sizeof(int));
1850 buf += sizeof(int);
1851 }
1852
1853 /* We are removing SHMs from the beginning of the list, so this
1854 * gives a higher priority to them */
1855 _font_shm_promote(iter->fc);
1856 eina_list_free(iter->glyphs);
1857 free(iter);
1858 }
1859
1860 *resp_size = size;
1861
1862 return (Msg_Font_Glyphs_Loaded *)resp;
1863}
1864#endif
1865
1866static Msg_Font_Glyphs_Loaded * 1715static Msg_Font_Glyphs_Loaded *
1867_glyphs_loaded_msg_create(Glyphs_Request *req, int *resp_size) 1716_glyphs_loaded_msg_create(Glyphs_Request *req, int *resp_size)
1868{ 1717{
@@ -2105,11 +1954,19 @@ _glyphs_load_request_response(Glyphs_Request *req,
2105 if (!msg->nglyphs) 1954 if (!msg->nglyphs)
2106 return _glyphs_loaded_msg_create(req, size); 1955 return _glyphs_loaded_msg_create(req, size);
2107 1956
1957 DBG("Font memory usage [begin]: %d / %d", font_mem_usage, max_font_usage);
1958
2108 if (!mempool) 1959 if (!mempool)
2109 mempool = cserve2_shared_mempool_new(0); 1960 {
1961 mempool = cserve2_shared_mempool_new(0);
1962 font_mem_usage += cserve2_shared_mempool_size_get(mempool);
1963 }
2110 1964
2111 if (!fe->glyph_datas) 1965 if (!fe->glyph_datas)
2112 fe->glyph_datas = cserve2_shared_array_new(1, sizeof(Glyph_Data), 0); 1966 {
1967 fe->glyph_datas = cserve2_shared_array_new(1, sizeof(Glyph_Data), 0);
1968 font_mem_usage += cserve2_shared_array_map_size_get(fe->glyph_datas);
1969 }
2113 1970
2114 shm_id = cserve2_shared_string_add(cserve2_shared_mempool_name_get(mempool)); 1971 shm_id = cserve2_shared_string_add(cserve2_shared_mempool_name_get(mempool));
2115 for (j = 0; j < msg->nglyphs; j++) 1972 for (j = 0; j < msg->nglyphs; j++)
@@ -2119,9 +1976,11 @@ _glyphs_load_request_response(Glyphs_Request *req,
2119 gl = fash_gl_find(fe->glyph_entries, msg->glyphs[j].index); 1976 gl = fash_gl_find(fe->glyph_entries, msg->glyphs[j].index);
2120 if (!gl) 1977 if (!gl)
2121 { 1978 {
2122 int glyph_id; 1979 int glyph_id, orig_mapsize, new_mapsize;
2123 Glyph_Data *gldata; 1980 Glyph_Data *gldata;
2124 1981
1982 orig_mapsize = cserve2_shared_array_map_size_get(fe->glyph_datas);
1983
2125 glyph_id = cserve2_shared_array_item_new(fe->glyph_datas); 1984 glyph_id = cserve2_shared_array_item_new(fe->glyph_datas);
2126 gldata = cserve2_shared_array_item_data_get(fe->glyph_datas, 1985 gldata = cserve2_shared_array_item_data_get(fe->glyph_datas,
2127 glyph_id); 1986 glyph_id);
@@ -2152,7 +2011,9 @@ _glyphs_load_request_response(Glyphs_Request *req,
2152 fe->nglyphs++; 2011 fe->nglyphs++;
2153 fash_gl_add(fe->glyph_entries, gldata->index, gl); 2012 fash_gl_add(fe->glyph_entries, gldata->index, gl);
2154 2013
2155 font_mem_usage += sizeof(*gl) + sizeof(*gldata); 2014 new_mapsize = cserve2_shared_array_map_size_get(fe->glyph_datas);
2015 font_mem_usage += new_mapsize - orig_mapsize;
2016 font_mem_usage += sizeof(*gl);
2156 } 2017 }
2157 req->answer[req->nanswer++] = gl; 2018 req->answer[req->nanswer++] = gl;
2158 } 2019 }
@@ -2169,6 +2030,9 @@ _glyphs_load_request_response(Glyphs_Request *req,
2169 2030
2170 fe->mempool = mempool; 2031 fe->mempool = mempool;
2171 2032
2033 DBG("Font memory usage [end]: %d / %d", font_mem_usage, max_font_usage);
2034 _font_lru_flush();
2035
2172 return _glyphs_loaded_msg_create(req, size); 2036 return _glyphs_loaded_msg_create(req, size);
2173} 2037}
2174 2038
@@ -2185,42 +2049,39 @@ static Slave_Request_Funcs _glyphs_load_funcs = {
2185}; 2049};
2186 2050
2187static Eina_Bool 2051static Eina_Bool
2188_font_entry_stats_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, void *data, void *fdata) 2052_font_requested_size_cb(const Eina_Hash *hash EINA_UNUSED,
2053 Glyph_Data *gldata, Msg_Stats *msg)
2189{ 2054{
2190 // FIXME TODO Must reimplement this 2055 if (gldata->refcount)
2056 msg->fonts.requested_size += gldata->size;
2191 2057
2192#if 0 2058 return EINA_TRUE;
2059}
2060
2061
2062static Eina_Bool
2063_font_entry_stats_cb(const Eina_Hash *hash EINA_UNUSED,
2064 const void *key EINA_UNUSED, void *data, void *fdata)
2065{
2193 Font_Entry *fe = data; 2066 Font_Entry *fe = data;
2194 Msg_Stats *msg = fdata; 2067 Msg_Stats *msg = fdata;
2195 Eina_List *iter; 2068 unsigned int shmsize;
2196 Font_Cache *fc;
2197 int nrefs = eina_list_count(fe->base.references);
2198 2069
2199 msg->fonts.fonts_loaded++; 2070 msg->fonts.fonts_loaded++;
2200 if (fe->unused) msg->fonts.fonts_unused++; 2071 if (fe->unused) msg->fonts.fonts_unused++;
2201 2072
2202 // accounting size 2073 // accounting size
2203 EINA_LIST_FOREACH(fe->caches, iter, fc) 2074 shmsize = cserve2_shared_mempool_size_get(fe->mempool);
2204 { 2075 msg->fonts.real_size += shmsize;
2205 unsigned int fc_usage, shmsize; 2076 if (fe->unused) msg->fonts.unused_size += shmsize;
2206 /* This is not real requested usage, but an approximation. We don't
2207 * know how many times each glyph would be used by each client, but
2208 * assume that a similar set of glyphs from a given font would be used
2209 * by each client, thus counting them one time per client referencing
2210 * them.
2211 */
2212 fc_usage = fc->usage * nrefs;
2213 shmsize = cserve2_shm_size_get(fc->shm);
2214 2077
2215 msg->fonts.requested_size += fc_usage; 2078 cserve2_shared_array_foreach(fe->glyph_datas,
2216 msg->fonts.real_size += shmsize; 2079 EINA_EACH_CB(_font_requested_size_cb), msg);
2217 if (fe->unused) msg->fonts.unused_size += shmsize;
2218 }
2219 2080
2220#ifdef DEBUG_LOAD_TIME 2081#ifdef DEBUG_LOAD_TIME
2221 // accounting fonts load time 2082 // accounting fonts load time
2222 msg->fonts.fonts_load_time += fe->base.load_time; 2083 msg->fonts.fonts_load_time += fe->base.load_time;
2223 if (fe->caches) 2084 if (fe->mempool)
2224 { 2085 {
2225 msg->fonts.fonts_used_load_time += fe->base.load_time; 2086 msg->fonts.fonts_used_load_time += fe->base.load_time;
2226 msg->fonts.fonts_used_saved_time += fe->base.saved_time; 2087 msg->fonts.fonts_used_saved_time += fe->base.saved_time;
@@ -2234,8 +2095,6 @@ _font_entry_stats_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNU
2234 msg->fonts.glyphs_slave_time += fe->gl_slave_time; 2095 msg->fonts.glyphs_slave_time += fe->gl_slave_time;
2235#endif 2096#endif
2236 2097
2237#endif
2238
2239 return EINA_TRUE; 2098 return EINA_TRUE;
2240} 2099}
2241 2100
@@ -2319,52 +2178,53 @@ struct _debug_info
2319}; 2178};
2320 2179
2321static Eina_Bool 2180static Eina_Bool
2322_font_entry_debug_size_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, void *data, void *fdata) 2181_font_entry_debug_size_cb(const Eina_Hash *hash EINA_UNUSED,
2182 const void *key EINA_UNUSED, void *data, void *fdata)
2323{ 2183{
2324 struct _debug_info *di = fdata; 2184 struct _debug_info *di = fdata;
2325 unsigned int size = di->size;
2326 Font_Entry *fe = data; 2185 Font_Entry *fe = data;
2327 const char *str; 2186 const char *str;
2328 2187
2329 // filelen 2188 // filelen
2330 size += sizeof(int); 2189 di->size+= sizeof(int);
2331 2190
2332 // file 2191 // file
2333 if (fe->src->file) 2192 if (fe->src->file)
2334 { 2193 {
2335 str = cserve2_shared_string_get(fe->src->file); 2194 str = cserve2_shared_string_get(fe->src->file);
2336 size += strlen(str) + 1; 2195 di->size+= strlen(str) + 1;
2337 } 2196 }
2338 2197
2339 // namelen 2198 // namelen
2340 size += sizeof(int); 2199 di->size+= sizeof(int);
2341 2200
2342 // name 2201 // name
2343 if (fe->src->name) 2202 if (fe->src->name)
2344 { 2203 {
2345 str = cserve2_shared_string_get(fe->src->file); 2204 str = cserve2_shared_string_get(fe->src->file);
2346 size += strlen(str) + 1; 2205 di->size+= strlen(str) + 1;
2347 } 2206 }
2348 2207
2349 // rend_flags, size, dpi 2208 // rend_flags, size, dpi, unused
2350 size += 3 * sizeof(int); 2209 di->size+= 4 * sizeof(int);
2351 2210
2352 // unused 2211 // glyph_data_shm and glyph_mempool_shm (short strings)
2353 size += sizeof(int); 2212 di->size+= 2 * 64;
2354 2213
2355 // ncaches 2214 // nglyphs
2356 size += sizeof(int); 2215 di->size+= sizeof(int);
2357 2216
2358 size += cserve2_shared_mempool_size_get(fe->mempool); 2217 // glyphs
2218 di->size+= fe->nglyphs * sizeof(Glyph_Data);
2359 2219
2360 di->size = size;
2361 di->nfonts++; 2220 di->nfonts++;
2362 2221
2363 return EINA_TRUE; 2222 return EINA_TRUE;
2364} 2223}
2365 2224
2366static Eina_Bool 2225static Eina_Bool
2367_font_entry_debug_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, void *data, void *fdata) 2226_font_entry_debug_cb(const Eina_Hash *hash EINA_UNUSED,
2227 const void *key EINA_UNUSED, void *data, void *fdata)
2368{ 2228{
2369 char **pos = fdata; 2229 char **pos = fdata;
2370 char *buf = *pos; 2230 char *buf = *pos;
@@ -2451,124 +2311,6 @@ _font_entry_debug_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNU
2451 return EINA_TRUE; 2311 return EINA_TRUE;
2452} 2312}
2453 2313
2454 // FIXME TODO Must reimplement this
2455#if 0
2456
2457 char **pos = fdata;
2458 char *buf = *pos;
2459 Font_Entry *fe = data;
2460 Font_Cache *fc;
2461 Eina_List *iter;
2462 unsigned int len;
2463 unsigned int unused;
2464 unsigned int ncaches;
2465 const char *str;
2466
2467 // filelen + file
2468 len = 0;
2469 if (fe->src->file)
2470 {
2471 str = cserve2_shared_string_get(fe->src->file);
2472 len = strlen(str) + 1;
2473 }
2474 memcpy(buf, &len, sizeof(int));
2475 buf += sizeof(int);
2476 if (len) memcpy(buf, cserve2_shared_string_get(fe->src->file), len);
2477 buf += len;
2478
2479 // namelen + name
2480 len = 0;
2481 if (fe->src->name)
2482 {
2483 str = cserve2_shared_string_get(fe->src->name);
2484 len = strlen(str) + 1;
2485 }
2486 memcpy(buf, &len, sizeof(int));
2487 buf += sizeof(int);
2488 if (len) memcpy(buf, cserve2_shared_string_get(fe->src->name), len);
2489 buf += len;
2490
2491 // rend_flags, size, dpi
2492 memcpy(buf, &fe->rend_flags, sizeof(int));
2493 buf += sizeof(int);
2494 memcpy(buf, &fe->size, sizeof(int));
2495 buf += sizeof(int);
2496 memcpy(buf, &fe->dpi, sizeof(int));
2497 buf += sizeof(int);
2498
2499 // unused
2500 unused = fe->unused;
2501 memcpy(buf, &unused, sizeof(int));
2502 buf += sizeof(int);
2503
2504 // ncaches
2505 ncaches = eina_list_count(fe->caches);
2506 memcpy(buf, &ncaches, sizeof(int));
2507 buf += sizeof(int);
2508
2509 EINA_LIST_FOREACH(fe->caches, iter, fc)
2510 {
2511 Glyph_Data *gldata;
2512 const char *shmname;
2513 unsigned int shmsize;
2514 unsigned int k;
2515
2516 // shmnamelen + shmname
2517 shmname = cserve2_shm_name_get(fc->shm);
2518 len = strlen(shmname) + 1;
2519 memcpy(buf, &len, sizeof(int));
2520 buf += sizeof(int);
2521 memcpy(buf, shmname, len);
2522 buf += len;
2523
2524 // TODO: Simplify memcpy operations (can be factorized into 1)
2525
2526 // size, usage, nglyphs
2527 shmsize = cserve2_shm_size_get(fc->shm);
2528 memcpy(buf, &shmsize, sizeof(int));
2529 buf += sizeof(int);
2530 memcpy(buf, &fc->usage, sizeof(int));
2531 buf += sizeof(int);
2532 memcpy(buf, &fc->nglyphs, sizeof(int));
2533 buf += sizeof(int);
2534
2535 for (k = 0; k < fc->nglyphs; k++)
2536 {
2537 int *gldata_id = cserve2_shared_array_item_data_get(
2538 fc->glyphs, fc->nglyphs);
2539 gldata = _glyph_data_find(*gldata_id);
2540
2541 // index, shm_id, offset, size
2542 memcpy(buf, &gldata->index, sizeof(int));
2543 buf += sizeof(int);
2544 memcpy(buf, &gldata->shm_id, sizeof(string_t));
2545 buf += sizeof(string_t);
2546 memcpy(buf, &gldata->offset, sizeof(int));
2547 buf += sizeof(int);
2548 memcpy(buf, &gldata->size, sizeof(int));
2549 buf += sizeof(int);
2550
2551 // rows, width, pitch
2552 memcpy(buf, &gldata->rows, sizeof(int));
2553 buf += sizeof(int);
2554 memcpy(buf, &gldata->width, sizeof(int));
2555 buf += sizeof(int);
2556 memcpy(buf, &gldata->pitch, sizeof(int));
2557 buf += sizeof(int);
2558
2559 // num_grays, pixel_mode
2560 memcpy(buf, &gldata->num_grays, sizeof(int));
2561 buf += sizeof(int);
2562 memcpy(buf, &gldata->pixel_mode, sizeof(int));
2563 buf += sizeof(int);
2564 }
2565 }
2566
2567 *pos = buf;
2568 return EINA_TRUE;
2569#endif
2570}
2571
2572static void * 2314static void *
2573_cserve2_cache_font_debug(unsigned int rid, unsigned int *size) 2315_cserve2_cache_font_debug(unsigned int rid, unsigned int *size)
2574{ 2316{
@@ -2582,27 +2324,24 @@ _cserve2_cache_font_debug(unsigned int rid, unsigned int *size)
2582 2324
2583 msg.base.type = CSERVE2_FONT_DEBUG; 2325 msg.base.type = CSERVE2_FONT_DEBUG;
2584 msg.base.rid = rid; 2326 msg.base.rid = rid;
2327 eina_strlcpy(msg.fonts_index_path,
2328 cserve2_shared_array_name_get(_font_data_array),
2329 sizeof(msg.fonts_index_path));
2585 2330
2586 // First calculate how much size is needed for this message: 2331 // First calculate how much size is needed for this message
2587
2588 // nfonts
2589 di.size += sizeof(unsigned int);
2590
2591 // size needed for each font entry
2592 eina_hash_foreach(font_entries, _font_entry_debug_size_cb, &di); 2332 eina_hash_foreach(font_entries, _font_entry_debug_size_cb, &di);
2593 2333
2594 // Now really create the message 2334 // Now really create the message
2595 buf = malloc(di.size); 2335 buf = malloc(di.size);
2596 pos = buf; 2336 pos = buf;
2597 2337
2338 // nfonts
2339 msg.nfonts = di.nfonts;
2340
2598 // msg base 2341 // msg base
2599 memcpy(buf, &msg, sizeof(msg)); 2342 memcpy(buf, &msg, sizeof(msg));
2600 pos += sizeof(msg); 2343 pos += sizeof(msg);
2601 2344
2602 // nfonts
2603 memcpy(pos, &di.nfonts, sizeof(unsigned int));
2604 pos += sizeof(unsigned int);
2605
2606 eina_hash_foreach(font_entries, _font_entry_debug_cb, &pos); 2345 eina_hash_foreach(font_entries, _font_entry_debug_cb, &pos);
2607 2346
2608 *size = di.size; 2347 *size = di.size;
@@ -3072,6 +2811,7 @@ cserve2_cache_font_load(Client *client, const char *source, const char *name,
3072 2811
3073 _entry_load_reused(&fe->base); 2812 _entry_load_reused(&fe->base);
3074 fe->unused = EINA_FALSE; 2813 fe->unused = EINA_FALSE;
2814 _font_lru_update(fe);
3075 2815
3076 if (fe->base.request) 2816 if (fe->base.request)
3077 cserve2_request_waiter_add(fe->base.request, rid, client); 2817 cserve2_request_waiter_add(fe->base.request, rid, client);
@@ -3090,6 +2830,7 @@ cserve2_cache_font_load(Client *client, const char *source, const char *name,
3090 ref = _entry_reference_add((Entry *)fe, client, 0); 2830 ref = _entry_reference_add((Entry *)fe, client, 0);
3091 client->fonts.referencing = eina_list_append(client->fonts.referencing, ref); 2831 client->fonts.referencing = eina_list_append(client->fonts.referencing, ref);
3092 fe->unused = EINA_FALSE; 2832 fe->unused = EINA_FALSE;
2833 _font_lru_update(fe);
3093 2834
3094 fs = _cserve2_font_source_find(fullname); 2835 fs = _cserve2_font_source_find(fullname);
3095 if (!fs) 2836 if (!fs)
@@ -3204,12 +2945,6 @@ cserve2_cache_font_glyphs_used(Client *client, const char *source,
3204 unsigned int nglyphs, 2945 unsigned int nglyphs,
3205 unsigned int rid EINA_UNUSED) 2946 unsigned int rid EINA_UNUSED)
3206{ 2947{
3207 // FIXME TODO: Must reimplement this
3208 return 0;
3209
3210#if 0
3211 Glyphs_Group *gg;
3212 Eina_List *groups;
3213 Glyphs_Request *req; 2948 Glyphs_Request *req;
3214 2949
3215 DBG("Received report of used glyphs from client %d", client->id); 2950 DBG("Received report of used glyphs from client %d", client->id);
@@ -3221,22 +2956,12 @@ cserve2_cache_font_glyphs_used(Client *client, const char *source,
3221 return 0; 2956 return 0;
3222 } 2957 }
3223 2958
3224 _glyphs_request_check(req, EINA_FALSE); 2959 // TODO: We could finetune based on which glyphs exactly are used.
3225 groups = _glyphs_group_create(req); 2960 req->fe->unused = EINA_FALSE;
3226 2961 _font_lru_update(req->fe);
3227 // Promote SHMs which are still cached and in use
3228 // TODO: We can use later the information from request_prepare to preload
3229 // glyphs which are not cached anymore, but are in use on the client.
3230 EINA_LIST_FREE(groups, gg)
3231 {
3232 //_font_shm_promote(gg->fc);
3233 eina_list_free(gg->glyphs);
3234 free(gg);
3235 }
3236 2962
3237 _glyphs_request_free(req); 2963 _glyphs_request_free(req);
3238 return 0; 2964 return 0;
3239#endif
3240} 2965}
3241 2966
3242void 2967void
diff --git a/src/bin/evas/evas_cserve2_debug.c b/src/bin/evas/evas_cserve2_debug.c
index e68e1138fc..10b9d5c92f 100644
--- a/src/bin/evas/evas_cserve2_debug.c
+++ b/src/bin/evas/evas_cserve2_debug.c
@@ -177,8 +177,6 @@ _debug_msg_send(void)
177} 177}
178 178
179typedef struct _Font_Entry Font_Entry; 179typedef struct _Font_Entry Font_Entry;
180typedef struct _Cache_Entry Cache_Entry;
181typedef struct _Glyph_Entry Glyph_Entry;
182 180
183struct _Font_Entry 181struct _Font_Entry
184{ 182{
@@ -188,27 +186,9 @@ struct _Font_Entry
188 unsigned int size; 186 unsigned int size;
189 unsigned int dpi; 187 unsigned int dpi;
190 unsigned int unused; 188 unsigned int unused;
191 Eina_List *caches; 189 char glyph_data_shm[64];
192}; 190 char glyph_mempool_shm[64];
193 191 Eina_List *glyphs; // Glyph_Data
194struct _Cache_Entry
195{
196 const char *shmname;
197 unsigned int size;
198 unsigned int usage;
199 Eina_List *glyphs;
200};
201
202struct _Glyph_Entry
203{
204 unsigned int index;
205 unsigned int offset;
206 unsigned int size;
207 unsigned int rows;
208 unsigned int width;
209 unsigned int pitch;
210 unsigned int num_grays;
211 unsigned int pixel_mode;
212}; 192};
213 193
214#define READIT(_dst, _src) \ 194#define READIT(_dst, _src) \
@@ -217,6 +197,7 @@ struct _Glyph_Entry
217 _src += sizeof(_dst); \ 197 _src += sizeof(_dst); \
218 } while(0) 198 } while(0)
219 199
200#if 0
220static Glyph_Entry * 201static Glyph_Entry *
221_parse_glyph_entry(char **msg) 202_parse_glyph_entry(char **msg)
222{ 203{
@@ -267,6 +248,7 @@ _parse_cache_entry(char **msg)
267 248
268 return ce; 249 return ce;
269} 250}
251#endif
270 252
271static Font_Entry * 253static Font_Entry *
272_parse_font_entry(char **msg) 254_parse_font_entry(char **msg)
@@ -291,12 +273,18 @@ _parse_font_entry(char **msg)
291 READIT(fe->dpi, buf); 273 READIT(fe->dpi, buf);
292 READIT(fe->unused, buf); 274 READIT(fe->unused, buf);
293 275
276 eina_strlcpy(fe->glyph_data_shm, buf, 64);
277 buf += 64;
278 eina_strlcpy(fe->glyph_mempool_shm, buf, 64);
279 buf += 64;
280
294 READIT(n, buf); 281 READIT(n, buf);
295 while (n--) 282 while (n--)
296 { 283 {
297 Cache_Entry *ce; 284 Glyph_Data *gd = calloc(1, sizeof(Glyph_Data));
298 ce = _parse_cache_entry(&buf); 285 memcpy(gd, buf, sizeof(Glyph_Data));
299 fe->caches = eina_list_append(fe->caches, ce); 286 buf += sizeof(Glyph_Data);
287 fe->glyphs = eina_list_append(fe->glyphs, gd);
300 } 288 }
301 289
302 *msg = buf; 290 *msg = buf;
@@ -307,7 +295,7 @@ _parse_font_entry(char **msg)
307static Eina_List * 295static Eina_List *
308_debug_msg_read(void) 296_debug_msg_read(void)
309{ 297{
310 Msg_Base *msg = NULL; 298 Msg_Font_Debug *msg = NULL;
311 char *buf; 299 char *buf;
312 int size; 300 int size;
313 unsigned int nfonts; 301 unsigned int nfonts;
@@ -317,16 +305,16 @@ _debug_msg_read(void)
317 while (!msg) 305 while (!msg)
318 msg = _server_read(&size); 306 msg = _server_read(&size);
319 307
320 if (msg->type != CSERVE2_FONT_DEBUG) 308 if (msg->base.type != CSERVE2_FONT_DEBUG)
321 { 309 {
322 ERR("Invalid message received from server." 310 ERR("Invalid message received from server. "
323 "Something went badly wrong."); 311 "Something went badly wrong.");
324 return NULL; 312 return NULL;
325 } 313 }
326 314
327 buf = (char *)msg + sizeof(*msg); 315 buf = (char *)msg + sizeof(*msg);
328 316
329 READIT(nfonts, buf); 317 nfonts = msg->nfonts;
330 while (nfonts--) 318 while (nfonts--)
331 { 319 {
332 Font_Entry *fe; 320 Font_Entry *fe;
@@ -334,34 +322,18 @@ _debug_msg_read(void)
334 fonts = eina_list_append(fonts, fe); 322 fonts = eina_list_append(fonts, fe);
335 } 323 }
336 324
325 printf("Font index table: %s\n", msg->fonts_index_path);
326 printf("Contains %u fonts\n\n", msg->nfonts);
337 return fonts; 327 return fonts;
338} 328}
339 329
340static void 330static void
341_glyph_entry_free(Glyph_Entry *ge)
342{
343 free(ge);
344}
345
346static void
347_cache_entry_free(Cache_Entry *ce)
348{
349 Glyph_Entry *ge;
350
351 EINA_LIST_FREE(ce->glyphs, ge)
352 _glyph_entry_free(ge);
353
354 eina_stringshare_del(ce->shmname);
355 free(ce);
356}
357
358static void
359_font_entry_free(Font_Entry *fe) 331_font_entry_free(Font_Entry *fe)
360{ 332{
361 Cache_Entry *ce; 333 Glyph_Data *gd;
362 334
363 EINA_LIST_FREE(fe->caches, ce) 335 EINA_LIST_FREE(fe->glyphs, gd)
364 _cache_entry_free(ce); 336 free(gd);
365 337
366 eina_stringshare_del(fe->name); 338 eina_stringshare_del(fe->name);
367 eina_stringshare_del(fe->file); 339 eina_stringshare_del(fe->file);
@@ -369,7 +341,7 @@ _font_entry_free(Font_Entry *fe)
369} 341}
370 342
371static void 343static void
372_glyph_entry_print(Glyph_Entry *ge) 344_glyph_data_print(Glyph_Data *gd)
373{ 345{
374 const char *pxmode[] = { 346 const char *pxmode[] = {
375 "FT_PIXEL_MODE_NONE", 347 "FT_PIXEL_MODE_NONE",
@@ -380,29 +352,18 @@ _glyph_entry_print(Glyph_Entry *ge)
380 "FT_PIXEL_MODE_LCD", 352 "FT_PIXEL_MODE_LCD",
381 "FT_PIXEL_MODE_LCD_V" 353 "FT_PIXEL_MODE_LCD_V"
382 }; 354 };
383 printf("\t\tGLYPH %u offset: %u size: %u %ux%u pitch: %u grays: %u " 355 printf(" GLYPH id: %-4u refcount %-2u: index: %-6u offset: %-6u size: %-3u "
384 "pixel mode: %s\n", 356 "%2ux%-3u pitch: %-2u grays: %-3u pixel mode: %s\n",
385 ge->index, ge->offset, ge->size, ge->width, ge->rows, ge->pitch, 357 gd->id, gd->refcount, gd->index, gd->offset, gd->size,
386 ge->num_grays, pxmode[ge->pixel_mode]); 358 gd->width, gd->rows, gd->pitch,
387} 359 gd->num_grays, pxmode[gd->pixel_mode]);
388
389static void
390_cache_entry_print(Cache_Entry *ce)
391{
392 Eina_List *l;
393 Glyph_Entry *ge;
394
395 printf("\tSHM %s used %u/%u\n", ce->shmname, ce->usage, ce->size);
396
397 EINA_LIST_FOREACH(ce->glyphs, l, ge)
398 _glyph_entry_print(ge);
399} 360}
400 361
401static void 362static void
402_font_entry_print(Font_Entry *fe) 363_font_entry_print(Font_Entry *fe)
403{ 364{
404 Eina_List *l; 365 Eina_List *l;
405 Cache_Entry *ce; 366 Glyph_Data *gd;
406 367
407 printf("FONT %s:%s size: %u dpi: %u %s%s%s %s\n", 368 printf("FONT %s:%s size: %u dpi: %u %s%s%s %s\n",
408 fe->file, fe->name, fe->size, fe->dpi, 369 fe->file, fe->name, fe->size, fe->dpi,
@@ -410,18 +371,46 @@ _font_entry_print(Font_Entry *fe)
410 fe->rend_flags & 1 ? "SLANT " : "", 371 fe->rend_flags & 1 ? "SLANT " : "",
411 fe->rend_flags & 2 ? "WEIGHT" : "", 372 fe->rend_flags & 2 ? "WEIGHT" : "",
412 fe->unused ? "(unused)" : ""); 373 fe->unused ? "(unused)" : "");
374 printf(" Index: %s\n"
375 " Mempool: %s\n"
376 " Glyph count: %u\n",
377 fe->glyph_data_shm, fe->glyph_mempool_shm,
378 eina_list_count(fe->glyphs));
413 379
414 EINA_LIST_FOREACH(fe->caches, l, ce) 380 EINA_LIST_FOREACH(fe->glyphs, l, gd)
415 _cache_entry_print(ce); 381 _glyph_data_print(gd);
416 382
417 putchar('\n'); 383 putchar('\n');
418} 384}
419 385
386static void
387_shared_index_print(Msg_Index_List *msg, size_t size)
388{
389 if (size < sizeof(*msg) || msg->base.type != CSERVE2_INDEX_LIST)
390 {
391 ERR("Invalid message received from server. "
392 "Something went wrong.");
393 return;
394 }
395
396 printf("Printing shared indexes status.\n");
397 printf("===============================\n\n");
398 printf("Generation ID: %-4d\n", msg->generation_id);
399 printf("Strings entries path: %s\n", msg->strings_entries_path);
400 printf("Strings index path: %s\n", msg->strings_index_path);
401 printf("Files index path: %s\n", msg->files_index_path);
402 printf("Images index path: %s\n", msg->images_index_path);
403 printf("Fonts index path: %s\n", msg->fonts_index_path);
404 printf("\n\n\n");
405}
406
420int 407int
421main(void) 408main(void)
422{ 409{
423 Eina_List *fonts; 410 Eina_List *fonts;
424 Font_Entry *fe; 411 Font_Entry *fe;
412 Msg_Index_List *msg = NULL;
413 int size;
425 414
426 eina_init(); 415 eina_init();
427 _evas_cserve2_debug_log_dom = eina_log_domain_register 416 _evas_cserve2_debug_log_dom = eina_log_domain_register
@@ -431,6 +420,11 @@ main(void)
431 ERR("Could not connect to server."); 420 ERR("Could not connect to server.");
432 return -1; 421 return -1;
433 } 422 }
423
424 while (!msg)
425 msg = _server_read(&size);
426 _shared_index_print(msg, size);
427
434 _debug_msg_send(); 428 _debug_msg_send();
435 fonts = _debug_msg_read(); 429 fonts = _debug_msg_read();
436 EINA_LIST_FREE(fonts, fe) 430 EINA_LIST_FREE(fonts, fe)
diff --git a/src/bin/evas/evas_cserve2_index.c b/src/bin/evas/evas_cserve2_index.c
index 7c3f176d89..ec63660493 100644
--- a/src/bin/evas/evas_cserve2_index.c
+++ b/src/bin/evas/evas_cserve2_index.c
@@ -293,6 +293,13 @@ cserve2_shared_array_count_get(Shared_Array *sa)
293} 293}
294 294
295int 295int
296cserve2_shared_array_map_size_get(Shared_Array *sa)
297{
298 if (!sa || !sa->ds) return 0;
299 return cserve2_shm_map_size_get(sa->ds->shm);
300}
301
302int
296cserve2_shared_array_item_size_get(Shared_Array *sa) 303cserve2_shared_array_item_size_get(Shared_Array *sa)
297{ 304{
298 if (!sa) return -1; 305 if (!sa) return -1;
@@ -841,7 +848,8 @@ size_t
841cserve2_shared_mempool_size_get(Shared_Mempool *sm) 848cserve2_shared_mempool_size_get(Shared_Mempool *sm)
842{ 849{
843 if (!sm) return 0; 850 if (!sm) return 0;
844 return cserve2_shm_map_size_get(sm->ds->shm); 851 return cserve2_shm_map_size_get(sm->ds->shm)
852 + cserve2_shared_array_map_size_get(sm->index->sa);
845} 853}
846 854
847const char * 855const char *
diff --git a/src/bin/evas/evas_cserve2_usage.c b/src/bin/evas/evas_cserve2_usage.c
index bcf0cdd7d0..3ab78a8383 100644
--- a/src/bin/evas/evas_cserve2_usage.c
+++ b/src/bin/evas/evas_cserve2_usage.c
@@ -177,47 +177,80 @@ _usage_msg_send(void)
177} 177}
178 178
179static void 179static void
180_shared_index_print(Msg_Base *data, size_t size)
181{
182 Msg_Index_List *msg = (Msg_Index_List *) data;
183
184 if (size < sizeof(*msg) || msg->base.type != CSERVE2_INDEX_LIST)
185 {
186 ERR("Invalid message received from server. "
187 "Something went wrong.");
188 return;
189 }
190
191 printf("Printing shared indexes status.\n");
192 printf("===============================\n\n");
193 printf("Generation ID: %-4d\n", msg->generation_id);
194 printf("Strings entries path: %s\n", msg->strings_entries_path);
195 printf("Strings index path: %s\n", msg->strings_index_path);
196 printf("Files index path: %s\n", msg->files_index_path);
197 printf("Images index path: %s\n", msg->images_index_path);
198 printf("Fonts index path: %s\n", msg->fonts_index_path);
199 printf("\n\n\n");
200}
201
202static void
180_usage_msg_read(void) 203_usage_msg_read(void)
181{ 204{
182 Msg_Stats *msg = NULL; 205 Msg_Stats *stats = NULL;
183 int size; 206 int size;
184 207
185 printf("Requesting server statistics.\n\n"); 208 printf("Requesting server statistics.\n\n");
186 while (!msg)
187 msg = _server_read(&size);
188 209
189 if (msg->base.type != CSERVE2_STATS) 210 while (!stats)
190 { 211 {
191 ERR("Invalid message received from server." 212 Msg_Base *msg = _server_read(&size);
192 "Something went badly wrong."); 213 if (!msg) continue;
193 return; 214 switch (msg->type)
215 {
216 case CSERVE2_INDEX_LIST:
217 _shared_index_print(msg, size);
218 break;
219 case CSERVE2_STATS:
220 stats = (Msg_Stats *) msg;
221 break;
222 default:
223 ERR("Invalid message received from server. "
224 "Something went badly wrong.");
225 return;
226 }
194 } 227 }
195 228
196 printf("Printing server usage.\n"); 229 printf("Printing server usage.\n");
197 printf("======================\n\n"); 230 printf("======================\n\n");
198 printf("\nImage Usage Statistics:\n"); 231 printf("\nImage Usage Statistics:\n");
199 printf("----------------------\n\n"); 232 printf("----------------------\n\n");
200 printf("Image headers usage: %d bytes\n", msg->images.files_size); 233 printf("Image headers usage: %d bytes\n", stats->images.files_size);
201 printf("Image data requested: %d kbytes\n", msg->images.requested_size / 1024); 234 printf("Image data requested: %d kbytes\n", stats->images.requested_size / 1024);
202 printf("Image data usage: %d kbytes\n", msg->images.images_size / 1024); 235 printf("Image data usage: %d kbytes\n", stats->images.images_size / 1024);
203 printf("Image data unused: %d kbytes\n", msg->images.unused_size / 1024); 236 printf("Image data unused: %d kbytes\n", stats->images.unused_size / 1024);
204 printf("Image headers load time: %dus\n", msg->images.files_load_time); 237 printf("Image headers load time: %dus\n", stats->images.files_load_time);
205 printf("Image headers saved time: %dus\n", msg->images.files_saved_time); 238 printf("Image headers saved time: %dus\n", stats->images.files_saved_time);
206 printf("Image data load time: %dus\n", msg->images.images_load_time); 239 printf("Image data load time: %dus\n", stats->images.images_load_time);
207 printf("Image data saved time: %dus\n", msg->images.images_saved_time); 240 printf("Image data saved time: %dus\n", stats->images.images_saved_time);
208 printf("\nFont Usage Statistics:\n"); 241 printf("\nFont Usage Statistics:\n");
209 printf("----------------------\n\n"); 242 printf("----------------------\n\n");
210 printf("Requested usage: %d bytes\n", msg->fonts.requested_size); 243 printf("Requested usage: %d bytes\n", stats->fonts.requested_size);
211 printf("Real usage: %d bytes\n", msg->fonts.real_size); 244 printf("Real usage: %d bytes\n", stats->fonts.real_size);
212 printf("Unused size: %d bytes\n", msg->fonts.unused_size); 245 printf("Unused size: %d bytes\n", stats->fonts.unused_size);
213 printf("Fonts load time: %dus\n", msg->fonts.fonts_load_time); 246 printf("Fonts load time: %dus\n", stats->fonts.fonts_load_time);
214 printf("Fonts used load time: %dus\n", msg->fonts.fonts_used_load_time); 247 printf("Fonts used load time: %dus\n", stats->fonts.fonts_used_load_time);
215 printf("Fonts used saved time: %dus\n", msg->fonts.fonts_used_saved_time); 248 printf("Fonts used saved time: %dus\n", stats->fonts.fonts_used_saved_time);
216 printf("Glyphs load time: %dus\n", msg->fonts.glyphs_load_time); 249 printf("Glyphs load time: %dus\n", stats->fonts.glyphs_load_time);
217 printf("Glyphs render time: %dus\n", msg->fonts.glyphs_render_time); 250 printf("Glyphs render time: %dus\n", stats->fonts.glyphs_render_time);
218 printf("Glyphs saved time: %dus\n", msg->fonts.glyphs_saved_time); 251 printf("Glyphs saved time: %dus\n", stats->fonts.glyphs_saved_time);
219 printf("Glyphs request time: %dus\n", msg->fonts.glyphs_request_time); 252 printf("Glyphs request time: %dus\n", stats->fonts.glyphs_request_time);
220 printf("Glyphs slave time: %dus\n", msg->fonts.glyphs_slave_time); 253 printf("Glyphs slave time: %dus\n", stats->fonts.glyphs_slave_time);
221 254
222 printf("\n"); 255 printf("\n");
223} 256}