Skip to content

Commit 367ec12

Browse files
committed
mbop/locale: add -T option to test set_locale performance
1 parent b91f900 commit 367ec12

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

doc/gromox-mbop.8

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ gromox\-mbop \-u [email protected] purge\-softdelete \-r / \-t 10d
353353
Recalculates the store size.
354354
.SH set\-locale
355355
.SS Synopsis
356-
\fBset\-locale\fP [\fB\-v\fP] \-l\fP \fIid\fP
356+
\fBset\-locale\fP [\fB\-Tv\fP] \-l\fP \fIid\fP
357357
.SS Description
358358
First, the set\-locale operation changes the "preferred language" setting for
359359
the user account. This affects the display of user interfaces like
@@ -365,6 +365,10 @@ locale, set\-locale also resets the display names of the mailbox's built-in
365365
folders.
366366
.SS Options
367367
.TP
368+
\fB\-T\fP
369+
Run a trivial performance test against exmdb by repeatedly setting the folder
370+
names.
371+
.TP
368372
\fB\-l\fP \fId\fP
369373
A locale identifier in the form of \fIlanguage\fP\fB_\fP[\fIterritory\fP],
370374
where language is a ISO 639-1 code and territory is a ISO 3166-1 Alpha 2 code,

tools/mbop_locale.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,47 @@ using namespace gromox;
1616
namespace set_locale {
1717

1818
static constexpr HXoption g_options_table[] = {
19+
{{}, 'T', HXTYPE_NONE, {}, {}, {}, 0, "Run EXRPC performance test"},
1920
{{}, 'l', HXTYPE_STRING, {}, {}, {}, 0, "XPG/POSIX-style locale code (e.g. ja_JP)", "CODE"},
2021
{nullptr, 'v', HXTYPE_NONE, &global::g_verbose_mode, {}, {}, 0, "Verbose mode"},
2122
MBOP_AUTOHELP,
2223
HXOPT_TABLEEND,
2324
};
2425

25-
static int set_names(const char *lang);
26+
static int set_names(const char *lang, size_t &);
27+
28+
static void do_perftest(const char *lang)
29+
{
30+
size_t fcount = 0;
31+
auto t_start = tp_now();
32+
while (true) {
33+
if (set_names(lang, fcount) != 0)
34+
/* ignore */;
35+
auto now = tp_now();
36+
auto delta = now - t_start;
37+
if (delta >= std::chrono::seconds(1)) {
38+
auto d = std::chrono::duration_cast<std::chrono::microseconds>(delta) / fcount;
39+
fprintf(stderr, "\r\e[2K%llu µs\e[K", static_cast<unsigned long long>(d.count()));
40+
t_start = now;
41+
fcount = 0;
42+
}
43+
}
44+
}
2645

2746
int main(int argc, char **argv)
2847
{
2948
const char *g_language = nullptr;
49+
bool run_perftest = false;
3050
HXopt6_auto_result result;
3151
if (HX_getopt6(g_options_table, argc, argv, &result, HXOPT_USAGEONERR |
3252
HXOPT_ITER_OPTS) != HXOPT_ERR_SUCCESS || g_exit_after_optparse)
3353
return EXIT_PARAM;
34-
for (int i = 0; i < result.nopts; ++i)
54+
for (int i = 0; i < result.nopts; ++i) {
3555
if (result.desc[i]->sh == 'l')
3656
g_language = result.oarg[i];
57+
else if (result.desc[i]->sh == 'T')
58+
run_perftest = true;
59+
}
3760
if (g_language == nullptr) {
3861
mbop_fprintf(stderr, "You need to specify the -l option\n");
3962
return EXIT_PARAM;
@@ -49,10 +72,16 @@ int main(int argc, char **argv)
4972
fprintf(stderr, "No folder name translations for locale \"%s\" available.\n", g_language);
5073
return EXIT_SUCCESS;
5174
}
52-
return set_names(lang) == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
75+
76+
if (run_perftest) {
77+
do_perftest(lang);
78+
return EXIT_SUCCESS;
79+
}
80+
size_t ignored = 0;
81+
return set_names(lang, ignored) == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
5382
}
5483

55-
static int set_names(const char *lang)
84+
static int set_names(const char *lang, size_t &fcount)
5685
{
5786
unsigned int start_gcv = 1;
5887
unsigned int end_gcv = g_public_folder ? PUBLIC_FID_UNASSIGNED_START : PRIVATE_FID_UNASSIGNED_START;
@@ -81,6 +110,7 @@ static int set_names(const char *lang)
81110
mbop_fprintf(stderr, "set_folder_props failed\n");
82111
return EXIT_FAILURE;
83112
}
113+
++fcount;
84114
}
85115
return EXIT_SUCCESS;
86116
}

0 commit comments

Comments
 (0)