|
| 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 | + |
| 62 | + procfs_snprintf(buf, sizeof(buf), |
| 63 | + "FS Performance Profile:\n" |
| 64 | + " Reads: %10lu (Total time: %llu ns)\n" |
| 65 | + " Writes: %10lu (Total time: %llu ns)\n" |
| 66 | + " Opens: %10lu (Total time: %llu ns)\n" |
| 67 | + " Closes: %10lu (Total time: %llu ns)\n", |
| 68 | + (unsigned long)atomic_read(&g_fs_profile.reads), |
| 69 | + (unsigned long long) |
| 70 | + atomic64_read(&g_fs_profile.total_read_time), |
| 71 | + (unsigned long)atomic_read(&g_fs_profile.writes), |
| 72 | + (unsigned long long) |
| 73 | + atomic64_read(&g_fs_profile.total_write_time), |
| 74 | + (unsigned long)atomic_read(&g_fs_profile.opens), |
| 75 | + (unsigned long long) |
| 76 | + atomic64_read(&g_fs_profile.total_open_time), |
| 77 | + (unsigned long)atomic_read(&g_fs_profile.closes), |
| 78 | + (unsigned long long) |
| 79 | + atomic64_read(&g_fs_profile.total_close_time)); |
| 80 | + |
| 81 | + linesize = strlen(buf); |
| 82 | + return procfs_memcpy(filep, buffer, buflen, buf, linesize); |
| 83 | +} |
| 84 | + |
| 85 | +static int profile_dup(FAR const struct file *oldp, FAR struct file *newp) |
| 86 | +{ |
| 87 | + return OK; |
| 88 | +} |
| 89 | + |
| 90 | +static int profile_stat(FAR const char *relpath, FAR struct stat *buf) |
| 91 | +{ |
| 92 | + memset(buf, 0, sizeof(struct stat)); |
| 93 | + buf->st_mode = S_IFREG | S_IROTH | S_IRGRP | S_IRUSR; |
| 94 | + return OK; |
| 95 | +} |
| 96 | + |
| 97 | +/**************************************************************************** |
| 98 | + * Public Data |
| 99 | + ****************************************************************************/ |
| 100 | + |
| 101 | +const struct procfs_operations g_fsprofile_operations = |
| 102 | +{ |
| 103 | + profile_open, /* open */ |
| 104 | + profile_close, /* close */ |
| 105 | + profile_read, /* read */ |
| 106 | + NULL, /* write */ |
| 107 | + NULL, /* poll */ |
| 108 | + profile_dup, /* dup */ |
| 109 | + NULL, /* opendir */ |
| 110 | + NULL, /* closedir */ |
| 111 | + NULL, /* readdir */ |
| 112 | + NULL, /* rewinddir */ |
| 113 | + profile_stat /* stat */ |
| 114 | +}; |
| 115 | + |
| 116 | +#endif |
| 117 | + |
0 commit comments