Fix for hosed end-of-run log numbers
[fio.git] / profile.c
CommitLineData
79d16311
JA
1#include "fio.h"
2#include "profile.h"
3#include "debug.h"
4#include "flist.h"
e2de69da 5#include "options.h"
79d16311
JA
6
7static FLIST_HEAD(profile_list);
8
15dc1934 9struct profile_ops *find_profile(const char *profile)
79d16311 10{
15dc1934 11 struct profile_ops *ops = NULL;
79d16311
JA
12 struct flist_head *n;
13
79d16311
JA
14 flist_for_each(n, &profile_list) {
15 ops = flist_entry(n, struct profile_ops, list);
16 if (!strcmp(profile, ops->name))
17 break;
18
19 ops = NULL;
20 }
21
15dc1934
JA
22 return ops;
23}
24
25int load_profile(const char *profile)
26{
27 struct profile_ops *ops;
28
29 dprint(FD_PROFILE, "loading profile '%s'\n", profile);
30
31 ops = find_profile(profile);
79d16311 32 if (ops) {
2363d8df
JA
33 ops->prep_cmd();
34 add_job_opts(ops->cmdline);
79d16311
JA
35 return 0;
36 }
37
38 log_err("fio: profile '%s' not found\n", profile);
39 return 1;
40}
41
07b3232d 42static int add_profile_options(struct profile_ops *ops)
e2de69da 43{
07b3232d 44 struct fio_option *o;
e2de69da
JA
45
46 if (!ops->options)
07b3232d 47 return 0;
e2de69da 48
07b3232d
JA
49 o = ops->options;
50 while (o->name) {
51 o->prof_name = ops->name;
52 if (add_option(o))
53 return 1;
54 o++;
e2de69da 55 }
07b3232d
JA
56
57 return 0;
e2de69da
JA
58}
59
07b3232d 60int register_profile(struct profile_ops *ops)
79d16311 61{
07b3232d
JA
62 int ret;
63
79d16311 64 dprint(FD_PROFILE, "register profile '%s'\n", ops->name);
f5b6bb85 65
07b3232d 66 ret = add_profile_options(ops);
f5b6bb85
JA
67 if (!ret) {
68 flist_add_tail(&ops->list, &profile_list);
69 add_opt_posval("profile", ops->name, ops->desc);
70 return 0;
71 }
07b3232d 72
f5b6bb85 73 invalidate_profile_options(ops->name);
07b3232d 74 return ret;
79d16311
JA
75}
76
77void unregister_profile(struct profile_ops *ops)
78{
79 dprint(FD_PROFILE, "unregister profile '%s'\n", ops->name);
80 flist_del(&ops->list);
07b3232d 81 invalidate_profile_options(ops->name);
f5b6bb85 82 del_opt_posval("profile", ops->name);
79d16311 83}
15dc1934
JA
84
85void profile_add_hooks(struct thread_data *td)
86{
87 struct profile_ops *ops;
88
89 if (!exec_profile)
90 return;
91
92 ops = find_profile(exec_profile);
93 if (!ops)
94 return;
95
7eb36574
JA
96 if (ops->io_ops)
97 td->prof_io_ops = *ops->io_ops;
15dc1934 98}
58c55ba0
JA
99
100int profile_td_init(struct thread_data *td)
101{
102 struct prof_io_ops *ops = &td->prof_io_ops;
103
104 if (ops->td_init)
105 return ops->td_init(td);
106
107 return 0;
108}
109
110void profile_td_exit(struct thread_data *td)
111{
112 struct prof_io_ops *ops = &td->prof_io_ops;
113
114 if (ops->td_exit)
115 ops->td_exit(td);
116}