caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Florian Hars <hars@bik-gmbh.de>
To: Dustin Sallings <dustin@spy.net>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] newbie type problem
Date: Wed, 29 Oct 2003 08:23:18 +0100	[thread overview]
Message-ID: <3F9F6AE6.9030102@bik-gmbh.de> (raw)
In-Reply-To: <087CB9D7-05FB-11D8-B1A2-000393DC8AE4@spy.net>

Dustin Sallings wrote:
>     Well, part of the problem is that my log files aren't necessarily 
> sequential, so I have to be able to go back to any point in time and 
> update the thing.

Last time I had that problem I used two structures: one to keep the open events 
that come in from the logfiles and one to keep the data for the complete 
transactions where I have read all the relevant events.
If your logfiles are line-oriented (as these critters tend to be), you might 
want to write a function thats folds a function over all lines of a text file.
Then your program will look something like (add error checking, logic for 
handling overlapping transactions of the same type and missing functions to taste):

type evt = Start of string * float | End of string * float | Junk

module M = Map.make (struct type t = string let compare = compare end)

let parse_line s =
   if is_start s then
     Start (get_transaction_type s, get_time_form_log_line s)
   else if is_end s then
     End (get_transaction_type s, get_time_from_log_line s)
   else
      Junk

let operate_on_line (start_events, transactions as init) s =
   match parse_line s with
   | Junk -> init
   | Start (t_type, time) ->
         M.add t_type time start_events, transactions
   | End (t_type, time) ->
	let start_time = M.find t_type start_events in
	let l = try M.find t_type transactions with Not_found -> [] in
         M.remove t_type start_events,
         M.add t_type ((time - start_time)::l) transactions

let parse_logfile filename =
   let ic = open_in filename in
   let start_events, transactions =
     Textfile.fold operate_on_line (M.empty, M.empty) ic in
   close_in ic;
   cleanup_dangling_events start_events transactions

let _ = print_transaction_info (parse_logfile "my_logfile")

Yours, Florian.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  parent reply	other threads:[~2003-10-29  7:23 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-24  6:11 Dustin Sallings
2003-10-23 23:32 ` David Brown
2003-10-24  6:54   ` Dustin Sallings
2003-10-24  0:52     ` David Brown
2003-10-24  8:21       ` Dustin Sallings
2003-10-24 12:49         ` Andrew Lenharth
2003-10-24 13:22           ` Remi Vanicat
2003-10-29  7:23         ` Florian Hars [this message]
2003-10-29  8:03           ` Dustin Sallings
2003-10-29 16:27             ` Florian Hars
2003-10-24  9:25     ` Hendrik Tews
2003-10-24 16:23       ` Dustin Sallings

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3F9F6AE6.9030102@bik-gmbh.de \
    --to=hars@bik-gmbh.de \
    --cc=caml-list@inria.fr \
    --cc=dustin@spy.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).