#include "file.h"
#include "fileIO.h"
#include "fileInt.h"
-#include "stats_file.h"
#include "dynbuf.h"
#include "base64.h"
#include "timeutil.h"
#include "unicodeOperations.h"
-#define SETUP_DEFINE_VARS
-#include "stats_user_setup.h"
-
#if !defined(O_BINARY)
#define O_BINARY 0
#endif
}
-/*
- *----------------------------------------------------------------------
- *
- * FileIO_StatsInit --
- *
- * Initialize the stat structure in the FileIODescriptor.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-void
-FileIO_StatsInit(FileIODescriptor *fd) // IN:
-{
- /* zero out the stat counters */
-
- ASSERT(fd);
-
-#if defined(VMX86_STATS)
- fd->readIn = 0; fd->writeIn = 0;
- fd->readvIn = 0; fd->writevIn = 0;
- fd->preadvIn = 0; fd->pwritevIn = 0;
- fd->readDirect = 0; fd->writeDirect = 0;
- fd->readvDirect = 0; fd->writevDirect = 0;
- fd->preadDirect = 0; fd->pwriteDirect = 0;
- fd->bytesRead = 0; fd->bytesWritten = 0;
- fd->numReadCoalesced = 0; fd->numWriteCoalesced = 0;
-#endif
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * FileIO_StatsLog --
- *
- * Dump statistics about file access in the log file.
- *
- * Results:
- * None.
- *
- * Side effects:
- * Logs.
- *
- *----------------------------------------------------------------------
- */
-
-void
-FileIO_StatsLog(FileIODescriptor *fd) // IN:
-{
- ASSERT(fd);
-
-#if defined(VMX86_STATS)
- if (fd->bytesRead + fd->bytesWritten == 0) {
- /* No activity --> no interesting stats */
- return;
- }
-
- if (fd->readIn + fd->writeIn + fd->readvIn + fd->writevIn +
- fd->preadvIn + fd->pwritevIn < 100) {
- /*
- * Less than 100 operations is insufficient to be interesting and this
- * way we don't get spew everytime a file (generally a disk) is opened
- * temporarily.
- */
- return;
- }
-
- Log("FILEIOSTATS | \"%s\" %d %d %d %d %d %d %d %d %d %d %d %d %d %d %"FMT64"d %"FMT64"d\n",
- fd->fileName ? UTF8(fd->fileName) : "",
- fd->readIn, fd->readDirect, fd->writeIn, fd->writeDirect,
- fd->readvIn, fd->readvDirect, fd->writevIn, fd->writevDirect,
- fd->preadvIn, fd->preadDirect, fd->pwritevIn, fd->pwriteDirect,
- fd->numReadCoalesced, fd->numWriteCoalesced,
- fd->bytesRead, fd->bytesWritten);
-#endif
-}
-
-
-/*
- *----------------------------------------------------------------------
- *
- * FileIO_StatsExit --
- *
- * Release resources allocated for statistics.
- *
- * Results:
- * None.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-void
-FileIO_StatsExit(const FileIODescriptor *fd) // IN:
-{
- ASSERT(fd);
-}
-
-
/*
*----------------------------------------------------------------------
*
#include "config.h"
#include "util.h"
#include "iovector.h"
-#include "stats_file.h"
#include "hostType.h"
#include "unicodeOperations.h"
FileIO_Invalidate(&fd);
-#if defined(VMX86_STATS)
- STATS_USER_INIT_MODULE_ONCE();
- fd.stats = STATS_USER_INIT_INST("Created");
-#endif
-
if (flags & O_RDWR) {
fd.flags |= (FILEIO_OPEN_ACCESS_READ | FILEIO_OPEN_ACCESS_WRITE);
} else if (flags & O_WRONLY) {
return FILEIO_ERROR;
}
-#if defined(VMX86_STATS)
- {
- Unicode tmp;
-
- File_SplitName(pathName, NULL, NULL, &tmp);
- STATS_USER_INIT_MODULE_ONCE();
- file->stats = STATS_USER_INIT_INST(tmp);
- Unicode_Free(tmp);
- }
-#endif
-
ASSERT(!FileIO_IsValid(file));
ASSERT(file->lockToken == NULL);
ASSERT_ON_COMPILE(FILEIO_ERROR_LAST < 16); /* See comment in fileIO.h */
file->posix = fd;
- FileIO_StatsInit(file);
-
return FILEIO_SUCCESS;
error:
ASSERT(fd);
- STAT_INST_INC(fd->stats, NumWrites);
- STAT_INST_INC_BY(fd->stats, BytesWritten, requested);
- STATS_ONLY({
- fd->writeIn++;
- fd->bytesWritten += requested;
- })
-
ASSERT_NOT_IMPLEMENTED(requested < 0x80000000);
initial_requested = requested;
while (requested > 0) {
ssize_t res;
- STATS_ONLY(fd->writeDirect++;)
res = write(fd->posix, buf, requested);
if (res == -1) {
ASSERT(fd);
- STAT_INST_INC(fd->stats, NumReads);
- STAT_INST_INC_BY(fd->stats, BytesRead, requested);
- STATS_ONLY({
- fd->readIn++;
- fd->bytesRead += requested;
- })
-
ASSERT_NOT_IMPLEMENTED(requested < 0x80000000);
initial_requested = requested;
while (requested > 0) {
ssize_t res;
- STATS_ONLY(fd->readDirect++;)
res = read(fd->posix, buf, requested);
if (res == -1) {
if (errno == EINTR) {
err = (close(file->posix) == -1) ? errno : 0;
- FileIO_StatsExit(file);
-
/* Unlock the file if it was locked */
FileIO_Unlock(file);
FileIO_Cleanup(file);
didCoalesce = FileIOCoalesce(v, numEntries, totalSize, FALSE,
FALSE, fd->flags, &coV);
- STAT_INST_INC(fd->stats, NumReadvs);
- STAT_INST_INC_BY(fd->stats, BytesReadv, totalSize);
- STATS_ONLY({
- fd->readvIn++;
- fd->bytesRead += totalSize;
- if (didCoalesce) {
- fd->numReadCoalesced++;
- }
- })
-
ASSERT_NOT_IMPLEMENTED(totalSize < 0x80000000);
numVec = didCoalesce ? 1 : numEntries;
ssize_t retval;
ASSERT(numVec > 0);
- STATS_ONLY(fd->readvDirect++;)
retval = readv(fd->posix, vPtr, numVec);
if (retval == -1) {
didCoalesce = FileIOCoalesce(v, numEntries, totalSize, TRUE,
FALSE, fd->flags, &coV);
- STAT_INST_INC(fd->stats, NumWritevs);
- STAT_INST_INC_BY(fd->stats, BytesWritev, totalSize);
- STATS_ONLY({
- fd->writevIn++;
- fd->bytesWritten += totalSize;
- if (didCoalesce) {
- fd->numWriteCoalesced++;
- }
- })
-
ASSERT_NOT_IMPLEMENTED(totalSize < 0x80000000);
numVec = didCoalesce ? 1 : numEntries;
ssize_t retval;
ASSERT(numVec > 0);
- STATS_ONLY(fd->writevDirect++;)
retval = writev(fd->posix, vPtr, numVec);
if (retval == -1) {
count = didCoalesce ? 1 : numEntries;
vPtr = didCoalesce ? &coV : entries;
- STAT_INST_INC(fd->stats, NumPreadvs);
- STAT_INST_INC_BY(fd->stats, BytesPreadv, totalSize);
- STATS_ONLY({
- fd->preadvIn++;
- fd->bytesRead += totalSize;
- if (didCoalesce) {
- fd->numReadCoalesced++;
- }
- })
-
fileOffset = offset;
while (count > 0) {
size_t leftToRead = vPtr->iov_len;
uint8 *buf = (uint8 *) vPtr->iov_base;
- STATS_ONLY(fd->preadDirect++;)
while (leftToRead > 0) {
ssize_t retval = pread(fd->posix, buf, leftToRead, fileOffset);
count = didCoalesce ? 1 : numEntries;
vPtr = didCoalesce ? &coV : entries;
- STAT_INST_INC(fd->stats, NumPwritevs);
- STAT_INST_INC_BY(fd->stats, BytesPwritev, totalSize);
- STATS_ONLY({
- fd->pwritevIn++;
- fd->bytesWritten += totalSize;
- if (didCoalesce) {
- fd->numWriteCoalesced++;
- }
- })
-
fileOffset = offset;
while (count > 0) {
size_t leftToWrite = vPtr->iov_len;
uint8 *buf = (uint8 *)vPtr->iov_base;
- STATS_ONLY(fd->pwriteDirect++;)
while (leftToWrite > 0) {
ssize_t retval = pwrite(fd->posix, buf, leftToWrite, fileOffset);
#include "iovector.h" // for struct iovec
-#if defined(VMX86_STATS)
-
-struct StatsUserBlock;
-
-#define FILEIO_STATS_VARS \
- uint32 readIn, readDirect; \
- uint32 writeIn, writeDirect; \
- uint32 readvIn, readvDirect; \
- uint32 writevIn, writevDirect; \
- uint32 preadvIn, preadDirect; \
- uint32 pwritevIn, pwriteDirect; \
- uint64 bytesRead, bytesWritten; \
- uint32 numReadCoalesced, numWriteCoalesced; \
- struct StatsUserBlock *stats;
-#else
-#define FILEIO_STATS_VARS
-#endif
-
#if defined(_WIN32)
# include <windows.h>
uint32 flags;
Unicode fileName;
void *lockToken;
- FILEIO_STATS_VARS
} FileIODescriptor;
#else
int flags;
Unicode fileName;
void *lockToken;
- FILEIO_STATS_VARS
} FileIODescriptor;
#endif
void FileIO_Cleanup(FileIODescriptor *fd);
-void FileIO_StatsInit(FileIODescriptor *fd);
-
-void FileIO_StatsLog(FileIODescriptor *fd);
-
-void FileIO_StatsExit(const FileIODescriptor *fd);
-
const char *FileIO_ErrorEnglish(FileIOResult status);
void FileIO_OptionalSafeInitialize(void);
+++ /dev/null
-/*********************************************************
- * Copyright (C) 1998 VMware, Inc. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation version 2.1 and no later version.
- *
- * This program 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 Lesser GNU General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- *********************************************************/
-
-/*
- * stats_file.h --
- *
- * Implements statistics counters for lib/file/.
- *
- */
-
-#ifndef STATS_FILE_H
-#define STATS_FILE_H
-
-#define INCLUDE_ALLOW_USERLEVEL
-#include "includeCheck.h"
-
-#define STATS_MODULE file
-#include "stats_user_defs.h"
-
-#define SETUP_DECLARE_VARS
-#ifdef VMX86_STATS
-#define STATS_COUNTERS_INLINE \
- STAT_INST(NumReads, STATS_MODULE, "# Calls to FileIO_Read()") \
- STAT_INST(NumReadvs, STATS_MODULE, "# Calls to FileIO_Readv()") \
- STAT_INST(NumPreadvs, STATS_MODULE, "# Calls to FileIO_Preadv()") \
- STAT_INST(BytesRead, STATS_MODULE, "# Bytes requested of FileIO_Read()") \
- STAT_INST(BytesReadv, STATS_MODULE, "# Bytes requested of FileIO_Readv()") \
- STAT_INST(BytesPreadv, STATS_MODULE, "# Bytes requested of FileIO_Preadv()") \
- \
- STAT_INST(NumWrites, STATS_MODULE, "# Calls to FileIO_Write()") \
- STAT_INST(NumWritevs, STATS_MODULE, "# Calls to FileIO_Writev()") \
- STAT_INST(NumPwritevs, STATS_MODULE, "# Calls to FileIO_Pwritev()") \
- STAT_INST(BytesWritten, STATS_MODULE, "# Bytes requested of FileIO_Write()") \
- STAT_INST(BytesWritev, STATS_MODULE, "# Bytes requested of FileIO_Writev()") \
- STAT_INST(BytesPwritev, STATS_MODULE, "# Bytes requested of FileIO_Pwritev()")
-
-#else
- /* No statcounter in non-STATS builds */
-#define STATS_COUNTERS_NONE
-#endif
-#include "stats_user_setup.h"
-
-#endif