|
| 1 | +/**************************************************************************** |
| 2 | + * fs/procfs/fs_procfsprofile.c |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + * |
| 6 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 7 | + * contributor license agreements. See the NOTICE file distributed with |
| 8 | + * this work for additional information regarding copyright ownership. The |
| 9 | + * ASF licenses this file to you under the Apache License, Version 2.0 (the |
| 10 | + * "License"); you may not use this file except in compliance with the |
| 11 | + * License. You may obtain a copy of the License at |
| 12 | + * |
| 13 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | + * |
| 15 | + * Unless required by applicable law or agreed to in writing, software |
| 16 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 17 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 18 | + * License for the specific language governing permissions and limitations |
| 19 | + * under the License. |
| 20 | + * |
| 21 | + ****************************************************************************/ |
| 22 | + |
| 23 | +/**************************************************************************** |
| 24 | + * Included Files |
| 25 | + ****************************************************************************/ |
| 26 | + |
| 27 | +#include <nuttx/config.h> |
| 28 | + |
| 29 | +#if defined(CONFIG_FS_PROCFS) && defined(CONFIG_FS_PROFILER) && \ |
| 30 | + defined(CONFIG_FS_PROCFS_PROFILER) |
| 31 | + |
| 32 | +#include <sys/types.h> |
| 33 | +#include <sys/stat.h> |
| 34 | +#include <stdio.h> |
| 35 | +#include <string.h> |
| 36 | + |
| 37 | +#include <nuttx/fs/fs.h> |
| 38 | +#include <nuttx/fs/procfs.h> |
| 39 | +#include "../vfs/vfs.h" |
| 40 | + |
| 41 | +/**************************************************************************** |
| 42 | + * Private Functions |
| 43 | + ****************************************************************************/ |
| 44 | + |
| 45 | +static int profile_open(FAR struct file *filep, FAR const char *relpath, |
| 46 | + int oflags, mode_t mode) |
| 47 | +{ |
| 48 | + return OK; |
| 49 | +} |
| 50 | + |
| 51 | +static int profile_close(FAR struct file *filep) |
| 52 | +{ |
| 53 | + return OK; |
| 54 | +} |
| 55 | + |
| 56 | +static ssize_t profile_read(FAR struct file *filep, FAR char *buffer, |
| 57 | + size_t buflen) |
| 58 | +{ |
| 59 | + char buf[256]; |
| 60 | + size_t linesize; |
| 61 | + off_t offset = filep->f_pos; |
| 62 | + |
| 63 | + if (offset > 0) |
| 64 | + { |
| 65 | + return 0; |
| 66 | + } |
| 67 | + |
| 68 | + procfs_snprintf(buf, sizeof(buf), |
| 69 | + "VFS Performance Profile:\n" |
| 70 | + " Reads: %10lu (Total time: %llu ns)\n" |
| 71 | + " Writes: %10lu (Total time: %llu ns)\n" |
| 72 | + " Opens: %10lu (Total time: %llu ns)\n" |
| 73 | + " Closes: %10lu (Total time: %llu ns)\n", |
| 74 | + (unsigned long)g_vfs_profile.reads, |
| 75 | + (unsigned long long)g_vfs_profile.total_read_time, |
| 76 | + (unsigned long)g_vfs_profile.writes, |
| 77 | + (unsigned long long)g_vfs_profile.total_write_time, |
| 78 | + (unsigned long)g_vfs_profile.opens, |
| 79 | + (unsigned long long)g_vfs_profile.total_open_time, |
| 80 | + (unsigned long)g_vfs_profile.closes, |
| 81 | + (unsigned long long)g_vfs_profile.total_close_time); |
| 82 | + |
| 83 | + linesize = strlen(buf); |
| 84 | + if (linesize > buflen) |
| 85 | + { |
| 86 | + linesize = buflen; |
| 87 | + } |
| 88 | + |
| 89 | + memcpy(buffer, buf, linesize); |
| 90 | + filep->f_pos += linesize; |
| 91 | + return linesize; |
| 92 | +} |
| 93 | + |
| 94 | +static int profile_dup(FAR const struct file *oldp, FAR struct file *newp) |
| 95 | +{ |
| 96 | + return OK; |
| 97 | +} |
| 98 | + |
| 99 | +static int profile_stat(FAR const char *relpath, FAR struct stat *buf) |
| 100 | +{ |
| 101 | + memset(buf, 0, sizeof(struct stat)); |
| 102 | + buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR; |
| 103 | + return OK; |
| 104 | +} |
| 105 | + |
| 106 | +/**************************************************************************** |
| 107 | + * Public Data |
| 108 | + ****************************************************************************/ |
| 109 | + |
| 110 | +const struct procfs_operations g_vfs_profile_operations = |
| 111 | +{ |
| 112 | + profile_open, /* open */ |
| 113 | + profile_close, /* close */ |
| 114 | + profile_read, /* read */ |
| 115 | + NULL, /* write */ |
| 116 | + NULL, /* poll */ |
| 117 | + profile_dup, /* dup */ |
| 118 | + NULL, /* opendir */ |
| 119 | + NULL, /* closedir */ |
| 120 | + NULL, /* readdir */ |
| 121 | + NULL, /* rewinddir */ |
| 122 | + profile_stat /* stat */ |
| 123 | +}; |
| 124 | + |
| 125 | +#endif |
| 126 | + |
0 commit comments