Permalink
Browse files

o Needed convenient sub-second resolution time. Added CurrentTime()

  in util.{h,cc}
o Use time in displaying last access and page generation time in
  status server.
  • Loading branch information...
1 parent 4cc56d4 commit c1a03f22b32fd66c129c7e4df5d40ae9b541e50d @hzeller committed Sep 15, 2012
Showing with 87 additions and 12 deletions.
  1. +6 −2 Makefile
  2. +4 −1 file-handler-cache.cc
  3. +3 −0 file-handler-cache.h
  4. +26 −9 status-server.cc
  5. +25 −0 util.cc
  6. +23 −0 util.h
View
@@ -5,8 +5,12 @@ CFLAGS=-D_FILE_OFFSET_BITS=64 -Wall -O2
CXXFLAGS=$(CFLAGS)
LDFLAGS=-lfuse -lsndfile -lzita-convolver -lmicrohttpd
-fuse-convolve: fuse-convolve.o convolver.o conversion-buffer.o zita-audiofile.o zita-config.o zita-fconfig.o zita-sstring.o file-handler-cache.o status-server.o
+OBJECTS = fuse-convolve.o convolver.o conversion-buffer.o \
+ file-handler-cache.o status-server.o util.o \
+ zita-audiofile.o zita-config.o zita-fconfig.o zita-sstring.o
+
+fuse-convolve: $(OBJECTS)
$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)
clean:
- rm -f fuse-convolve *.o
+ rm -f fuse-convolve $(OBJECTS)
View
@@ -22,9 +22,10 @@
#include "file-handler.h"
#include "file-handler-cache.h"
+#include "util.h"
FileHandlerCache::Entry::Entry(const std::string &k, FileHandler *h)
- : key(k), handler(h), references(0) {}
+ : key(k), handler(h), references(0), last_access(0) {}
FileHandler *FileHandlerCache::InsertPinned(const std::string &key,
FileHandler *handler) {
@@ -40,6 +41,7 @@ FileHandler *FileHandlerCache::InsertPinned(const std::string &key,
if (cache_.size() > high_watermark_) {
CleanupUnreferencedLocked();
}
+ ins->second->last_access = fuse_convolve::CurrentTime();
return ins->second->handler;
}
@@ -49,6 +51,7 @@ FileHandler *FileHandlerCache::FindAndPin(const std::string &key) {
if (found == cache_.end())
return NULL;
++found->second->references;
+ found->second->last_access = fuse_convolve::CurrentTime();
return found->second->handler;
}
View
@@ -17,6 +17,8 @@
#ifndef _FUSE_CONVOLVER_FILE_HANDLER_CACHE_
#define _FUSE_CONVOLVER_FILE_HANDLER_CACHE_
+#include <time.h>
+
#include <map>
#include <vector>
#include <string>
@@ -38,6 +40,7 @@ class FileHandlerCache {
const std::string key;
FileHandler *const handler;
int references;
+ double last_access; // seconds since epoch, sub-second resolution.
};
FileHandlerCache(int low_watermark, int high_watermark)
View
@@ -25,8 +25,9 @@
#include <microhttpd.h>
-#include "status-server.h"
#include "convolver-filesystem.h"
+#include "status-server.h"
+#include "util.h"
int StatusServer::HandleHttp(void* user_argument,
struct MHD_Connection *connection,
@@ -64,31 +65,38 @@ StatusServer::~StatusServer() {
MHD_stop_daemon(daemon_);
}
-static const char sMessageRowHtml[] = "<td>%s</td><td>%s</td>"
+static const char sMessageRowHtml[] = "<td>%s</td><td>%s</td><td>%s</td>"
"<td colspan='3'>-</td>";
static const char sProgressRowHtml[] =
- "<td>%s</td><td>"
+ "<td>%s</td><td>%s</td><td>"
"<div style='width:%dpx; border:1px solid black;'>\n"
" <div style='width:%d%%;background:#7070ff;'>&nbsp;</div>\n</div></td>"
"<td align='right'>%2d:%02d</td><td>/</td><td align='right'>%2d:%02d</td>";
+static void FmtTime(char *buf, size_t size, int duration) {
+ snprintf(buf, size, "%d:%02d", duration / 60, duration % 60);
+}
+
static void AppendFileInfo(std::string *result, const std::string &filename,
- const FileHandler *handler, int refs) {
+ const FileHandler *handler, int refs,
+ double last_access) {
result->append("<tr>");
char row[1024];
const int kMaxWidth = 400;
const float progress = handler->Progress();
const char *access_level = (refs == 1) ? "idle" : "open";
+ char last[128];
+ FmtTime(last, sizeof(last), last_access);
if (progress <= 0) {
- snprintf(row, sizeof(row), sMessageRowHtml, access_level,
+ snprintf(row, sizeof(row), sMessageRowHtml, access_level, last,
(progress < 0)
? "Not a sound file or no filter found. Pass through."
: "Only Header accessed.");
} else {
const int secs = handler->Duration();
const int fract_sec = progress * secs;
- snprintf(row, sizeof(row), sProgressRowHtml, access_level,
+ snprintf(row, sizeof(row), sProgressRowHtml, access_level, last,
kMaxWidth, (int) (100 * progress),
fract_sec / 60, fract_sec % 60, secs / 60, secs % 60);
}
@@ -99,8 +107,8 @@ static void AppendFileInfo(std::string *result, const std::string &filename,
result->append("</tr>\n");
}
-
void StatusServer::CreatePage(const char **buffer, size_t *size) {
+ const double start = fuse_convolve::CurrentTime();
current_page_.clear();
current_page_.append("<body style='font-family:Helvetica;'>");
current_page_.append("<center>Welcome to fuse convolve ")
@@ -113,10 +121,15 @@ void StatusServer::CreatePage(const char **buffer, size_t *size) {
entries.size());
current_page_.append(current_open);
current_page_.append("<table>\n");
+ current_page_.append("<tr><th>Stat</th><th>Last</th>"
+ "<th width='400px'>Progress</th>"
+ "<th>Pos</th><td></td><th>Tot</th><th>Format</th>"
+ "<th>File</th></tr>\n");
+ const double now = fuse_convolve::CurrentTime();
for (size_t i = 0; i < entries.size(); ++i) {
const FileHandlerCache::Entry *entry = entries[i];
AppendFileInfo(&current_page_, entry->key, entry->handler,
- entry->references);
+ entry->references, now - entry->last_access);
filesystem_->handler_cache()->Unpin(entry->key);
}
current_page_.append("</table><hr/>\n");
@@ -126,7 +139,11 @@ void StatusServer::CreatePage(const char **buffer, size_t *size) {
filesystem_->total_file_openings(),
filesystem_->total_file_reopen());
current_page_.append(file_openings);
- current_page_.append("<div align='right'>HZ</div></body>");
+ const double duration = fuse_convolve::CurrentTime() - start;
+ char time_buffer[128];
+ snprintf(time_buffer, sizeof(time_buffer), " | page-gen %.2fms",
+ duration * 1000.0);
+ current_page_.append(time_buffer).append("<div align='right'>HZ</div></body>");
*buffer = current_page_.data();
*size = current_page_.size();
}
View
25 util.cc
@@ -0,0 +1,25 @@
+// Copyright (C) 2012 Henner Zeller <h.zeller@acm.org>
+//
+// This program 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.
+//
+// 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
+// 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/>.
+
+#include <sys/time.h>
+#include <stdio.h>
+
+#include "util.h"
+
+double fuse_convolve::CurrentTime() {
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return tv.tv_sec + tv.tv_usec / 1e6;
+}
View
23 util.h
@@ -0,0 +1,23 @@
+// Copyright (C) 2012 Henner Zeller <h.zeller@acm.org>
+//
+// This program 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.
+//
+// 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
+// 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/>.
+
+#ifndef FUSE_CONVOLVE_UTIL_H
+#define FUSE_CONVOLVE_UTIL_H
+
+namespace fuse_convolve {
+ double CurrentTime();
+} // namespece fuse_convolve
+
+#endif // FUSE_CONVOLVE_UTIL_H

0 comments on commit c1a03f2

Please sign in to comment.