Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 1 | #include "fio.h" |
| 2 | #include "profile.h" |
| 3 | #include "debug.h" |
| 4 | #include "flist.h" |
Jens Axboe | e2de69d | 2010-03-04 14:05:48 +0100 | [diff] [blame] | 5 | #include "options.h" |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 6 | |
| 7 | static FLIST_HEAD(profile_list); |
| 8 | |
| 9 | int load_profile(const char *profile) |
| 10 | { |
| 11 | struct profile_ops *ops; |
| 12 | struct flist_head *n; |
| 13 | |
| 14 | dprint(FD_PROFILE, "loading profile '%s'\n", profile); |
| 15 | |
| 16 | flist_for_each(n, &profile_list) { |
| 17 | ops = flist_entry(n, struct profile_ops, list); |
| 18 | if (!strcmp(profile, ops->name)) |
| 19 | break; |
| 20 | |
| 21 | ops = NULL; |
| 22 | } |
| 23 | |
| 24 | if (ops) { |
Jens Axboe | 2363d8d | 2010-03-04 14:30:02 +0100 | [diff] [blame^] | 25 | ops->prep_cmd(); |
| 26 | add_job_opts(ops->cmdline); |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 27 | return 0; |
| 28 | } |
| 29 | |
| 30 | log_err("fio: profile '%s' not found\n", profile); |
| 31 | return 1; |
| 32 | } |
| 33 | |
Jens Axboe | e2de69d | 2010-03-04 14:05:48 +0100 | [diff] [blame] | 34 | static void add_profile_options(struct profile_ops *ops) |
| 35 | { |
| 36 | struct fio_option *fo; |
| 37 | struct ext_option *eo; |
| 38 | |
| 39 | if (!ops->options) |
| 40 | return; |
| 41 | |
| 42 | fo = ops->options; |
| 43 | while (fo->name) { |
| 44 | eo = malloc(sizeof(*eo)); |
| 45 | eo->prof_name = ops->name; |
| 46 | memcpy(&eo->o, fo, sizeof(*fo)); |
| 47 | register_ext_option(eo); |
| 48 | fo++; |
| 49 | } |
| 50 | } |
| 51 | |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 52 | void register_profile(struct profile_ops *ops) |
| 53 | { |
| 54 | dprint(FD_PROFILE, "register profile '%s'\n", ops->name); |
| 55 | flist_add_tail(&ops->list, &profile_list); |
Jens Axboe | e2de69d | 2010-03-04 14:05:48 +0100 | [diff] [blame] | 56 | add_profile_options(ops); |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | void unregister_profile(struct profile_ops *ops) |
| 60 | { |
| 61 | dprint(FD_PROFILE, "unregister profile '%s'\n", ops->name); |
| 62 | flist_del(&ops->list); |
Jens Axboe | e2de69d | 2010-03-04 14:05:48 +0100 | [diff] [blame] | 63 | prune_profile_options(ops->name); |
Jens Axboe | 79d1631 | 2010-03-04 12:43:20 +0100 | [diff] [blame] | 64 | } |