]>
git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/app/iscsi_top/iscsi_top.cpp
4 * Copyright (c) Intel Corporation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/types.h>
52 #include "spdk/trace.h"
53 #include "iscsi/conn.h"
56 static char *exe_name
;
57 static int g_shm_id
= 0;
59 static void usage(void)
61 fprintf(stderr
, "usage:\n");
62 fprintf(stderr
, " %s <option>\n", exe_name
);
63 fprintf(stderr
, " option = '-i' to specify the shared memory ID,"
68 conns_compare(struct spdk_iscsi_conn
*first
, struct spdk_iscsi_conn
*second
)
70 if (first
->lcore
< second
->lcore
)
73 if (first
->lcore
> second
->lcore
)
76 if (first
->id
< second
->id
)
83 print_connections(void)
85 std::vector
<struct spdk_iscsi_conn
*> v
;
86 std::vector
<struct spdk_iscsi_conn
*>::iterator iter
;
88 struct spdk_iscsi_conn
*conns
, *conn
;
93 snprintf(shm_name
, sizeof(shm_name
), "spdk_iscsi_conns.%d", g_shm_id
);
94 fd
= shm_open(shm_name
, O_RDONLY
, 0600);
96 fprintf(stderr
, "Cannot open shared memory: %s\n", shm_name
);
101 conns_size
= sizeof(*conns
) * MAX_ISCSI_CONNECTIONS
;
103 conns_ptr
= mmap(NULL
, conns_size
, PROT_READ
, MAP_SHARED
, fd
, 0);
104 if (conns_ptr
== NULL
) {
105 fprintf(stderr
, "Cannot mmap shared memory\n");
109 conns
= (struct spdk_iscsi_conn
*)conns_ptr
;
111 for (i
= 0; i
< MAX_ISCSI_CONNECTIONS
; i
++) {
112 if (!conns
[i
].is_valid
) {
115 v
.push_back(&conns
[i
]);
118 stable_sort(v
.begin(), v
.end(), conns_compare
);
119 for (iter
= v
.begin(); iter
!= v
.end(); iter
++) {
121 printf("lcore %2d conn %3d T:%-8s I:%s (%s)\n",
122 conn
->lcore
, conn
->id
,
123 conn
->target_short_name
, conn
->initiator_name
,
124 conn
->initiator_addr
);
128 munmap(conns
, conns_size
);
132 int main(int argc
, char **argv
)
135 struct spdk_trace_histories
*histories
;
136 struct spdk_trace_history
*history
;
138 uint64_t tasks_done
, last_tasks_done
[SPDK_TRACE_MAX_LCORE
];
139 int delay
, old_delay
, history_fd
, i
, quit
, rc
;
140 int tasks_done_delta
, tasks_done_per_sec
;
141 int total_tasks_done_per_sec
;
142 struct timeval timeout
;
145 struct termios oldt
, newt
;
146 char spdk_trace_shm_name
[64];
150 while ((op
= getopt(argc
, argv
, "i:")) != -1) {
153 g_shm_id
= atoi(optarg
);
161 snprintf(spdk_trace_shm_name
, sizeof(spdk_trace_shm_name
), "/iscsi_trace.%d", g_shm_id
);
162 history_fd
= shm_open(spdk_trace_shm_name
, O_RDONLY
, 0600);
163 if (history_fd
< 0) {
164 fprintf(stderr
, "Unable to open history shm %s\n", spdk_trace_shm_name
);
169 history_ptr
= mmap(NULL
, sizeof(*histories
), PROT_READ
, MAP_SHARED
, history_fd
, 0);
170 if (history_ptr
== MAP_FAILED
) {
171 fprintf(stderr
, "Unable to mmap history shm\n");
175 histories
= (struct spdk_trace_histories
*)history_ptr
;
177 memset(last_tasks_done
, 0, sizeof(last_tasks_done
));
179 for (i
= 0; i
< SPDK_TRACE_MAX_LCORE
; i
++) {
180 history
= &histories
->per_lcore_history
[i
];
181 last_tasks_done
[i
] = history
->tpoint_count
[TRACE_ISCSI_TASK_DONE
];
189 newt
.c_lflag
&= ~(ICANON
);
190 tcsetattr(0, TCSANOW
, &newt
);
196 timeout
.tv_sec
= delay
;
198 rc
= select(2, &fds
, NULL
, NULL
, &timeout
);
201 if (read(0, &ch
, 1) != 1) {
202 fprintf(stderr
, "Read error on stdin\n");
209 printf("Enter num seconds to delay (1-10): ");
211 rc
= scanf("%d", &delay
);
213 fprintf(stderr
, "Illegal delay value\n");
215 } else if (delay
< 1 || delay
> 10) {
223 fprintf(stderr
, "'%c' not recognized\n", ch
);
232 printf("\e[1;1H\e[2J");
234 printf("lcore tasks\n");
235 printf("=============\n");
236 total_tasks_done_per_sec
= 0;
237 for (i
= 0; i
< SPDK_TRACE_MAX_LCORE
; i
++) {
238 history
= &histories
->per_lcore_history
[i
];
239 tasks_done
= history
->tpoint_count
[TRACE_ISCSI_TASK_DONE
];
240 tasks_done_delta
= tasks_done
- last_tasks_done
[i
];
241 if (tasks_done_delta
== 0) {
244 last_tasks_done
[i
] = tasks_done
;
245 tasks_done_per_sec
= tasks_done_delta
/ delay
;
246 printf("%5d %7d\n", history
->lcore
, tasks_done_per_sec
);
247 total_tasks_done_per_sec
+= tasks_done_per_sec
;
249 printf("Total %7d\n", total_tasks_done_per_sec
);
253 tcsetattr(0, TCSANOW
, &oldt
);
255 munmap(history_ptr
, sizeof(*histories
));