blob: 6a80dec2c7b7479cff92d24c47d2a0d9ac8fa691 [file] [log] [blame]
Jens Axboe79d16312010-03-04 12:43:20 +01001#include "fio.h"
2#include "profile.h"
3#include "debug.h"
4#include "flist.h"
Jens Axboee2de69d2010-03-04 14:05:48 +01005#include "options.h"
Jens Axboe79d16312010-03-04 12:43:20 +01006
7static FLIST_HEAD(profile_list);
8
Jens Axboe15dc1932010-03-05 10:59:06 +01009struct profile_ops *find_profile(const char *profile)
Jens Axboe79d16312010-03-04 12:43:20 +010010{
Jens Axboe15dc1932010-03-05 10:59:06 +010011 struct profile_ops *ops = NULL;
Jens Axboe79d16312010-03-04 12:43:20 +010012 struct flist_head *n;
13
Jens Axboe79d16312010-03-04 12:43:20 +010014 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
Jens Axboe15dc1932010-03-05 10:59:06 +010022 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);
Jens Axboe79d16312010-03-04 12:43:20 +010032 if (ops) {
Jens Axboe2363d8d2010-03-04 14:30:02 +010033 ops->prep_cmd();
Jens Axboe46bcd492012-03-14 11:31:21 +010034 add_job_opts(ops->cmdline, FIO_CLIENT_TYPE_CLI);
Jens Axboe79d16312010-03-04 12:43:20 +010035 return 0;
36 }
37
38 log_err("fio: profile '%s' not found\n", profile);
39 return 1;
40}
41
Jens Axboe07b32322010-03-05 09:48:44 +010042static int add_profile_options(struct profile_ops *ops)
Jens Axboee2de69d2010-03-04 14:05:48 +010043{
Jens Axboe07b32322010-03-05 09:48:44 +010044 struct fio_option *o;
Jens Axboe3c3ed072012-03-27 09:12:39 +020045
Jens Axboee2de69d2010-03-04 14:05:48 +010046 if (!ops->options)
Jens Axboe07b32322010-03-05 09:48:44 +010047 return 0;
Jens Axboee2de69d2010-03-04 14:05:48 +010048
Jens Axboe07b32322010-03-05 09:48:44 +010049 o = ops->options;
50 while (o->name) {
51 o->prof_name = ops->name;
52 if (add_option(o))
53 return 1;
54 o++;
Jens Axboee2de69d2010-03-04 14:05:48 +010055 }
Jens Axboe07b32322010-03-05 09:48:44 +010056
57 return 0;
Jens Axboee2de69d2010-03-04 14:05:48 +010058}
59
Jens Axboe07b32322010-03-05 09:48:44 +010060int register_profile(struct profile_ops *ops)
Jens Axboe79d16312010-03-04 12:43:20 +010061{
Jens Axboe07b32322010-03-05 09:48:44 +010062 int ret;
63
Jens Axboe79d16312010-03-04 12:43:20 +010064 dprint(FD_PROFILE, "register profile '%s'\n", ops->name);
Jens Axboe07b32322010-03-05 09:48:44 +010065
Jens Axboef5b6bb82010-03-05 10:09:59 +010066 ret = add_profile_options(ops);
67 if (!ret) {
68 flist_add_tail(&ops->list, &profile_list);
69 add_opt_posval("profile", ops->name, ops->desc);
70 return 0;
71 }
72
73 invalidate_profile_options(ops->name);
Jens Axboe07b32322010-03-05 09:48:44 +010074 return ret;
Jens Axboe79d16312010-03-04 12:43:20 +010075}
76
77void unregister_profile(struct profile_ops *ops)
78{
79 dprint(FD_PROFILE, "unregister profile '%s'\n", ops->name);
80 flist_del(&ops->list);
Jens Axboe07b32322010-03-05 09:48:44 +010081 invalidate_profile_options(ops->name);
Jens Axboef5b6bb82010-03-05 10:09:59 +010082 del_opt_posval("profile", ops->name);
Jens Axboe79d16312010-03-04 12:43:20 +010083}
Jens Axboe15dc1932010-03-05 10:59:06 +010084
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
Jens Axboed72be542012-11-30 19:37:46 +010096 if (ops->io_ops) {
Jens Axboe7eb36572010-03-08 13:58:49 +010097 td->prof_io_ops = *ops->io_ops;
Jens Axboed72be542012-11-30 19:37:46 +010098 td->flags |= TD_F_PROFILE_OPS;
99 }
Jens Axboe15dc1932010-03-05 10:59:06 +0100100}
Jens Axboe58c55ba2010-03-09 12:20:08 +0100101
102int profile_td_init(struct thread_data *td)
103{
104 struct prof_io_ops *ops = &td->prof_io_ops;
105
106 if (ops->td_init)
107 return ops->td_init(td);
108
109 return 0;
110}
111
112void profile_td_exit(struct thread_data *td)
113{
114 struct prof_io_ops *ops = &td->prof_io_ops;
115
116 if (ops->td_exit)
117 ops->td_exit(td);
118}