summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/latency.c
blob: dfce235c07c93cf7a53f181adc8a177b0b2fa3b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
  Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com>
  This file is part of GlusterFS.

  GlusterFS is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 3 of the License,
  or (at your option) any later version.

  GlusterFS is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see
  <http://www.gnu.org/licenses/>.
*/


/*
 * This file contains functions to support dumping of
 * latencies of FOPs broken down by subvolumes.
 */

#include "glusterfs.h"
#include "stack.h"
#include "xlator.h"
#include "common-utils.h"
#include "statedump.h"


void
gf_set_fop_from_fn_pointer (call_frame_t *frame, struct xlator_fops *fops, void *fn)
{
        glusterfs_fop_t fop = -1;

        if (fops->stat == fn)
                fop = GF_FOP_STAT;
        else if (fops->readlink == fn)
                fop = GF_FOP_READLINK;
        else if (fops->mknod == fn)
                fop = GF_FOP_MKNOD;
        else if (fops->mkdir == fn)
                fop = GF_FOP_MKDIR;
        else if (fops->unlink == fn)
                fop = GF_FOP_UNLINK;
        else if (fops->rmdir == fn)
                fop = GF_FOP_RMDIR;
        else if (fops->symlink == fn)
                fop = GF_FOP_SYMLINK;
        else if (fops->rename == fn)
                fop = GF_FOP_RENAME;
        else if (fops->link == fn)
                fop = GF_FOP_LINK;
        else if (fops->truncate == fn)
                fop = GF_FOP_TRUNCATE;
        else if (fops->open == fn)
                fop = GF_FOP_OPEN;
        else if (fops->readv == fn)
                fop = GF_FOP_READ;
        else if (fops->writev == fn)
                fop = GF_FOP_WRITE;
        else if (fops->statfs == fn)
                fop = GF_FOP_STATFS;
        else if (fops->flush == fn)
                fop = GF_FOP_FLUSH;
        else if (fops->fsync == fn)
                fop = GF_FOP_FSYNC;
        else if (fops->setxattr == fn)
                fop = GF_FOP_SETXATTR;
        else if (fops->getxattr == fn)
                fop = GF_FOP_GETXATTR;
        else if (fops->removexattr == fn)
                fop = GF_FOP_REMOVEXATTR;
        else if (fops->opendir == fn)
                fop = GF_FOP_OPENDIR;
        else if (fops->fsyncdir == fn)
                fop = GF_FOP_FSYNCDIR;
        else if (fops->access == fn)
                fop = GF_FOP_ACCESS;
        else if (fops->create == fn)
                fop = GF_FOP_CREATE;
        else if (fops->ftruncate == fn)
                fop = GF_FOP_FTRUNCATE;
        else if (fops->fstat == fn)
                fop = GF_FOP_FSTAT;
        else if (fops->lk == fn)
                fop = GF_FOP_LK;
        else if (fops->lookup == fn)
                fop = GF_FOP_LOOKUP;
        else if (fops->readdir == fn)
                fop = GF_FOP_READDIR;
        else if (fops->inodelk == fn)
                fop = GF_FOP_INODELK;
        else if (fops->finodelk == fn)
                fop = GF_FOP_FINODELK;
        else if (fops->entrylk == fn)
                fop = GF_FOP_ENTRYLK;
        else if (fops->fentrylk == fn)
                fop = GF_FOP_FENTRYLK;
        else if (fops->xattrop == fn)
                fop = GF_FOP_XATTROP;
        else if (fops->fxattrop == fn)
                fop = GF_FOP_FXATTROP;
        else if (fops->fgetxattr == fn)
                fop = GF_FOP_FGETXATTR;
        else if (fops->fsetxattr == fn)
                fop = GF_FOP_FSETXATTR;
        else if (fops->rchecksum == fn)
                fop = GF_FOP_RCHECKSUM;
        else if (fops->setattr == fn)
                fop = GF_FOP_SETATTR;
        else if (fops->fsetattr == fn)
                fop = GF_FOP_FSETATTR;
        else if (fops->readdirp == fn)
                fop = GF_FOP_READDIRP;
        else if (fops->getspec == fn)
                fop = GF_FOP_GETSPEC;
        else
                fop = -1;

        frame->op   = fop;
}


void
gf_update_latency (call_frame_t *frame)
{
        double elapsed;
        struct timeval *begin, *end;

        fop_latency_t *lat;

        begin = &frame->begin;
        end   = &frame->end;

        elapsed = (end->tv_sec - begin->tv_sec) * 1e6
                + (end->tv_usec - begin->tv_usec);

        lat = &frame->this->latencies[frame->op];

        lat->total += elapsed;
        lat->count++;
        lat->mean = lat->mean + (elapsed - lat->mean) / lat->count;
}


void
gf_proc_dump_latency_info (xlator_t *xl)
{
        char key_prefix[GF_DUMP_MAX_BUF_LEN];
        char key[GF_DUMP_MAX_BUF_LEN];
        int i;

        snprintf (key_prefix, GF_DUMP_MAX_BUF_LEN, "%s.latency", xl->name);
        gf_proc_dump_add_section (key_prefix);

        for (i = 0; i < GF_FOP_MAXVALUE; i++) {
                gf_proc_dump_build_key (key, key_prefix, gf_fop_list[i]);

                gf_proc_dump_write (key, "%.03f,%"PRId64",%.03f",
                                    xl->latencies[i].mean,
                                    xl->latencies[i].count,
                                    xl->latencies[i].total);
        }
}


void
gf_latency_toggle (int signum)
{
        glusterfs_ctx_t *ctx = NULL;

        ctx = glusterfs_ctx_get ();

        if (ctx) {
                ctx->measure_latency = !ctx->measure_latency;
                gf_log ("[core]", GF_LOG_INFO,
                        "Latency measurement turned %s",
                        ctx->measure_latency ? "on" : "off");
        }
}